11import { expect , test } from '@grafana/plugin-e2e' ;
22import { ExplorePage } from './fixtures/explore' ;
3+ import { getTestIdFromMetric , testIds } from '../src/utils/testIds' ;
4+ import type { Page } from '@playwright/test' ;
35
46test . describe ( 'navigating app' , ( ) => {
57 let explorePage : ExplorePage ;
6-
8+
79 test . beforeEach ( async ( { page } ) => {
810 explorePage = new ExplorePage ( page ) ;
911 await explorePage . gotoExplorePage ( ) ;
@@ -19,3 +21,81 @@ test.describe('navigating app', () => {
1921 await explorePage . assertMissingData ( ) ;
2022 } ) ;
2123} ) ;
24+
25+ test . describe ( 'ensure back button works for main actions' , ( ) => {
26+ let explorePage : ExplorePage ;
27+
28+ test . beforeEach ( async ( { page } ) => {
29+ explorePage = new ExplorePage ( page ) ;
30+ await explorePage . gotoExplorePage ( ) ;
31+ await explorePage . assertNotLoading ( ) ;
32+ } ) ;
33+
34+ test . afterEach ( async ( ) => {
35+ await explorePage . unroute ( ) ;
36+ } ) ;
37+
38+ test ( 'clicking on errors panel, browser back and browser forward should work as expected' , async ( { page } ) => {
39+ await assertBackAndForwardNavigationWorks ( page , 'rate' , 'errors' ) ;
40+ } ) ;
41+
42+ test ( 'clicking on duration panel, browser back and browser forward should work as expected' , async ( { page } ) => {
43+ await assertBackAndForwardNavigationWorks ( page , 'rate' , 'duration' ) ;
44+ } ) ;
45+ } ) ;
46+
47+ type MetricType = 'rate' | 'errors' | 'duration' ;
48+
49+ async function assertBackAndForwardNavigationWorks ( page : Page , startMetric : MetricType , switchToMetric : MetricType ) {
50+ const explorePage = new ExplorePage ( page ) ;
51+ await explorePage . assertNotLoading ( ) ;
52+
53+ await assertREDPanelRadioVisible ( page , startMetric ) ;
54+ await assertREDPanelRadioVisible ( page , switchToMetric ) ;
55+
56+ await assertCheckedForREDPanelRadio ( page , startMetric ) ;
57+ await assertUnCheckedForREDPanelRadio ( page , switchToMetric ) ;
58+
59+ await clickOnREDPanelRadio ( page , switchToMetric ) ;
60+ await explorePage . assertNotLoading ( ) ;
61+
62+ await assertCheckedForREDPanelRadio ( page , switchToMetric ) ;
63+ await assertUnCheckedForREDPanelRadio ( page , startMetric ) ;
64+
65+ await expect ( page . getByTestId ( testIds . errorState ) ) . not . toBeVisible ( ) ;
66+
67+ await page . goBack ( ) ;
68+ await explorePage . assertNotLoading ( ) ;
69+
70+ await assertCheckedForREDPanelRadio ( page , startMetric ) ;
71+ await assertUnCheckedForREDPanelRadio ( page , switchToMetric ) ;
72+
73+ await expect ( page . getByTestId ( testIds . errorState ) ) . not . toBeVisible ( ) ;
74+
75+ await page . goForward ( ) ;
76+ await explorePage . assertNotLoading ( ) ;
77+
78+ await assertCheckedForREDPanelRadio ( page , switchToMetric ) ;
79+ await assertUnCheckedForREDPanelRadio ( page , startMetric ) ;
80+
81+ await expect ( page . getByTestId ( testIds . errorState ) ) . not . toBeVisible ( ) ;
82+ }
83+
84+ async function assertREDPanelRadioVisible ( page : Page , metric : MetricType ) {
85+ await expect ( page . getByTestId ( getTestIdFromMetric ( metric ) ) ) . toBeVisible ( ) ;
86+ await expect ( page . getByTestId ( getTestIdFromMetric ( metric ) ) . getByRole ( 'radio' ) . first ( ) ) . toBeVisible ( ) ;
87+ }
88+
89+ async function assertCheckedForREDPanelRadio ( page : Page , metric : MetricType ) {
90+ // toBeChecked() is flaky here: `checked` property flickers during re-renders; the attribute is stable.
91+ await expect ( page . getByTestId ( getTestIdFromMetric ( metric ) ) . getByRole ( 'radio' ) . first ( ) ) . toHaveAttribute ( 'checked' ) ;
92+ }
93+
94+ async function assertUnCheckedForREDPanelRadio ( page : Page , metric : MetricType ) {
95+ // toBeChecked() is flaky here: `checked` property flickers during re-renders; the attribute is stable.
96+ await expect ( page . getByTestId ( getTestIdFromMetric ( metric ) ) . getByRole ( 'radio' ) . first ( ) ) . not . toHaveAttribute ( 'checked' ) ;
97+ }
98+
99+ async function clickOnREDPanelRadio ( page : Page , metric : MetricType ) {
100+ await page . getByTestId ( getTestIdFromMetric ( metric ) ) . getByRole ( 'radio' ) . first ( ) . click ( ) ;
101+ }
0 commit comments