From a0fe3644c33963bb6d3ec21dc98d1e5bf9b918ad Mon Sep 17 00:00:00 2001 From: regexowl Date: Thu, 8 May 2025 10:22:33 +0200 Subject: [PATCH] src: Remove more `data-testid`s As using `data-testid`s in tests is an anti-pattern, this removes more of them and replaces them with appropriate locators in the tests. --- playwright/test.spec.ts | 8 +- .../Blueprints/BlueprintActionsMenu.tsx | 1 - .../Blueprints/ImportBlueprintModal.tsx | 1 - .../FileSystem/components/FileSystemTable.tsx | 10 +- .../components/ReleaseLifecycle.tsx | 1 - .../components/TargetEnvironment.tsx | 12 -- .../Registration/components/Registration.tsx | 2 - .../steps/Repositories/components/Empty.tsx | 1 - .../Snapshot/components/TemplatesEmpty.tsx | 1 - .../Azure/AzureHyperVSelect.tsx | 1 - .../steps/TargetEnvironment/Gcp/index.tsx | 5 - src/Components/ImagesTable/EmptyState.tsx | 1 - .../sharedComponents/ImageBuilderHeader.tsx | 1 - .../Components/Blueprints/Blueprints.test.tsx | 6 +- .../Blueprints/ImportBlueprintModal.test.tsx | 43 +++-- .../CreateImageWizard.test.tsx | 42 +++-- .../FileSystemConfiguration.test.tsx | 23 +-- .../steps/ImageOutput/ImageOutput.test.tsx | 166 +++++++++++++----- .../steps/Oscap/Oscap.test.tsx | 10 +- .../TargetEnvironment/AwsTarget.test.tsx | 10 +- .../TargetEnvironment/AzureTarget.test.tsx | 10 +- .../TargetEnvironment/GCPTarget.test.tsx | 38 ++-- .../steps/Users/Users.test.tsx | 4 +- .../CreateImageWizard/wizardTestUtils.tsx | 4 +- .../ImagesTable/ImagesTable.test.tsx | 12 +- .../LandingPage/LandingPage.test.tsx | 4 +- 26 files changed, 257 insertions(+), 160 deletions(-) diff --git a/playwright/test.spec.ts b/playwright/test.spec.ts index 4bec2f84..a8c43830 100644 --- a/playwright/test.spec.ts +++ b/playwright/test.spec.ts @@ -22,14 +22,16 @@ test.describe.serial('test', () => { await frame.getByTestId('blueprints-create-button').click(); frame.getByRole('heading', { name: 'Image output' }); - await frame.getByTestId('checkbox-guest-image').click(); + await frame + .getByRole('checkbox', { name: /Virtualization guest image/i }) + .click(); await frame.getByRole('button', { name: 'Next', exact: true }).click(); if (isHosted()) { frame.getByRole('heading', { name: 'Register systems using this image', }); - await page.getByTestId('register-later-radio').click(); + await page.getByRole('radio', { name: /Register later/i }).click(); await frame.getByRole('button', { name: 'Next', exact: true }).click(); } @@ -164,7 +166,7 @@ test.describe.serial('test', () => { // the clickable blueprint cards are a bit awkward, so use the // button's id instead await frame.locator(`button[id="${blueprintName}"]`).click(); - await frame.getByTestId('blueprint-action-menu-toggle').click(); + await frame.getByRole('button', { name: /blueprint menu toggle/i }).click(); await frame.getByRole('menuitem', { name: 'Delete blueprint' }).click(); await frame.getByRole('button', { name: 'Delete' }).click(); }); diff --git a/src/Components/Blueprints/BlueprintActionsMenu.tsx b/src/Components/Blueprints/BlueprintActionsMenu.tsx index a759bf92..beb66d94 100644 --- a/src/Components/Blueprints/BlueprintActionsMenu.tsx +++ b/src/Components/Blueprints/BlueprintActionsMenu.tsx @@ -60,7 +60,6 @@ export const BlueprintActionsMenu: React.FunctionComponent< onClick={() => setShowBlueprintActionsMenu(!showBlueprintActionsMenu)} variant="plain" aria-label="blueprint menu toggle" - data-testid="blueprint-action-menu-toggle" >