From 5dd8353ab16547b7e97e8a340c20a97d22560086 Mon Sep 17 00:00:00 2001 From: Khushi Jain Date: Wed, 24 Apr 2024 18:46:19 +0530 Subject: [PATCH] Dashboards: Migrate from aria-label e2e selectors to data-testid (#78536) * Dashboards: Migrate from aria-label e2e selectors to data-testid * more changes * addPanelwidget * Test: Update .betterer.results * refactor: fix e2e tests * refactor: fix failing test * refactor: update plugin-e2e after adding selector changes to the packege --------- Co-authored-by: Laura Benz <48948963+L-M-K-B@users.noreply.github.com> Co-authored-by: Laura Benz --- .betterer.results | 34 +++++-------------- e2e/various-suite/filter-annotations.spec.ts | 12 ++++--- package.json | 2 +- .../src/selectors/components.ts | 19 ++++++----- .../src/selectors/pages.ts | 10 +++--- .../inspect/InspectJsonTab.tsx | 2 +- .../AnnotationSettingsEdit.tsx | 8 ++--- .../components/PanelEditor/OptionsPane.tsx | 2 +- .../PanelEditor/OptionsPaneCategory.tsx | 5 ++- .../PanelEditor/OptionsPaneOptions.test.tsx | 2 +- .../components/PanelEditor/PanelEditor.tsx | 6 ++-- .../app/features/inspector/InspectJSONTab.tsx | 2 +- yarn.lock | 10 +++--- 13 files changed, 49 insertions(+), 65 deletions(-) diff --git a/.betterer.results b/.betterer.results index b1db9758f60..1fec2f3f3ed 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2408,9 +2408,6 @@ exports[`better eslint`] = { "public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] - ], "public/app/features/dashboard-scene/pages/DashboardScenePage.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -2518,11 +2515,7 @@ exports[`better eslint`] = { ], "public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx:5381": [ [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "2"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "3"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"] + [0, 0, 0, "Styles should be written using objects.", "1"] ], "public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsList.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -2620,15 +2613,10 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "2"] ], "public/app/features/dashboard/components/PanelEditor/OptionsPane.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], + [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"], [0, 0, 0, "Styles should be written using objects.", "2"], - [0, 0, 0, "Styles should be written using objects.", "3"], - [0, 0, 0, "Styles should be written using objects.", "4"] - ], - "public/app/features/dashboard/components/PanelEditor/OptionsPaneCategory.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"] + [0, 0, 0, "Styles should be written using objects.", "3"] ], "public/app/features/dashboard/components/PanelEditor/OptionsPaneItemDescriptor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2658,20 +2646,17 @@ exports[`better eslint`] = { ], "public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx:5381": [ [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "2"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], + [0, 0, 0, "Do not use any type assertions.", "1"], + [0, 0, 0, "Styles should be written using objects.", "2"], + [0, 0, 0, "Styles should be written using objects.", "3"], + [0, 0, 0, "Styles should be written using objects.", "4"], [0, 0, 0, "Styles should be written using objects.", "5"], [0, 0, 0, "Styles should be written using objects.", "6"], [0, 0, 0, "Styles should be written using objects.", "7"], [0, 0, 0, "Styles should be written using objects.", "8"], [0, 0, 0, "Styles should be written using objects.", "9"], [0, 0, 0, "Styles should be written using objects.", "10"], - [0, 0, 0, "Styles should be written using objects.", "11"], - [0, 0, 0, "Styles should be written using objects.", "12"], - [0, 0, 0, "Styles should be written using objects.", "13"], - [0, 0, 0, "Styles should be written using objects.", "14"] + [0, 0, 0, "Styles should be written using objects.", "11"] ], "public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], @@ -3691,9 +3676,6 @@ exports[`better eslint`] = { "public/app/features/inspector/InspectDataTab.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], - "public/app/features/inspector/InspectJSONTab.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] - ], "public/app/features/inspector/InspectStatsTab.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] diff --git a/e2e/various-suite/filter-annotations.spec.ts b/e2e/various-suite/filter-annotations.spec.ts index 23d64eb0826..26cf83f00e2 100644 --- a/e2e/various-suite/filter-annotations.spec.ts +++ b/e2e/various-suite/filter-annotations.spec.ts @@ -18,19 +18,21 @@ describe('Annotations filtering', () => { .should('be.visible') .within(() => { // All panels - e2e.components.Annotations.annotationsTypeInput().click({ force: true }).type('All panels{enter}'); + e2e.components.Annotations.annotationsTypeInput().find('input').type('All panels{enter}', { force: true }); e2e.components.Annotations.annotationsChoosePanelInput().should('not.exist'); // All panels except - e2e.components.Annotations.annotationsTypeInput().click({ force: true }).type('All panels except{enter}'); + e2e.components.Annotations.annotationsTypeInput() + .find('input') + .type('All panels except{enter}', { force: true }); e2e.components.Annotations.annotationsChoosePanelInput().should('be.visible'); // Selected panels - e2e.components.Annotations.annotationsTypeInput().click({ force: true }).type('Selected panels{enter}'); + e2e.components.Annotations.annotationsTypeInput().find('input').type('Selected panels{enter}', { force: true }); e2e.components.Annotations.annotationsChoosePanelInput() .should('be.visible') - .click({ force: true }) - .type('Panel two{enter}'); + .find('input') + .type('Panel two{enter}', { force: true }); }); e2e.pages.Dashboard.Settings.Annotations.NewAnnotation.previewInDashboard().click({ force: true }); diff --git a/package.json b/package.json index 0db6125d884..ded110dd49a 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@emotion/eslint-plugin": "11.11.0", "@grafana/eslint-config": "7.0.0", "@grafana/eslint-plugin": "link:./packages/grafana-eslint-rules", - "@grafana/plugin-e2e": "1.1.1", + "@grafana/plugin-e2e": "1.2.0", "@grafana/tsconfig": "^1.3.0-rc1", "@manypkg/get-packages": "^2.2.0", "@playwright/test": "1.43.1", diff --git a/packages/grafana-e2e-selectors/src/selectors/components.ts b/packages/grafana-e2e-selectors/src/selectors/components.ts index ccfef3f8388..7dd6dd3ecb3 100644 --- a/packages/grafana-e2e-selectors/src/selectors/components.ts +++ b/packages/grafana-e2e-selectors/src/selectors/components.ts @@ -218,22 +218,22 @@ export const Components = { }, PanelEditor: { General: { - content: 'Panel editor content', + content: 'data-testid Panel editor content', }, OptionsPane: { - content: 'Panel editor option pane content', + content: 'data-testid Panel editor option pane content', select: 'Panel editor option pane select', fieldLabel: (type: string) => `${type} field property editor`, fieldInput: (title: string) => `data-testid Panel editor option pane field input ${title}`, }, // not sure about the naming *DataPane* DataPane: { - content: 'Panel editor data pane content', + content: 'data-testid Panel editor data pane content', }, applyButton: 'data-testid Apply changes and go back to dashboard', toggleVizPicker: 'data-testid toggle-viz-picker', toggleVizOptions: 'data-testid toggle-viz-options', - toggleTableView: 'toggle-table-view', + toggleTableView: 'data-testid toggle-table-view', // [Geomap] Map controls showZoomField: 'Map controls Show zoom control field property editor', @@ -252,7 +252,7 @@ export const Components = { content: 'Panel inspector Stats content', }, Json: { - content: 'Panel inspector Json content', + content: 'data-testid Panel inspector Json content', }, Query: { content: 'Panel inspector Query content', @@ -377,8 +377,9 @@ export const Components = { backArrow: 'data-testid Go Back', }, OptionsGroup: { - group: (title?: string) => (title ? `Options group ${title}` : 'Options group'), - toggle: (title?: string) => (title ? `Options group ${title} toggle` : 'Options group toggle'), + group: (title?: string) => (title ? `data-testid Options group ${title}` : 'data-testid Options group'), + toggle: (title?: string) => + title ? `data-testid Options group ${title} toggle` : 'data-testid Options group toggle', }, PluginVisualization: { item: (title: string) => `Plugin visualization item ${title}`, @@ -535,8 +536,8 @@ export const Components = { variableOption: 'data-testid variable-option', }, Annotations: { - annotationsTypeInput: 'annotations-type-input', - annotationsChoosePanelInput: 'choose-panels-input', + annotationsTypeInput: 'data-testid annotations-type-input', + annotationsChoosePanelInput: 'data-testid choose-panels-input', editor: { testButton: 'data-testid annotations-test-button', resultContainer: 'data-testid annotations-query-result-container', diff --git a/packages/grafana-e2e-selectors/src/selectors/pages.ts b/packages/grafana-e2e-selectors/src/selectors/pages.ts index 5368be3830a..fabdda9e0b8 100644 --- a/packages/grafana-e2e-selectors/src/selectors/pages.ts +++ b/packages/grafana-e2e-selectors/src/selectors/pages.ts @@ -43,9 +43,9 @@ export const Pages = { AddDashboard: { url: '/dashboard/new', itemButton: (title: string) => `data-testid ${title}`, - addNewPanel: 'Add new panel', - addNewRow: 'Add new row', - addNewPanelLibrary: 'Add new panel from panel library', + addNewPanel: 'data-testid Add new panel', + addNewRow: 'data-testid Add new row', + addNewPanelLibrary: 'data-testid Add new panel from panel library', }, Dashboard: { url: (uid: string) => `/d/${uid}`, @@ -103,11 +103,11 @@ export const Pages = { annotations: 'data-testid list-annotations', }, Settings: { - name: 'Annotations settings name input', + name: 'data-testid Annotations settings name input', }, NewAnnotation: { panelFilterSelect: 'data-testid annotations-panel-filter', - showInLabel: 'show-in-label', + showInLabel: 'data-testid show-in-label', previewInDashboard: 'data-testid annotations-preview', delete: 'data-testid annotations-delete', apply: 'data-testid annotations-apply', diff --git a/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx b/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx index ce9e21371f0..e43ac6f5d0f 100644 --- a/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx +++ b/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx @@ -163,7 +163,7 @@ export class InspectJsonTab extends SceneObjectBase { return (
-
+
{ - + <>