1- import { type BrowserContext , type Page } from '@playwright/test'
1+ import { type BrowserContext , type Page , expect } from '@playwright/test'
22import { test } from './fixtures'
33import {
44 getDynamicContentMasks ,
99} from './lib'
1010import { takeScreenshot , assertFixedDimensions } from './lib/visual'
1111import { waitForPageReady } from './lib/waits'
12+ import { HR_TILE_MIN_HEIGHT } from '../../constants/layout'
1213
1314// Test suite configuration
1415test . describe . configure ( { mode : 'serial' } )
@@ -61,17 +62,27 @@ test.describe('Visual Regression Tests', () => {
6162 } )
6263
6364 test . describe ( 'HR-Related Components' , ( ) => {
65+ // Reset devices after each test to prevent state pollution
66+ test . afterEach ( async ( ) => {
67+ await mockMultipleHrDevices ( dashboardPage , [ ] )
68+ await expect ( dashboardPage . getByTestId ( 'hr-tile-card' ) ) . toHaveCount ( 0 )
69+ } )
70+
6471 test ( 'dashboard with HR data' , async ( ) => {
6572 await mockPage . getByLabel ( 'Current BPM' ) . fill ( '155' )
6673 await mockPage . getByRole ( 'button' , { name : 'Zone 4' } ) . click ( )
6774
68- // Wait for HR tile to appear on dashboard
75+ // Wait for HR tile to appear
76+ await expect (
77+ dashboardPage . getByTestId ( 'hr-tile-card' ) . first ( )
78+ ) . toBeVisible ( )
79+
80+ // Assert HR tile height is within limits
6981 const hrTile = dashboardPage . getByTestId ( 'hr-tile-card' ) . first ( )
70- await hrTile . waitFor ( { state : 'visible' , timeout : 5000 } )
7182
7283 // Assert HR tile height is within limits
7384 await assertFixedDimensions ( hrTile , {
74- minHeight : 180 ,
85+ minHeight : HR_TILE_MIN_HEIGHT ,
7586 } )
7687
7788 const dashboard = dashboardPage . getByTestId ( 'dashboard' )
@@ -106,12 +117,17 @@ test.describe('Visual Regression Tests', () => {
106117 } ,
107118 ] )
108119
109- // Assert all HR tiles maintain dimensions
120+ // Wait for HR tiles to appear
110121 const hrTiles = dashboardPage . getByTestId ( 'hr-tile-card' )
122+ await expect ( hrTiles ) . toHaveCount ( 2 )
123+ await expect ( hrTiles . first ( ) ) . toBeVisible ( )
124+ await expect ( hrTiles . nth ( 1 ) ) . toBeVisible ( )
125+
126+ // Assert all HR tiles maintain dimensions
111127 const count = await hrTiles . count ( )
112128 for ( let i = 0 ; i < count ; i ++ ) {
113129 await assertFixedDimensions ( hrTiles . nth ( i ) , {
114- minHeight : 180 ,
130+ minHeight : HR_TILE_MIN_HEIGHT ,
115131 } )
116132 }
117133
@@ -132,6 +148,11 @@ test.describe('Visual Regression Tests', () => {
132148 await mockPage . getByLabel ( 'Current BPM' ) . fill ( String ( 60 + zone * 20 ) )
133149 await mockPage . getByRole ( 'button' , { name : `Zone ${ zone } ` } ) . click ( )
134150
151+ // Wait for HR tile to appear
152+ await expect (
153+ dashboardPage . getByTestId ( 'hr-tile-card' ) . first ( )
154+ ) . toBeVisible ( )
155+
135156 const dashboard = dashboardPage . getByTestId ( 'dashboard' )
136157 await takeScreenshot ( dashboard , `dashboard-hr-zone-${ zone } .png` , {
137158 maxDiffPixelRatio : 0.1 ,
0 commit comments