mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
test: Add resource moving modal tests (no-changelog) (#9775)
This commit is contained in:
parent
60491d979d
commit
403947a6a4
|
@ -0,0 +1,65 @@
|
||||||
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
|
import { createComponentRenderer } from '@/__tests__/render';
|
||||||
|
import { PROJECT_MOVE_RESOURCE_CONFIRM_MODAL } from '@/constants';
|
||||||
|
import ProjectMoveResourceConfirmModal from '@/components/Projects/ProjectMoveResourceConfirmModal.vue';
|
||||||
|
import { useProjectsStore } from '@/stores/projects.store';
|
||||||
|
import { useTelemetry } from '@/composables/useTelemetry';
|
||||||
|
|
||||||
|
vi.mock('@/stores/ui.store', () => ({
|
||||||
|
useUIStore: vi.fn().mockReturnValue({
|
||||||
|
isModalOpen: vi.fn().mockReturnValue(() => true),
|
||||||
|
closeModal: vi.fn(),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const renderComponent = createComponentRenderer(ProjectMoveResourceConfirmModal, {
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
Modal: {
|
||||||
|
template:
|
||||||
|
'<div role="dialog"><slot name="header" /><slot name="content" /><slot name="footer" /></div>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let projectsStore: ReturnType<typeof useProjectsStore>;
|
||||||
|
let telemetry: ReturnType<typeof useTelemetry>;
|
||||||
|
|
||||||
|
describe('ProjectMoveResourceConfirmModal', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
setActivePinia(createPinia());
|
||||||
|
projectsStore = useProjectsStore();
|
||||||
|
telemetry = useTelemetry();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send telemetry when resource moving is confirmed', async () => {
|
||||||
|
vi.spyOn(projectsStore, 'moveResourceToProject').mockResolvedValue();
|
||||||
|
|
||||||
|
const telemetryTrackSpy = vi.spyOn(telemetry, 'track');
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
modalName: PROJECT_MOVE_RESOURCE_CONFIRM_MODAL,
|
||||||
|
data: {
|
||||||
|
resourceType: 'workflow',
|
||||||
|
resource: {
|
||||||
|
id: '1',
|
||||||
|
},
|
||||||
|
projectId: '1',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const { getByRole, getAllByRole } = renderComponent({ props });
|
||||||
|
const confirmBtn = getByRole('button', { name: /confirm/i });
|
||||||
|
expect(confirmBtn).toBeDisabled();
|
||||||
|
await Promise.all(
|
||||||
|
getAllByRole('checkbox').map(async (checkbox) => await userEvent.click(checkbox)),
|
||||||
|
);
|
||||||
|
expect(confirmBtn).toBeEnabled();
|
||||||
|
await userEvent.click(confirmBtn);
|
||||||
|
expect(telemetryTrackSpy).toHaveBeenCalledWith(
|
||||||
|
'User successfully moved workflow',
|
||||||
|
expect.objectContaining({ workflow_id: '1' }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
|
import { createComponentRenderer } from '@/__tests__/render';
|
||||||
|
import { PROJECT_MOVE_RESOURCE_CONFIRM_MODAL } from '@/constants';
|
||||||
|
import ProjectMoveResourceModal from '@/components/Projects/ProjectMoveResourceModal.vue';
|
||||||
|
import { useTelemetry } from '@/composables/useTelemetry';
|
||||||
|
|
||||||
|
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(() => {
|
||||||
|
setActivePinia(createPinia());
|
||||||
|
telemetry = useTelemetry();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send telemetry when mounted', async () => {
|
||||||
|
const telemetryTrackSpy = vi.spyOn(telemetry, 'track');
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
modalName: PROJECT_MOVE_RESOURCE_CONFIRM_MODAL,
|
||||||
|
data: {
|
||||||
|
resourceType: 'workflow',
|
||||||
|
resource: {
|
||||||
|
id: '1',
|
||||||
|
},
|
||||||
|
projectId: '1',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
renderComponent({ props });
|
||||||
|
expect(telemetryTrackSpy).toHaveBeenCalledWith(
|
||||||
|
'User clicked to move a workflow',
|
||||||
|
expect.objectContaining({ workflow_id: '1' }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue