mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
add unit tests
This commit is contained in:
parent
8e2a562220
commit
c124bb9e4c
|
@ -3,8 +3,9 @@ import type { ExecutionSummary } from 'n8n-workflow';
|
||||||
import { i18n } from '@/plugins/i18n';
|
import { i18n } from '@/plugins/i18n';
|
||||||
import { convertToDisplayDate } from '@/utils/formatters/dateFormatter';
|
import { convertToDisplayDate } from '@/utils/formatters/dateFormatter';
|
||||||
|
|
||||||
const { resolve } = vi.hoisted(() => ({
|
const { resolve, track } = vi.hoisted(() => ({
|
||||||
resolve: vi.fn(),
|
resolve: vi.fn(),
|
||||||
|
track: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('vue-router', () => ({
|
vi.mock('vue-router', () => ({
|
||||||
|
@ -14,6 +15,10 @@ vi.mock('vue-router', () => ({
|
||||||
RouterLink: vi.fn(),
|
RouterLink: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock('@/composables/useTelemetry', () => ({
|
||||||
|
useTelemetry: () => ({ track }),
|
||||||
|
}));
|
||||||
|
|
||||||
describe('useExecutionHelpers()', () => {
|
describe('useExecutionHelpers()', () => {
|
||||||
describe('getUIDetails()', () => {
|
describe('getUIDetails()', () => {
|
||||||
it.each([
|
it.each([
|
||||||
|
@ -93,4 +98,56 @@ describe('useExecutionHelpers()', () => {
|
||||||
expect(window.open).toHaveBeenCalledWith(href, '_blank');
|
expect(window.open).toHaveBeenCalledWith(href, '_blank');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('trackOpeningRelatedExecution', () => {
|
||||||
|
it('tracks sub execution click', () => {
|
||||||
|
const { trackOpeningRelatedExecution } = useExecutionHelpers();
|
||||||
|
|
||||||
|
trackOpeningRelatedExecution(
|
||||||
|
{ subExecution: { executionId: '123', workflowId: 'xyz' } },
|
||||||
|
'table',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(track).toHaveBeenCalledWith('User clicked inspect sub-workflow', { view: 'table' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tracks parent execution click', () => {
|
||||||
|
const { trackOpeningRelatedExecution } = useExecutionHelpers();
|
||||||
|
|
||||||
|
trackOpeningRelatedExecution(
|
||||||
|
{ parentExecution: { executionId: '123', workflowId: 'xyz' } },
|
||||||
|
'json',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(track).toHaveBeenCalledWith('User clicked parent execution button', { view: 'json' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('resolveRelatedExecutionUrl', () => {
|
||||||
|
it('resolves sub execution url', () => {
|
||||||
|
const fullPath = 'test.com';
|
||||||
|
resolve.mockReturnValue({ fullPath });
|
||||||
|
const { resolveRelatedExecutionUrl } = useExecutionHelpers();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
resolveRelatedExecutionUrl({ subExecution: { executionId: '123', workflowId: 'xyz' } }),
|
||||||
|
).toEqual(fullPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves parent execution url', () => {
|
||||||
|
const fullPath = 'test.com';
|
||||||
|
resolve.mockReturnValue({ fullPath });
|
||||||
|
const { resolveRelatedExecutionUrl } = useExecutionHelpers();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
resolveRelatedExecutionUrl({ parentExecution: { executionId: '123', workflowId: 'xyz' } }),
|
||||||
|
).toEqual(fullPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns empty if no related execution url', () => {
|
||||||
|
const { resolveRelatedExecutionUrl } = useExecutionHelpers();
|
||||||
|
|
||||||
|
expect(resolveRelatedExecutionUrl({})).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue