chore: make e2e more stable

This commit is contained in:
Zeke Zhang 2024-04-28 17:46:31 +08:00
parent c23631be4a
commit 8524beae67
2 changed files with 22 additions and 21 deletions

View File

@ -1,15 +1,6 @@
import { expect, test } from '@nocobase/test/e2e';
import { oneTableWithMap } from './templates';
test.afterEach(async ({ page }) => {
await page.goto('/admin/settings/map');
await page.getByRole('button', { name: 'Edit' }).click();
await page.getByLabel('Access key').clear();
await page.getByLabel('securityJsCode or serviceHost').clear();
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible();
});
test.describe('where map block can be added', () => {
test('page & popup', async ({ page, mockPage }) => {
const nocoPage = await mockPage(oneTableWithMap).waitForInit();
@ -29,14 +20,13 @@ test.describe('where map block can be added', () => {
// 2. 点击跳转按钮去配置页面,配置好后返回刚才的页面,应该能正常显示地图
await page.getByRole('button', { name: 'Go to the configuration page' }).click();
await page.waitForLoadState('networkidle');
if (await page.getByRole('button', { name: 'Edit' }).isVisible()) {
await page.getByRole('button', { name: 'Edit' }).click();
await page.waitForTimeout(1000);
if (await page.getByRole('button', { name: 'Edit' }).first().isVisible()) {
await page.getByRole('button', { name: 'Edit' }).first().click();
}
await page.getByLabel('Access key').click();
await page.getByLabel('Access key').fill('9717a70e44273882bcf5489f72b4e261');
await page.getByLabel('securityJsCode or serviceHost').click();
await page.getByLabel('securityJsCode or serviceHost').fill('6876ed2d3a6168b75c4fba852e16c99c');
await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('button', { name: 'Save' }).first().click();
await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible();
await nocoPage.goto();
await expect(page.getByLabel('block-item-CardItem-map-map').locator('.amap-layer')).toBeAttached();
@ -46,5 +36,15 @@ test.describe('where map block can be added', () => {
await page.getByLabel('schema-initializer-Grid-form:').hover();
await page.getByRole('menuitem', { name: 'point' }).click();
await expect(page.getByLabel('block-item-CollectionField-').locator('.amap-layer')).toBeAttached();
// 4. 清空配置信息,以免影响其他测试用例
await page.goto('/admin/settings/map');
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'Edit' }).first().click();
await page.getByLabel('Access key').clear();
await page.getByLabel('securityJsCode or serviceHost').clear();
await page.getByRole('button', { name: 'Save' }).first().click();
await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible();
});
});

View File

@ -4,23 +4,24 @@ import { oneMapUsedToTestSettings } from './templates';
test.beforeEach(async ({ page }) => {
await page.goto('/admin/settings/map');
await page.waitForLoadState('networkidle');
if (await page.getByRole('button', { name: 'Edit' }).isVisible()) {
await page.getByRole('button', { name: 'Edit' }).click();
await page.waitForTimeout(1000);
if (await page.getByRole('button', { name: 'Edit' }).first().isVisible()) {
await page.getByRole('button', { name: 'Edit' }).first().click();
}
await page.getByLabel('Access key').click();
await page.getByLabel('Access key').fill('9717a70e44273882bcf5489f72b4e261');
await page.getByLabel('securityJsCode or serviceHost').click();
await page.getByLabel('securityJsCode or serviceHost').fill('6876ed2d3a6168b75c4fba852e16c99c');
await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('button', { name: 'Save' }).first().click();
await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible();
});
test.afterEach(async ({ page }) => {
await page.goto('/admin/settings/map');
await page.getByRole('button', { name: 'Edit' }).click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'Edit' }).first().click();
await page.getByLabel('Access key').clear();
await page.getByLabel('securityJsCode or serviceHost').clear();
await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('button', { name: 'Save' }).first().click();
await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible();
});