test(editor): SSO tests (#5946)

* test(editor): SSO tests

* test(editor): move store tests to __tests__ folder

* test(editor): move tests in a different PR

* test(editor): add SSO tests

* test(editor): add SSO settings page tests

* test(editor): add SSO onboarding page base test

* test(editor): add SSO onboarding page test

* test(editor): fix router spy
This commit is contained in:
Csaba Tuncsik
2023-04-13 16:17:47 +02:00
committed by GitHub
parent 1a8a9f8ddb
commit bc1db5e16a
10 changed files with 475 additions and 79 deletions

View File

@@ -14,8 +14,7 @@ import { showMessage } from '@/mixins/showMessage';
import { i18nInstance } from '@/plugins/i18n';
import type { IWorkflowShortResponse } from '@/Interface';
import type { IExecutionsSummary } from 'n8n-workflow';
const waitAllPromises = () => new Promise((resolve) => setTimeout(resolve));
import { waitAllPromises } from '@/utils/testUtils';
const workflowDataFactory = (): IWorkflowShortResponse => ({
createdAt: faker.date.past().toDateString(),

View File

@@ -0,0 +1,59 @@
import { PiniaVuePlugin } from 'pinia';
import { render } from '@testing-library/vue';
import { createTestingPinia } from '@pinia/testing';
import { merge } from 'lodash-es';
import SSOLogin from '@/components/SSOLogin.vue';
import { STORES } from '@/constants';
import { useSSOStore } from '@/stores/sso';
import { SETTINGS_STORE_DEFAULT_STATE } from '@/utils/testUtils';
import { afterEach } from 'vitest';
let pinia: ReturnType<typeof createTestingPinia>;
let ssoStore: ReturnType<typeof useSSOStore>;
const renderComponent = (renderOptions: Parameters<typeof render>[1] = {}) =>
render(
SSOLogin,
merge(
{
pinia,
stubs: {
'n8n-button': {
template: '<button data-testid="sso-button"></button>',
},
},
},
renderOptions,
),
(vue) => {
vue.use(PiniaVuePlugin);
},
);
describe('SSOLogin', () => {
beforeEach(() => {
pinia = createTestingPinia({
initialState: {
[STORES.SETTINGS]: {
settings: merge({}, SETTINGS_STORE_DEFAULT_STATE.settings),
},
},
});
ssoStore = useSSOStore();
});
afterEach(() => {
vi.clearAllMocks();
});
it('should not render button if conditions are not met', () => {
const { queryByRole } = renderComponent();
expect(queryByRole('button')).not.toBeInTheDocument();
});
it('should render button if the store returns true for the conditions', () => {
vi.spyOn(ssoStore, 'showSsoLoginButton', 'get').mockReturnValue(true);
const { queryByRole } = renderComponent();
expect(queryByRole('button')).toBeInTheDocument();
});
});