From 9eb512b5a4e9beab85eda75d058dfed77fe649a0 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Fri, 15 Sep 2023 18:20:51 +0800 Subject: [PATCH] refactor(test): add `cls` and `dcls` util functions (#4513) To build string for matching class names. --- .../src/ui-helpers/expect-console.ts | 11 +++++---- .../src/ui-helpers/expect-page.ts | 4 ++-- packages/integration-tests/src/utils.ts | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/integration-tests/src/ui-helpers/expect-console.ts b/packages/integration-tests/src/ui-helpers/expect-console.ts index 9d608ed17..81bc8a4b1 100644 --- a/packages/integration-tests/src/ui-helpers/expect-console.ts +++ b/packages/integration-tests/src/ui-helpers/expect-console.ts @@ -3,6 +3,7 @@ import path from 'node:path'; import { appendPath } from '@silverhand/essentials'; import { consolePassword, consoleUsername, logtoConsoleUrl } from '#src/constants.js'; +import { dcls } from '#src/utils.js'; import ExpectPage, { ExpectPageError } from './expect-page.js'; import { expectConfirmModalAndAct, expectToSaveChanges } from './index.js'; @@ -53,7 +54,7 @@ export default class ExpectConsole extends ExpectPage { async gotoPage(pathname: string, title: ConsoleTitle) { await this.navigateTo(this.buildUrl(path.join(this.options.tenantId, pathname))); await expect(this.page).toMatchElement( - 'div[class*=_main] div[class*=_container] div[class*=_cardTitle]', + [dcls('main'), dcls('container'), dcls('cardTitle')].join(' '), { text: title } ); } @@ -67,7 +68,7 @@ export default class ExpectConsole extends ExpectPage { await Promise.all( titles.map(async (title) => { return expect(this.page).toMatchElement( - 'div[class*=_tabContent] div[class*=_card] div[class*=_title]', + [dcls('tabContent'), dcls('card'), dcls('title')].join(' '), { text: new RegExp(title, 'i'), visible: true } ); }) @@ -78,7 +79,7 @@ export default class ExpectConsole extends ExpectPage { const fieldTitle = await expect(this.page).toMatchElement( // Use `:has()` for a quick and dirty way to match the field title. // Not harmful in most cases. - 'div[class*=_field]:has(div[class*=_title])', + `${dcls('field')}:has(${dcls('title')})`, { text: new RegExp(title, 'i'), visible: true, @@ -100,7 +101,9 @@ export default class ExpectConsole extends ExpectPage { * Click a `