17
17
18
18
import TaskState from '@/model/TaskState.model'
19
19
20
+ // Get cell text for a column by header name, as an array
21
+ Cypress . Commands . add ( 'getColumnValues' , ( header ) => {
22
+ return cy . get ( '.c-table th' )
23
+ . contains ( header )
24
+ . parents ( 'th' )
25
+ . then ( ( $th ) => cy . get ( `.c-table tr > td:nth-child(${ $th . index ( ) + 1 } )` ) )
26
+ . then ( ( $cells ) => Array . from ( $cells , ( cell ) => cell . innerText . trim ( ) ) )
27
+ } )
28
+
20
29
const initialNumRows = 7
21
30
22
31
describe ( 'Table view' , ( ) => {
@@ -30,7 +39,7 @@ describe('Table view', () => {
30
39
. should ( 'be.visible' )
31
40
} )
32
41
33
- describe ( 'Filters' , ( ) => {
42
+ describe ( 'Filters & sorting ' , ( ) => {
34
43
it ( 'Should filter by ID' , ( ) => {
35
44
cy . get ( '.c-table table > tbody > tr' )
36
45
. should ( 'have.length' , initialNumRows )
@@ -51,6 +60,7 @@ describe('Table view', () => {
51
60
. should ( 'be.visible' )
52
61
}
53
62
} )
63
+
54
64
it ( 'Should filter by task state' , ( ) => {
55
65
cy
56
66
. get ( '.c-table table > tbody > tr' )
@@ -73,6 +83,7 @@ describe('Table view', () => {
73
83
. should ( 'have.length' , 1 )
74
84
. should ( 'be.visible' )
75
85
} )
86
+
76
87
it ( 'Should filter by ID and states' , ( ) => {
77
88
cy
78
89
. get ( '.c-table table > tbody > tr' )
@@ -95,6 +106,7 @@ describe('Table view', () => {
95
106
. get ( 'td [data-cy-task-name=eventually_succeeded]' )
96
107
. should ( 'be.visible' )
97
108
} )
109
+
98
110
it ( 'displays and sorts latest job run time' , ( ) => {
99
111
const nonzeroValues = [
100
112
'00:00:01' ,
@@ -107,27 +119,48 @@ describe('Table view', () => {
107
119
cy . get ( '.c-table' )
108
120
. contains ( 'th' , 'Run Time' ) . as ( 'dTHeader' )
109
121
. click ( )
110
- . get ( 'tbody tr td:nth-child(10)' ) // 10th column
111
- . then ( ( $cells ) => {
112
- expect ( Array . from ( $cells , ( cell ) => cell . innerText . trim ( ) ) ) . to . deep . equal ( [
113
- ...nonzeroValues ,
114
- '' , // no value sorted after numbers
115
- '' ,
116
- ] )
117
- } )
122
+ cy . getColumnValues ( 'Run Time' ) . should ( 'deep.equal' , [
123
+ ...nonzeroValues ,
124
+ '' , // no value sorted after numbers
125
+ '' ,
126
+ ] )
118
127
// sort dt-mean descending
119
128
cy . get ( '@dTHeader' )
120
129
. click ( )
121
- . get ( 'tbody tr td:nth-child(10)' )
122
- . then ( ( $cells ) => {
123
- expect ( Array . from ( $cells , ( cell ) => cell . innerText . trim ( ) ) ) . to . deep . equal ( [
124
- ...nonzeroValues . slice ( ) . reverse ( ) ,
125
- '' , // no value still sorted after numbers
126
- '' ,
127
- ] )
128
- } )
130
+ cy . getColumnValues ( 'Run Time' ) . should ( 'deep.equal' , [
131
+ ...nonzeroValues . slice ( ) . reverse ( ) ,
132
+ '' , // no value still sorted after numbers
133
+ '' ,
134
+ ] )
129
135
} )
130
136
} )
137
+
138
+ it ( 'sorts finish time including estimates' , ( ) => {
139
+ const nonzeroValues = [
140
+ '2020-11-08T22:57:16Z' ,
141
+ '2020-11-08T22:57:19Z' ,
142
+ '2020-11-08T22:57:33Z' ,
143
+ '2020-11-08T22:57:41Z' ,
144
+ '2020-11-08T23:00:36Z' ,
145
+ ]
146
+ // sort finish time ascending
147
+ cy . get ( '.c-table' )
148
+ . contains ( 'th' , 'Finish' ) . as ( 'header' )
149
+ . click ( )
150
+ cy . getColumnValues ( 'Finish' ) . should ( 'deep.equal' , [
151
+ ...nonzeroValues ,
152
+ '' , // no value sorted after numbers
153
+ '' ,
154
+ ] )
155
+ // sort finish time descending
156
+ cy . get ( '@header' )
157
+ . click ( )
158
+ cy . getColumnValues ( 'Finish' ) . should ( 'deep.equal' , [
159
+ ...nonzeroValues . slice ( ) . reverse ( ) ,
160
+ '' , // no value still sorted after numbers
161
+ '' ,
162
+ ] )
163
+ } )
131
164
} )
132
165
133
166
function addView ( view ) {
0 commit comments