@@ -5,7 +5,7 @@ import { CloudRunStubs } from '@packages/graphql/test/stubCloudTypes'
5
5
import { cloneDeep } from 'lodash'
6
6
import { useUserProjectStatusStore } from '@packages/frontend-shared/src/store/user-project-status-store'
7
7
8
- function mountComponent ( props : { initialNavExpandedVal ?: boolean , cloudProject ?: { status : CloudRunStatus , numFailedTests : number } , isLoading ?: boolean , online ?: boolean } = { } ) {
8
+ function mountComponent ( props : { initialNavExpandedVal ?: boolean , cloudProject ?: { status : CloudRunStatus , numFailedTests : number } , latestCloudProject ?: { status : CloudRunStatus , numFailedTests : number } , isLoading ?: boolean , online ?: boolean } = { } ) {
9
9
const withDefaults = { initialNavExpandedVal : false , isLoading : false , online : true , ...props }
10
10
let _gql : SidebarNavigationFragment
11
11
@@ -15,23 +15,48 @@ function mountComponent (props: { initialNavExpandedVal?: boolean, cloudProject?
15
15
return defineResult ( { setPreferences : _gql } )
16
16
} )
17
17
18
+ const selectedVariables = withDefaults . cloudProject ? {
19
+ selectedRunNumber : 1 ,
20
+ hasSelectedRun : true ,
21
+ } : {
22
+ selectedRunNumber : - 1 ,
23
+ hasSelectedRun : false ,
24
+ }
25
+
26
+ const latestVariables = withDefaults . latestCloudProject ? {
27
+ latestRunNumber : 1 ,
28
+ hasLatestRun : true ,
29
+ } : {
30
+ latestRunNumber : - 1 ,
31
+ hasLatestRun : false ,
32
+ }
33
+
18
34
cy . mountFragment ( SidebarNavigationFragmentDoc , {
19
35
variableTypes : {
20
- runNumber : 'Int' ,
21
- hasCurrentRun : 'Boolean' ,
36
+ selectedRunNumber : 'Int' ,
37
+ hasSelectedRun : 'Boolean' ,
38
+ latestRunNumber : 'Int' ,
39
+ hasLatestRun : 'Boolean' ,
22
40
} ,
23
41
variables : {
24
- runNumber : 1 ,
25
- hasCurrentRun : true ,
42
+ ... selectedVariables ,
43
+ ... latestVariables ,
26
44
} ,
27
45
onResult ( gql ) {
28
46
if ( ! gql . currentProject ) return
29
47
30
- if ( gql . currentProject ?. cloudProject ?. __typename === 'CloudProject' && withDefaults . cloudProject ) {
31
- gql . currentProject . cloudProject . runByNumber = cloneDeep ( CloudRunStubs . failingWithTests )
32
- gql . currentProject . cloudProject . runByNumber . status = withDefaults . cloudProject . status as CloudRunStatus
33
-
34
- gql . currentProject . cloudProject . runByNumber . totalFailed = withDefaults . cloudProject . numFailedTests
48
+ if ( gql . currentProject ?. cloudProject ?. __typename === 'CloudProject' ) {
49
+ if ( withDefaults . cloudProject ) {
50
+ gql . currentProject . cloudProject . selectedRun = cloneDeep ( CloudRunStubs . failingWithTests )
51
+ gql . currentProject . cloudProject . selectedRun . status = withDefaults . cloudProject . status as CloudRunStatus
52
+ gql . currentProject . cloudProject . selectedRun . totalFailed = withDefaults . cloudProject . numFailedTests
53
+ }
54
+
55
+ if ( withDefaults . latestCloudProject ) {
56
+ gql . currentProject . cloudProject . latestRun = cloneDeep ( CloudRunStubs . failingWithTests )
57
+ gql . currentProject . cloudProject . latestRun . status = withDefaults . latestCloudProject . status as CloudRunStatus
58
+ gql . currentProject . cloudProject . latestRun . totalFailed = withDefaults . latestCloudProject . numFailedTests
59
+ }
35
60
} else {
36
61
gql . currentProject . cloudProject = null
37
62
}
@@ -215,4 +240,75 @@ describe('SidebarNavigation', () => {
215
240
cy . findByTestId ( 'debug-badge' ) . should ( 'not.exist' )
216
241
} )
217
242
} )
243
+
244
+ context ( 'runs status icon' , ( ) => {
245
+ it ( 'renders passing status if run status is "RUNNING" with no failures' , ( ) => {
246
+ mountComponent ( { latestCloudProject : { status : 'RUNNING' , numFailedTests : 0 } } )
247
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run is in progress' )
248
+ cy . percySnapshot ( 'Runs Icon:running' )
249
+ } )
250
+
251
+ it ( 'renders failing status if run status is "RUNNING" with failures' , ( ) => {
252
+ mountComponent ( { latestCloudProject : { status : 'RUNNING' , numFailedTests : 3 } } )
253
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'failing' )
254
+ cy . percySnapshot ( 'Runs Icon:failing' )
255
+ } )
256
+
257
+ it ( 'renders success status when status is "PASSED"' , ( ) => {
258
+ mountComponent ( { latestCloudProject : { status : 'PASSED' , numFailedTests : 0 } } )
259
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run passed' )
260
+ cy . percySnapshot ( 'Runs Icon:passed' )
261
+ } )
262
+
263
+ it ( 'renders failed status when status is "FAILED"' , ( ) => {
264
+ mountComponent ( { latestCloudProject : { status : 'FAILED' , numFailedTests : 1 } } )
265
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run had 1 test failure' )
266
+ cy . percySnapshot ( 'Runs Icon:failed' )
267
+ } )
268
+
269
+ it ( 'renders cancelled status when status is "CANCELLED"' , ( ) => {
270
+ mountComponent ( { latestCloudProject : { status : 'CANCELLED' , numFailedTests : 0 } } )
271
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run has been cancelled' )
272
+ cy . percySnapshot ( 'Runs Icon:cancelled' )
273
+ } )
274
+
275
+ it ( 'renders attention status when abnormal status' , ( ) => {
276
+ for ( const status of [ 'ERRORED' , 'NOTESTS' , 'OVERLIMIT' , 'TIMEDOUT' ] as CloudRunStatus [ ] ) {
277
+ cy . log ( status )
278
+ mountComponent ( { latestCloudProject : { status, numFailedTests : 0 } } )
279
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run had an error' )
280
+ }
281
+
282
+ cy . percySnapshot ( 'Runs Icon:errored' )
283
+ } )
284
+
285
+ it ( 'renders attention status when abnormal status and failing tests' , ( ) => {
286
+ for ( const status of [ 'ERRORED' , 'NOTESTS' , 'OVERLIMIT' , 'TIMEDOUT' ] as CloudRunStatus [ ] ) {
287
+ cy . log ( status )
288
+ mountComponent ( { latestCloudProject : { status, numFailedTests : 3 } } )
289
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'be.visible' ) . contains ( 'Latest run had an error with 3 test failures' )
290
+ }
291
+ } )
292
+
293
+ it ( 'renders no status if no cloudProject' , ( ) => {
294
+ mountComponent ( )
295
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'not.exist' )
296
+ } )
297
+
298
+ it ( 'renders no status when query is loading' , ( ) => {
299
+ const userProjectStatusStore = useUserProjectStatusStore ( )
300
+
301
+ userProjectStatusStore . setProjectFlag ( 'isProjectConnected' , true )
302
+
303
+ mountComponent ( { isLoading : true } )
304
+
305
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'not.exist' )
306
+ } )
307
+
308
+ it ( 'renders no status if offline' , ( ) => {
309
+ mountComponent ( { online : false } )
310
+
311
+ cy . findByTestId ( 'icon-status-message' ) . should ( 'not.exist' )
312
+ } )
313
+ } )
218
314
} )
0 commit comments