fix(editor): Fix ts errors in PersonalizationModal.spec.ts (no-changelog) (#9562)

This commit is contained in:
Tomi Turtiainen 2024-05-31 12:19:24 +03:00 committed by GitHub
parent 020bd36354
commit 6ce18ccda1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View file

@ -4,10 +4,15 @@ import type { ISettingsState } from '@/Interface';
import { UserManagementAuthenticationMethod } from '@/Interface';
import { defaultSettings } from './defaults';
export const retry = async (
assertion: () => ReturnType<typeof expect>,
{ interval = 20, timeout = 1000 } = {},
) => {
/**
* Retries the given assertion until it passes or the timeout is reached
*
* @example
* await retry(
* () => expect(screen.getByText('Hello')).toBeInTheDocument()
* );
*/
export const retry = async (assertion: () => void, { interval = 20, timeout = 1000 } = {}) => {
return await new Promise((resolve, reject) => {
const startTime = Date.now();
@ -15,9 +20,9 @@ export const retry = async (
setTimeout(() => {
try {
resolve(assertion());
} catch (err) {
} catch (error) {
if (Date.now() - startTime > timeout) {
reject(err);
reject(error);
} else {
tryAgain();
}

View file

@ -73,6 +73,7 @@ describe('PersonalizationModal.vue', () => {
);
for (const index of [3, 4, 5, 6]) {
const expectFn = expect; // So we don't break @typescript-eslint/no-loop-func
const select = wrapper.container.querySelectorAll('.n8n-select')[1];
await fireEvent.click(select);
@ -82,8 +83,8 @@ describe('PersonalizationModal.vue', () => {
await fireEvent.click(item);
await retry(() => {
expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6);
expect(wrapper.container.querySelector('[name^="automationGoal"]')).toBeInTheDocument();
expectFn(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6);
expectFn(wrapper.container.querySelector('[name^="automationGoal"]')).toBeInTheDocument();
});
}
});
@ -125,7 +126,8 @@ describe('PersonalizationModal.vue', () => {
const item = select.querySelectorAll('.el-select-dropdown__item')[3];
await fireEvent.click(item);
const agreeCheckbox = wrapper.container.querySelector('.n8n-checkbox')!;
const agreeCheckbox = wrapper.container.querySelector('.n8n-checkbox');
assert(agreeCheckbox);
await fireEvent.click(agreeCheckbox);
const submitButton = wrapper.getByRole('button');