@@ -52,6 +52,7 @@ test.describe('Documents Grid', () => {
5252 orderDefault : '' ,
5353 orderDesc : '&ordering=-title' ,
5454 orderAsc : '&ordering=title' ,
55+ defaultColumn : false ,
5556 } ,
5657 {
5758 nameColumn : 'Created at' ,
@@ -60,6 +61,7 @@ test.describe('Documents Grid', () => {
6061 orderDefault : '' ,
6162 orderDesc : '&ordering=-created_at' ,
6263 orderAsc : '&ordering=created_at' ,
64+ defaultColumn : false ,
6365 } ,
6466 {
6567 nameColumn : 'Updated at' ,
@@ -68,6 +70,7 @@ test.describe('Documents Grid', () => {
6870 orderDefault : '&ordering=-updated_at' ,
6971 orderDesc : '&ordering=updated_at' ,
7072 orderAsc : '' ,
73+ defaultColumn : true ,
7174 } ,
7275 ] . forEach (
7376 ( {
@@ -77,6 +80,7 @@ test.describe('Documents Grid', () => {
7780 orderDefault,
7881 orderDesc,
7982 orderAsc,
83+ defaultColumn,
8084 } ) => {
8185 test ( `checks datagrid ordering ${ ordering } ` , async ( { page } ) => {
8286 const responsePromise = page . waitForResponse (
@@ -98,20 +102,19 @@ test.describe('Documents Grid', () => {
98102 ) ;
99103
100104 // Checks the initial state
101- const datagrid = page
102- . getByLabel ( 'Datagrid of the documents page 1' )
103- . getByRole ( 'table' ) ;
104- const thead = datagrid . locator ( 'thead' ) ;
105+ const datagrid = page . getByLabel ( 'Datagrid of the documents page 1' ) ;
106+ const datagridTable = datagrid . getByRole ( 'table' ) ;
107+ const thead = datagridTable . locator ( 'thead' ) ;
105108
106109 const response = await responsePromise ;
107110 expect ( response . ok ( ) ) . toBeTruthy ( ) ;
108111
109- const docNameRow1 = datagrid
112+ const docNameRow1 = datagridTable
110113 . getByRole ( 'row' )
111114 . nth ( 1 )
112115 . getByRole ( 'cell' )
113116 . nth ( cellNumber ) ;
114- const docNameRow2 = datagrid
117+ const docNameRow2 = datagridTable
115118 . getByRole ( 'row' )
116119 . nth ( 2 )
117120 . getByRole ( 'cell' )
@@ -144,13 +147,21 @@ test.describe('Documents Grid', () => {
144147 await expect ( docNameRow2 ) . toHaveText ( / .* / ) ;
145148 const textDocNameRow1Asc = await docNameRow1 . textContent ( ) ;
146149 const textDocNameRow2Asc = await docNameRow2 . textContent ( ) ;
150+
151+ const compare = ( comp1 : string , comp2 : string ) => {
152+ const comparisonResult = comp1 . localeCompare ( comp2 , 'en' , {
153+ caseFirst : 'false' ,
154+ ignorePunctuation : true ,
155+ } ) ;
156+
157+ // eslint-disable-next-line playwright/no-conditional-in-test
158+ return defaultColumn ? comparisonResult >= 0 : comparisonResult <= 0 ;
159+ } ;
160+
147161 expect (
148162 textDocNameRow1Asc &&
149163 textDocNameRow2Asc &&
150- textDocNameRow1Asc . localeCompare ( textDocNameRow2Asc , 'en' , {
151- caseFirst : 'false' ,
152- ignorePunctuation : true ,
153- } ) <= 0 ,
164+ compare ( textDocNameRow1Asc , textDocNameRow2Asc ) ,
154165 ) . toBeTruthy ( ) ;
155166
156167 // Ordering Desc
@@ -171,10 +182,7 @@ test.describe('Documents Grid', () => {
171182 expect (
172183 textDocNameRow1Desc &&
173184 textDocNameRow2Desc &&
174- textDocNameRow1Desc . localeCompare ( textDocNameRow2Desc , 'en' , {
175- caseFirst : 'false' ,
176- ignorePunctuation : true ,
177- } ) >= 0 ,
185+ compare ( textDocNameRow2Desc , textDocNameRow1Desc ) ,
178186 ) . toBeTruthy ( ) ;
179187 } ) ;
180188 } ,
0 commit comments