From 0dc49d32e4d09f37adb954a1cab9e9aef2b9f4f5 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Sun, 27 Oct 2024 10:20:47 +0800 Subject: [PATCH] chore(e2e): make e2e more stable --- .../src/client/__e2e__/auth.test.ts | 11 ++++++---- .../fields/checkbox/schemaSettings.test.ts | 20 +++++++++++-------- .../client/__e2e__/createLocalStorage.test.ts | 1 - 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-auth/src/client/__e2e__/auth.test.ts b/packages/plugins/@nocobase/plugin-auth/src/client/__e2e__/auth.test.ts index 7744cc818f..6c756c2729 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/client/__e2e__/auth.test.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/client/__e2e__/auth.test.ts @@ -19,10 +19,13 @@ test.describe('auth', () => { }); test('register', async ({ page }) => { + // Generate a random username + const username = `zidonghuaceshi${Math.random().toString(36).substring(2, 15)}`; + await page.goto('/'); await page.getByRole('link', { name: 'Create an account' }).click(); await page.getByPlaceholder('Username').click(); - await page.getByPlaceholder('Username').fill('zidonghuaceshi'); + await page.getByPlaceholder('Username').fill(username); await page.getByPlaceholder('Password', { exact: true }).click(); await page.getByPlaceholder('Password', { exact: true }).fill('zidonghuaceshi123'); await page.getByPlaceholder('Confirm password').click(); @@ -31,14 +34,14 @@ test.describe('auth', () => { await expect(page.getByText('Sign up successfully, and automatically jump to the sign in page')).toBeVisible(); - // 用新账户登录 + // Sign in with the new account await page.getByPlaceholder('Username/Email').click(); - await page.getByPlaceholder('Username/Email').fill('zidonghuaceshi'); + await page.getByPlaceholder('Username/Email').fill(username); await page.getByPlaceholder('Password').click(); await page.getByPlaceholder('Password').fill('zidonghuaceshi123'); await page.getByRole('button', { name: 'Sign in' }).click(); await page.getByTestId('user-center-button').hover(); - await expect(page.getByText('zidonghuaceshi')).toBeVisible(); + await expect(page.getByText(username)).toBeVisible(); }); }); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts index c7e94c032c..4cff5661fa 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts @@ -192,14 +192,18 @@ test.describe('form item & edit form', () => { ).toBeDisabled(); }, expectEasyReading: async () => { - await expect( - page.getByLabel('block-item-CollectionField-general-form-general.checkbox-checkbox').getByRole('checkbox'), - ).toBeVisible(); - await expect( - page - .getByLabel('block-item-CollectionField-general-form-general.checkbox-checkbox') - .getByRole('img', { name: 'check' }), - ).toBeVisible({ visible: record.checkbox }); + if (record.checkbox) { + await expect( + page + .getByLabel('block-item-CollectionField-general-form-general.checkbox-checkbox') + .getByRole('img', { name: 'check' }), + ).toBeVisible({ visible: record.checkbox }); + } else { + // 未选中状态会显示一个禁用的 checkbox + await expect( + page.getByLabel('block-item-CollectionField-general-form-general.checkbox-checkbox').getByRole('checkbox'), + ).toBeDisabled(); + } }, }); }); diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/__e2e__/createLocalStorage.test.ts b/packages/plugins/@nocobase/plugin-file-manager/src/client/__e2e__/createLocalStorage.test.ts index 4793cde5ae..5387da40f9 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/__e2e__/createLocalStorage.test.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/__e2e__/createLocalStorage.test.ts @@ -22,7 +22,6 @@ test.describe('file manager', () => { // 2、测试步骤:进入“文件管理器”-“新建”按钮,填写表单,点击“确定”按钮 await page.goto('/admin/settings/file-manager'); - await page.waitForLoadState('networkidle'); await page.getByRole('button', { name: 'plus Add new' }).hover(); await page.getByRole('menuitem', { name: 'Local storage' }).click(); const createLocalStorage = new CreateLocalStorage(page);