2024-09-27 06:12:31 -07:00
|
|
|
import { createTestingPinia } from '@pinia/testing';
|
2024-06-17 02:31:21 -07:00
|
|
|
import { createComponentRenderer } from '@/__tests__/render';
|
2024-09-27 06:12:31 -07:00
|
|
|
import { PROJECT_MOVE_RESOURCE_MODAL } from '@/constants';
|
2024-06-17 02:31:21 -07:00
|
|
|
import ProjectMoveResourceModal from '@/components/Projects/ProjectMoveResourceModal.vue';
|
|
|
|
import { useTelemetry } from '@/composables/useTelemetry';
|
2024-09-27 06:12:31 -07:00
|
|
|
import { mockedStore } from '@/__tests__/utils';
|
|
|
|
import { useProjectsStore } from '@/stores/projects.store';
|
2024-06-17 02:31:21 -07:00
|
|
|
|
|
|
|
const renderComponent = createComponentRenderer(ProjectMoveResourceModal, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
Modal: {
|
|
|
|
template:
|
|
|
|
'<div role="dialog"><slot name="header" /><slot name="content" /><slot name="footer" /></div>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
let telemetry: ReturnType<typeof useTelemetry>;
|
|
|
|
|
|
|
|
describe('ProjectMoveResourceModal', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
telemetry = useTelemetry();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should send telemetry when mounted', async () => {
|
2024-09-27 06:12:31 -07:00
|
|
|
const pinia = createTestingPinia();
|
2024-06-17 02:31:21 -07:00
|
|
|
const telemetryTrackSpy = vi.spyOn(telemetry, 'track');
|
|
|
|
|
2024-09-27 06:12:31 -07:00
|
|
|
const projectsStore = mockedStore(useProjectsStore);
|
|
|
|
projectsStore.availableProjects = [
|
|
|
|
{
|
|
|
|
id: '1',
|
|
|
|
name: 'My Project',
|
2024-12-27 10:00:40 -08:00
|
|
|
icon: { type: 'icon', value: 'folder' },
|
2024-09-27 06:12:31 -07:00
|
|
|
type: 'personal',
|
|
|
|
role: 'project:personalOwner',
|
|
|
|
createdAt: '2021-01-01T00:00:00.000Z',
|
|
|
|
updatedAt: '2021-01-01T00:00:00.000Z',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-06-17 02:31:21 -07:00
|
|
|
const props = {
|
2024-09-27 06:12:31 -07:00
|
|
|
modalName: PROJECT_MOVE_RESOURCE_MODAL,
|
2024-06-17 02:31:21 -07:00
|
|
|
data: {
|
|
|
|
resourceType: 'workflow',
|
2024-09-27 06:12:31 -07:00
|
|
|
resourceTypeLabel: 'Workflow',
|
2024-06-17 02:31:21 -07:00
|
|
|
resource: {
|
|
|
|
id: '1',
|
2024-09-27 06:12:31 -07:00
|
|
|
homeProject: {
|
|
|
|
id: '2',
|
|
|
|
name: 'My Project',
|
|
|
|
},
|
2024-06-17 02:31:21 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2024-09-27 06:12:31 -07:00
|
|
|
renderComponent({ props, pinia });
|
2024-06-17 02:31:21 -07:00
|
|
|
expect(telemetryTrackSpy).toHaveBeenCalledWith(
|
|
|
|
'User clicked to move a workflow',
|
|
|
|
expect.objectContaining({ workflow_id: '1' }),
|
|
|
|
);
|
|
|
|
});
|
2024-09-27 06:12:31 -07:00
|
|
|
|
|
|
|
it('should show no available projects message', async () => {
|
|
|
|
const pinia = createTestingPinia();
|
|
|
|
|
|
|
|
const projectsStore = mockedStore(useProjectsStore);
|
|
|
|
projectsStore.availableProjects = [];
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
modalName: PROJECT_MOVE_RESOURCE_MODAL,
|
|
|
|
data: {
|
|
|
|
resourceType: 'workflow',
|
|
|
|
resourceTypeLabel: 'Workflow',
|
|
|
|
resource: {
|
|
|
|
id: '1',
|
|
|
|
homeProject: {
|
|
|
|
id: '2',
|
|
|
|
name: 'My Project',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const { getByText } = renderComponent({ props, pinia });
|
|
|
|
expect(getByText(/Currently there are not any projects or users available/)).toBeVisible();
|
|
|
|
});
|
2024-06-17 02:31:21 -07:00
|
|
|
});
|