add unit tests

This commit is contained in:
Mutasem Aldmour 2024-11-14 14:18:53 +01:00
parent 8e2a562220
commit c124bb9e4c
No known key found for this signature in database
GPG key ID: 3DFA8122BB7FD6B8

View file

@ -3,8 +3,9 @@ import type { ExecutionSummary } from 'n8n-workflow';
import { i18n } from '@/plugins/i18n';
import { convertToDisplayDate } from '@/utils/formatters/dateFormatter';
const { resolve } = vi.hoisted(() => ({
const { resolve, track } = vi.hoisted(() => ({
resolve: vi.fn(),
track: vi.fn(),
}));
vi.mock('vue-router', () => ({
@ -14,6 +15,10 @@ vi.mock('vue-router', () => ({
RouterLink: vi.fn(),
}));
vi.mock('@/composables/useTelemetry', () => ({
useTelemetry: () => ({ track }),
}));
describe('useExecutionHelpers()', () => {
describe('getUIDetails()', () => {
it.each([
@ -93,4 +98,56 @@ describe('useExecutionHelpers()', () => {
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('');
});
});
});