From f32d200fc0047810e03255d38cced0ed36f983ce Mon Sep 17 00:00:00 2001 From: Sarah Zinger Date: Mon, 19 Jul 2021 14:01:31 -0400 Subject: [PATCH] E2E: Add support for data-test-id over aria labels and add importDashboard flow (#36483) * E2E: Add support for data-testids and not just aria-labels. --- contribute/style-guides/e2e.md | 38 ++++++ e2e/suite1/specs/import-dashboard.spec.ts | 122 ++++++++++++++++++ .../src/selectors/components.ts | 14 ++ .../grafana-e2e/src/flows/importDashboard.ts | 55 ++++++++ packages/grafana-e2e/src/flows/index.ts | 1 + packages/grafana-e2e/src/support/selector.ts | 2 + packages/grafana-e2e/src/support/types.ts | 21 ++- .../manage-dashboards/DashboardImportPage.tsx | 6 +- .../components/ImportDashboardForm.tsx | 3 + 9 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 e2e/suite1/specs/import-dashboard.spec.ts create mode 100644 packages/grafana-e2e/src/flows/importDashboard.ts diff --git a/contribute/style-guides/e2e.md b/contribute/style-guides/e2e.md index 4c69945a42a..4a53e065cfd 100644 --- a/contribute/style-guides/e2e.md +++ b/contribute/style-guides/e2e.md @@ -160,3 +160,41 @@ describe('List test', () => { }); }); ``` + +## Aria-Labels vs data-testid +Our selectors are set up to work with both aria-labels and data-testid attributes. Aria-labels help assistive technologies such as screenreaders identify interactive elements of a page for our users. + +A good example of a time to use an aria-label might be if you have a button with an X to close: +``` + + )} diff --git a/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx b/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx index 865a75a07f5..7c679382e62 100644 --- a/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx +++ b/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx @@ -14,6 +14,7 @@ import { DataSourcePicker } from '@grafana/runtime'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; import { DashboardInput, DashboardInputs, DataSourceInput, ImportDashboardDTO } from '../state/reducers'; import { validateTitle, validateUid } from '../utils/validation'; +import { selectors } from '@grafana/e2e-selectors'; interface Props extends Pick, 'register' | 'errors' | 'control' | 'getValues' | 'watch'> { uidReset: boolean; @@ -61,6 +62,7 @@ export const ImportDashboardForm: FC = ({ validate: async (v: string) => await validateTitle(v, getValues().folder.id), })} type="text" + data-testid={selectors.components.ImportDashboardForm.name} /> @@ -137,6 +139,7 @@ export const ImportDashboardForm: FC = ({