fix: update tests

This commit is contained in:
Alex Grozav 2023-07-26 13:11:28 +03:00
parent d28685beba
commit 2cbf49e8d7
3 changed files with 21 additions and 35 deletions

View file

@ -20,10 +20,6 @@ export const retry = async (assertion: () => any, { interval = 20, timeout = 100
}); });
}; };
type RenderParams = Parameters<typeof render>;
export const renderComponent = (Component: RenderParams[0], renderOptions: RenderParams[1] = {}) =>
render(Component, renderOptions);
export const waitAllPromises = async () => new Promise((resolve) => setTimeout(resolve)); export const waitAllPromises = async () => new Promise((resolve) => setTimeout(resolve));
export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = { export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {

View file

@ -1,4 +1,3 @@
import { render } from '@testing-library/vue';
import { createTestingPinia } from '@pinia/testing'; import { createTestingPinia } from '@pinia/testing';
import { merge } from 'lodash-es'; import { merge } from 'lodash-es';
import SSOLogin from '@/components/SSOLogin.vue'; import SSOLogin from '@/components/SSOLogin.vue';
@ -6,27 +5,20 @@ import { STORES } from '@/constants';
import { useSSOStore } from '@/stores/sso.store'; import { useSSOStore } from '@/stores/sso.store';
import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils'; import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
import { afterEach } from 'vitest'; import { afterEach } from 'vitest';
import { createComponentRenderer } from '@/__tests__/render';
let pinia: ReturnType<typeof createTestingPinia>; let pinia: ReturnType<typeof createTestingPinia>;
let ssoStore: ReturnType<typeof useSSOStore>; let ssoStore: ReturnType<typeof useSSOStore>;
const renderComponent = (renderOptions: Parameters<typeof render>[1] = {}) => const renderComponent = createComponentRenderer(SSOLogin, {
render( global: {
SSOLogin, stubs: {
merge( 'n8n-button': {
{ template: '<button data-test-id="sso-button"></button>',
store: pinia,
global: {
stubs: {
'n8n-button': {
template: '<button data-test-id="sso-button"></button>',
},
},
},
}, },
renderOptions, },
), },
); });
describe('SSOLogin', () => { describe('SSOLogin', () => {
beforeEach(() => { beforeEach(() => {
@ -45,13 +37,13 @@ describe('SSOLogin', () => {
}); });
it('should not render button if conditions are not met', () => { it('should not render button if conditions are not met', () => {
const { queryByRole } = renderComponent(); const { queryByRole } = renderComponent({ pinia });
expect(queryByRole('button')).not.toBeInTheDocument(); expect(queryByRole('button')).not.toBeInTheDocument();
}); });
it('should render button if the store returns true for the conditions', () => { it('should render button if the store returns true for the conditions', () => {
vi.spyOn(ssoStore, 'showSsoLoginButton', 'get').mockReturnValue(true); vi.spyOn(ssoStore, 'showSsoLoginButton', 'get').mockReturnValue(true);
const { queryByRole } = renderComponent(); const { queryByRole } = renderComponent({ pinia });
expect(queryByRole('button')).toBeInTheDocument(); expect(queryByRole('button')).toBeInTheDocument();
}); });
}); });

View file

@ -40,18 +40,16 @@
</n8n-button> </n8n-button>
</div> </div>
</template> </template>
<template v-else> <div v-else data-test-id="action-box-licensed">
<div data-test-id="action-box-licensed"> <n8n-action-box
<n8n-action-box :buttonText="$locale.baseText(`settings.log-streaming.add`)"
:buttonText="$locale.baseText(`settings.log-streaming.add`)" @click:button="addDestination"
@click:button="addDestination" >
> <template #heading>
<template #heading> <span v-html="$locale.baseText(`settings.log-streaming.addFirstTitle`)" />
<span v-html="$locale.baseText(`settings.log-streaming.addFirstTitle`)" /> </template>
</template> </n8n-action-box>
</n8n-action-box> </div>
</div>
</template>
</template> </template>
<template v-else> <template v-else>
<div v-if="$locale.baseText('settings.log-streaming.infoText')" class="mb-l"> <div v-if="$locale.baseText('settings.log-streaming.infoText')" class="mb-l">