Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
despairblue committed Jan 28, 2025
1 parent f03bb90 commit 6bc49ab
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/editor-ui/src/stores/settings.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { FrontendSettings } from '@n8n/api-types';
import { createPinia, setActivePinia } from 'pinia';
import { mock } from 'vitest-mock-extended';
import { useSettingsStore } from './settings.store';
import { useLocalStorage } from '@vueuse/core';
import { ref } from 'vue';

const { getSettings } = vi.hoisted(() => ({
getSettings: vi.fn(),
Expand Down Expand Up @@ -54,6 +56,16 @@ vi.mock('@/stores/versions.store', () => ({
})),
}));

vi.mock('@vueuse/core', async () => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const originalModule = await vi.importActual<typeof import('@vueuse/core')>('@vueuse/core');

return {
...originalModule, // Keep all original exports
useLocalStorage: vi.fn().mockReturnValue({ value: undefined }), // Mock useLocalStorage
};
});

const mockSettings = mock<FrontendSettings>({
authCookie: { secure: true },
});
Expand Down Expand Up @@ -99,4 +111,47 @@ describe('settings.store', () => {
expect(sessionStarted).not.toHaveBeenCalled();
});
});

describe('partialExecutionVersion', () => {
it.each([
{
name: 'pick the default',
default: 1 as const,
enforce: false,
userVersion: -1,
result: 1,
},
{
name: "pick the user' choice",
default: 1 as const,
enforce: false,
userVersion: 2,
result: 2,
},
{
name: 'enforce the default',
default: 1 as const,
enforce: true,
userVersion: 2,
result: 1,
},
{
name: 'enforce the default',
default: 2 as const,
enforce: true,
userVersion: 1,
result: 2,
},
])('%name', async ({ default: defaultVersion, userVersion, enforce, result }) => {
const settingsStore = useSettingsStore();

settingsStore.settings.partialExecution = {
version: defaultVersion,
enforce,
};
vi.mocked(useLocalStorage).mockReturnValueOnce(ref(userVersion));

expect(settingsStore.partialExecutionVersion).toBe(result);
});
});
});

0 comments on commit 6bc49ab

Please sign in to comment.