@@ -22,21 +22,33 @@ describe('Viewing all requests', () => {
22
22
// Intercept the response from the endpoint to view all requests
23
23
// TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
24
24
cy . intercept ( 'GET' , `${ scientistApiBaseURL } /quote_groups/mine.json` , ( req ) => {
25
- if ( ( requestList === undefined ) && ( loading === true ) ) {
25
+ switch ( true ) {
26
26
// reply with an empty response: both data and error will be undefined.
27
- req . reply ( )
28
- } else if ( ( requestList === undefined ) && ( loading === false ) && ( error === true ) ) {
27
+ case loading : req . reply ( )
28
+ break
29
+
29
30
// error will be defined
30
- req . reply ( { statusCode : 500 } )
31
- } else if ( requestList === true ) {
31
+ case error : req . reply ( { statusCode : 500 } )
32
+ break
33
+
34
+ case requestList : req . reply ( { fixture : 'all-requests/requests.json' } )
35
+ break
36
+
32
37
// reply with a request body- default status code is 200
33
- req . reply ( { fixture : 'all-requests/requests.json' } )
34
- } else if ( requestList === false ) {
35
- req . reply ( { fixture : 'all-requests/no-requests.json' } )
38
+ case ! requestList : req . reply ( { fixture : 'all-requests/no-requests.json' } )
39
+ break
36
40
}
37
41
} )
38
42
// Intercept the response from the endpoint that gets the default ware ID
39
- cy . intercept ( 'GET' , `${ scientistApiBaseURL } /wares.json?q=make-a-request` , { fixture : 'all-requests/make-a-request.json' } )
43
+ cy . intercept ( 'GET' , `${ scientistApiBaseURL } /wares.json?q=make-a-request` , ( req ) => {
44
+ switch ( true ) {
45
+ case error : req . reply ( { statusCode : 500 } )
46
+ break
47
+
48
+ default : req . reply ( { fixture : 'all-requests/make-a-request.json' } )
49
+ break
50
+ }
51
+ } )
40
52
cy . visit ( '/requests' )
41
53
} )
42
54
@@ -52,24 +64,24 @@ describe('Viewing all requests', () => {
52
64
} )
53
65
} )
54
66
55
- // TODO: uncomment this and try to make the page it not get an undefined error
56
- // context('error while making a request to the api', () => {
57
- // before(() => {
58
- // requestList = undefined
59
- // loading = false
60
- // error = true
61
- // })
62
- // it('should show an error message.', () => {
63
- // cy.get("div[role='alert']").should('be.visible').then(() => {
64
- // cy.log('Successfully hits an error.')
65
- // })
66
- // })
67
- // })
67
+ context ( 'error while making a request to the api' , ( ) => {
68
+ before ( ( ) => {
69
+ requestList = undefined
70
+ loading = false
71
+ error = true
72
+ } )
73
+ it ( 'should show an error message.' , ( ) => {
74
+ cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
75
+ cy . log ( 'Successfully hits an error.' )
76
+ } )
77
+ } )
78
+ } )
68
79
69
80
describe ( 'request components are loading successfully, &' , ( ) => {
70
81
context ( 'the user has requests' , ( ) => {
71
82
before ( ( ) => {
72
83
requestList = true
84
+ error = false
73
85
} )
74
86
it ( "should show the user's request list." , ( ) => {
75
87
cy . get ( 'article.request-item' ) . should ( 'exist' ) . then ( ( ) => {
0 commit comments