Files
n8n-enterprise-unlocked/packages/editor-ui/src/__tests__/utils.ts

88 lines
2.2 KiB
TypeScript

import { within, waitFor } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
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 } = {},
) => {
return await new Promise((resolve, reject) => {
const startTime = Date.now();
const tryAgain = () => {
setTimeout(() => {
try {
resolve(assertion());
} catch (err) {
if (Date.now() - startTime > timeout) {
reject(err);
} else {
tryAgain();
}
}
}, interval);
};
tryAgain();
});
};
export const waitAllPromises = async () => await new Promise((resolve) => setTimeout(resolve));
export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
settings: defaultSettings,
promptsData: {
message: '',
title: '',
showContactPrompt: false,
showValueSurvey: false,
},
userManagement: {
showSetupOnFirstLoad: false,
smtpSetup: false,
authenticationMethod: UserManagementAuthenticationMethod.Email,
quota: defaultSettings.userManagement.quota,
},
templatesEndpointHealthy: false,
api: {
enabled: false,
latestVersion: 0,
path: '/',
swaggerUi: {
enabled: false,
},
},
ldap: {
loginLabel: '',
loginEnabled: false,
},
saml: {
loginLabel: '',
loginEnabled: false,
},
onboardingCallPromptEnabled: false,
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
saveManualExecutions: false,
initialized: false,
mfa: {
enabled: false,
},
};
export const getDropdownItems = async (dropdownTriggerParent: HTMLElement) => {
await userEvent.click(within(dropdownTriggerParent).getByRole('textbox'));
const selectTrigger = dropdownTriggerParent.querySelector(
'.select-trigger[aria-describedby]',
) as HTMLElement;
await waitFor(() => expect(selectTrigger).toBeInTheDocument());
const selectDropdownId = selectTrigger.getAttribute('aria-describedby');
const selectDropdown = document.getElementById(selectDropdownId as string) as HTMLElement;
await waitFor(() => expect(selectDropdown).toBeInTheDocument());
return selectDropdown.querySelectorAll('.el-select-dropdown__item');
};