@@ -51,9 +51,7 @@ const examplePlanSmall1 = JSON.parse(
5151 )
5252) ;
5353
54- const TIME_TO_FROM_COLUMN = 2 ;
55- const HEADER_ROW = 0 ;
56- const NUM_COLUMNS = 5 ;
54+ const TIME_TO_FROM_COLUMN = 'countdown' ;
5755
5856/**
5957 * The regular expression used to parse the countdown string.
@@ -124,44 +122,42 @@ test.describe('Time List with controlled clock @clock', () => {
124122 test ( 'Time List shows current events and counts down correctly in real-time mode' , async ( {
125123 page
126124 } ) => {
127- const countUpCells = [
128- getTimeListCellByIndex ( page , 1 , TIME_TO_FROM_COLUMN ) ,
129- getTimeListCellByIndex ( page , 2 , TIME_TO_FROM_COLUMN )
130- ] ;
131- const countdownCells = [
132- getTimeListCellByIndex ( page , 3 , TIME_TO_FROM_COLUMN ) ,
133- getTimeListCellByIndex ( page , 4 , TIME_TO_FROM_COLUMN )
134- ] ;
125+ const countUpRowsNames = [ 'Time since the last time I ate' , 'Time since last accident' ] ;
126+ const countdownRowsNames = [ 'Time until birthday' , 'Time until supper' ] ;
135127
136128 // Verify that the countdown cells are counting down
137- for ( let i = 0 ; i < countdownCells . length ; i ++ ) {
129+ for ( let i = 0 ; i < countdownRowsNames . length ; i ++ ) {
138130 await test . step ( `Countdown cell ${ i + 1 } counts down` , async ( ) => {
139- const countdownCell = countdownCells [ i ] ;
131+ const countdownCell = getTimeListCellByName (
132+ page ,
133+ countdownRowsNames [ i ] ,
134+ TIME_TO_FROM_COLUMN
135+ ) ;
140136 // Get the initial countdown timestamp object
141- const beforeCountdown = await getAndAssertCountdownOrUpObject ( page , i + 3 ) ;
142- // should not have a '-' sign
143- await expect ( countdownCell ) . not . toHaveText ( '-' ) ;
137+ const beforeCountdown = await getAndAssertCountdownOrUpObject ( page , countdownRowsNames [ i ] ) ;
138+ // should have a '-' sign BECAUSE IT'S A COUNTDOWN
139+ await expect ( countdownCell ) . toContainText ( '-' ) ;
144140 // Wait until it changes
145- await expect ( countdownCell ) . not . toHaveText ( beforeCountdown . toString ( ) ) ;
141+ await expect ( countdownCell ) . not . toContainText ( beforeCountdown . toString ( ) ) ;
146142 // Get the new countdown timestamp object
147- const afterCountdown = await getAndAssertCountdownOrUpObject ( page , i + 3 ) ;
143+ const afterCountdown = await getAndAssertCountdownOrUpObject ( page , countdownRowsNames [ i ] ) ;
148144 // Verify that the new countdown timestamp object is less than the old one
149145 expect ( Number ( afterCountdown . seconds ) ) . toBeLessThan ( Number ( beforeCountdown . seconds ) ) ;
150146 } ) ;
151147 }
152148
153149 // Verify that the count-up cells are counting up
154- for ( let i = 0 ; i < countUpCells . length ; i ++ ) {
150+ for ( let i = 0 ; i < countUpRowsNames . length ; i ++ ) {
155151 await test . step ( `Count-up cell ${ i + 1 } counts up` , async ( ) => {
156- const countUpCell = countUpCells [ i ] ;
152+ const countUpCell = getTimeListCellByName ( page , countUpRowsNames [ i ] , TIME_TO_FROM_COLUMN ) ;
157153 // Get the initial count-up timestamp object
158- const beforeCountUp = await getAndAssertCountdownOrUpObject ( page , i + 1 ) ;
159- // should not have a '+' sign
160- await expect ( countUpCell ) . not . toHaveText ( '+' ) ;
154+ const beforeCountUp = await getAndAssertCountdownOrUpObject ( page , countUpRowsNames [ i ] ) ;
155+ // should have a '+' sign BECAUSE IT'S A COUNTUP
156+ await expect ( countUpCell ) . toContainText ( '+' ) ;
161157 // Wait until it changes
162- await expect ( countUpCell ) . not . toHaveText ( beforeCountUp . toString ( ) ) ;
158+ await expect ( countUpCell ) . not . toContainText ( beforeCountUp . toString ( ) ) ;
163159 // Get the new count-up timestamp object
164- const afterCountUp = await getAndAssertCountdownOrUpObject ( page , i + 1 ) ;
160+ const afterCountUp = await getAndAssertCountdownOrUpObject ( page , countUpRowsNames [ i ] ) ;
165161 // Verify that the new count-up timestamp object is greater than the old one
166162 expect ( Number ( afterCountUp . seconds ) ) . toBeGreaterThan ( Number ( beforeCountUp . seconds ) ) ;
167163 } ) ;
@@ -202,8 +198,11 @@ test.describe('Activity progress when now is after end of the activity @clock',
202198 * @param {number } columnIndex
203199 * @returns {import('@playwright/test').Locator } cell
204200 */
205- function getTimeListCellByIndex ( page , rowIndex , columnIndex ) {
206- return page . getByRole ( 'cell' ) . nth ( rowIndex * NUM_COLUMNS + columnIndex ) ;
201+ function getTimeListCellByName ( page , rowName , columnName ) {
202+ const rowLocator = page . getByRole ( 'row' , { name : rowName } ) ;
203+ const cellLocator = rowLocator . locator ( `td.--${ columnName } ` ) ;
204+
205+ return cellLocator ;
207206}
208207
209208/**
@@ -213,8 +212,8 @@ function getTimeListCellByIndex(page, rowIndex, columnIndex) {
213212 * @param {number } columnIndex
214213 * @returns {Promise<string> } text
215214 */
216- async function getTimeListCellTextByIndex ( page , rowIndex , columnIndex ) {
217- const text = await getTimeListCellByIndex ( page , rowIndex , columnIndex ) . innerText ( ) ;
215+ async function getTimeListCellTextByName ( page , rowName , columnName ) {
216+ const text = await getTimeListCellByName ( page , rowName , columnName ) . innerText ( ) ;
218217 return text ;
219218}
220219
@@ -225,12 +224,8 @@ async function getTimeListCellTextByIndex(page, rowIndex, columnIndex) {
225224 * @param {number } rowIndex the row index
226225 * @returns {Promise<CountdownOrUpObject> } The countdown (or countup) object
227226 */
228- async function getAndAssertCountdownOrUpObject ( page , rowIndex ) {
229- const timeToFrom = await getTimeListCellTextByIndex (
230- page ,
231- HEADER_ROW + rowIndex ,
232- TIME_TO_FROM_COLUMN
233- ) ;
227+ async function getAndAssertCountdownOrUpObject ( page , rowName ) {
228+ const timeToFrom = await getTimeListCellTextByName ( page , rowName , TIME_TO_FROM_COLUMN ) ;
234229
235230 expect ( timeToFrom ) . toMatch ( COUNTDOWN_REGEXP ) ;
236231 const match = timeToFrom . match ( COUNTDOWN_REGEXP ) ;
0 commit comments