From 8e56e3ae29c31e11658a0ce58e1c14959ad3f50c Mon Sep 17 00:00:00 2001 From: Roar Larsen Date: Mon, 18 Sep 2023 14:02:18 +0200 Subject: [PATCH] refactor: list example --- e2e/tests/plugin-list-task_list.spec.ts | 93 +++++++------------ .../dm-core-plugins/src/list/ListPlugin.tsx | 1 + 2 files changed, 34 insertions(+), 60 deletions(-) diff --git a/e2e/tests/plugin-list-task_list.spec.ts b/e2e/tests/plugin-list-task_list.spec.ts index a2f1cb2db..5a29205e4 100644 --- a/e2e/tests/plugin-list-task_list.spec.ts +++ b/e2e/tests/plugin-list-task_list.spec.ts @@ -71,11 +71,10 @@ test('Delete a task', async ({ page }) => { await expect( page.getByRole('paragraph').getByText('Tax return') ).toBeVisible() + await page - .locator('div') - .filter({ - hasText: /^Open itemTax returnMaria JohnsonMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Tax return', { exact: true }) }) .getByRole('button', { name: 'Delete' }) .click() await page.getByRole('button', { name: 'Save' }).click() @@ -88,118 +87,92 @@ test('Delete a task', async ({ page }) => { test('Move task up and down', async ({ page }) => { await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) ).toBeDisabled() + await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) ).toBeEnabled() + await page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) .click() await page.getByRole('button', { name: 'Save' }).click() await reloadPage(page) //TODO: Remove when #153 is solved. await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) ).toBeEnabled() await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) ).toBeEnabled() await page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) .click() await page.getByRole('button', { name: 'Save' }).click() await reloadPage(page) //TODO: Remove when #153 is solved. await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) ).toBeEnabled() await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) ).toBeDisabled() await page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) .click() await page.getByRole('button', { name: 'Save' }).click() await reloadPage(page) //TODO: Remove when #153 is solved. await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) ).toBeEnabled() await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) ).toBeEnabled() await page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) .click() await page.getByRole('button', { name: 'Save' }).click() await reloadPage(page) //TODO: Remove when #153 is solved. await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move down' }) ).toBeDisabled() await expect( page - .locator('div') - .filter({ - hasText: /^Open itemPaint the living roomMove upMove DownDelete$/, - }) + .getByRole('row') + .filter({ has: page.getByText('Paint the living room', { exact: true }) }) .getByRole('button', { name: 'Move up' }) ).toBeEnabled() }) diff --git a/packages/dm-core-plugins/src/list/ListPlugin.tsx b/packages/dm-core-plugins/src/list/ListPlugin.tsx index dcc824aa7..cbdfddf85 100644 --- a/packages/dm-core-plugins/src/list/ListPlugin.tsx +++ b/packages/dm-core-plugins/src/list/ListPlugin.tsx @@ -171,6 +171,7 @@ export const ListPlugin = (props: IUIPlugin & { config?: TListConfig }) => {