@@ -42,76 +42,51 @@ test.describe.serial('Items planning plannings - Sorting', () => {
4242 const itemsPlanningPlanningPage = new ItemsPlanningPlanningPage ( page ) ;
4343 await page . waitForTimeout ( 1000 ) ;
4444
45+ // Click once for ascending sort
46+ await itemsPlanningPlanningPage . clickIdTableHeader ( ) ;
4547 let list = await page . locator ( 'td.planningId' ) . all ( ) ;
46- const planningBefore = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
47-
48- for ( let i = 0 ; i < 2 ; i ++ ) {
49- await itemsPlanningPlanningPage . clickIdTableHeader ( ) ;
50-
51- list = await page . locator ( 'td.planningId' ) . all ( ) ;
52- const planningAfter = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
53-
54- const sortIcon = await page . locator ( 'th.planningId' ) . locator ( '.ng-trigger-leftPointer' ) . getAttribute ( 'style' ) ;
55- let sorted ;
56- if ( sortIcon === 'transform: rotate(45deg);' ) {
57- sorted = [ ...planningBefore ] . sort ( ) . reverse ( ) ;
58- } else if ( sortIcon === 'expand_less' ) {
59- sorted = planningBefore ;
60- } else {
61- sorted = [ ...planningBefore ] . sort ( ) ;
62- }
63- expect ( sorted ) . toEqual ( planningAfter ) ;
64- }
48+ const ascValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
49+ const sortedAsc = [ ...ascValues ] . sort ( ) ;
50+ expect ( ascValues ) . toEqual ( sortedAsc ) ;
51+
52+ // Click again for descending sort
53+ await itemsPlanningPlanningPage . clickIdTableHeader ( ) ;
54+ list = await page . locator ( 'td.planningId' ) . all ( ) ;
55+ const descValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
56+ const sortedDesc = [ ...descValues ] . sort ( ) . reverse ( ) ;
57+ expect ( descValues ) . toEqual ( sortedDesc ) ;
6558 } ) ;
6659
6760 test ( 'should be able to sort by Name' , async ( ) => {
6861 const itemsPlanningPlanningPage = new ItemsPlanningPlanningPage ( page ) ;
6962
63+ await itemsPlanningPlanningPage . clickNameTableHeader ( ) ;
7064 let list = await page . locator ( 'td.planningName' ) . all ( ) ;
71- const planningBefore = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
72-
73- for ( let i = 0 ; i < 2 ; i ++ ) {
74- await itemsPlanningPlanningPage . clickNameTableHeader ( ) ;
75-
76- list = await page . locator ( 'td.planningName' ) . all ( ) ;
77- const planningAfter = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
78-
79- const sortIcon = await page . locator ( 'th.planningName' ) . locator ( '.ng-trigger-leftPointer' ) . getAttribute ( 'style' ) ;
80- let sorted ;
81- if ( sortIcon === 'transform: rotate(45deg);' ) {
82- sorted = [ ...planningBefore ] . sort ( ) . reverse ( ) ;
83- } else if ( sortIcon === 'expand_less' ) {
84- sorted = planningBefore ;
85- } else {
86- sorted = [ ...planningBefore ] . sort ( ) ;
87- }
88- expect ( sorted ) . toEqual ( planningAfter ) ;
89- }
65+ const ascValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
66+ const sortedAsc = [ ...ascValues ] . sort ( ) ;
67+ expect ( ascValues ) . toEqual ( sortedAsc ) ;
68+
69+ await itemsPlanningPlanningPage . clickNameTableHeader ( ) ;
70+ list = await page . locator ( 'td.planningName' ) . all ( ) ;
71+ const descValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
72+ const sortedDesc = [ ...descValues ] . sort ( ) . reverse ( ) ;
73+ expect ( descValues ) . toEqual ( sortedDesc ) ;
9074 } ) ;
9175
9276 test ( 'should be able to sort by Description' , async ( ) => {
9377 const itemsPlanningPlanningPage = new ItemsPlanningPlanningPage ( page ) ;
9478
79+ await itemsPlanningPlanningPage . clickDescriptionTableHeader ( ) ;
9580 let list = await page . locator ( 'td.planningDescription' ) . all ( ) ;
96- const planningBefore = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
97-
98- for ( let i = 0 ; i < 2 ; i ++ ) {
99- await itemsPlanningPlanningPage . clickDescriptionTableHeader ( ) ;
100-
101- list = await page . locator ( 'td.planningDescription' ) . all ( ) ;
102- const planningAfter = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
103-
104- const sortIcon = await page . locator ( 'th.planningDescription' ) . locator ( '.ng-trigger-leftPointer' ) . getAttribute ( 'style' ) ;
105- let sorted ;
106- if ( sortIcon === 'transform: rotate(45deg);' ) {
107- sorted = [ ...planningBefore ] . sort ( ) . reverse ( ) ;
108- } else if ( sortIcon === 'expand_less' ) {
109- sorted = planningBefore ;
110- } else {
111- sorted = [ ...planningBefore ] . sort ( ) ;
112- }
113- expect ( sorted ) . toEqual ( planningAfter ) ;
114- }
81+ const ascValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
82+ const sortedAsc = [ ...ascValues ] . sort ( ) ;
83+ expect ( ascValues ) . toEqual ( sortedAsc ) ;
84+
85+ await itemsPlanningPlanningPage . clickDescriptionTableHeader ( ) ;
86+ list = await page . locator ( 'td.planningDescription' ) . all ( ) ;
87+ const descValues = await Promise . all ( list . map ( ( item ) => item . textContent ( ) ) ) ;
88+ const sortedDesc = [ ...descValues ] . sort ( ) . reverse ( ) ;
89+ expect ( descValues ) . toEqual ( sortedDesc ) ;
11590 } ) ;
11691
11792 test ( 'should clear table' , async ( ) => {
0 commit comments