@@ -2,50 +2,103 @@ describe('Viewing all requests', () => {
2
2
describe ( 'as a logged out user' , ( ) => {
3
3
it ( 'should show an error message.' , ( ) => {
4
4
// Visit a protected route in order to allow cypress to set the cookie and mock the login
5
- cy . visit ( " /requests" )
5
+ cy . visit ( ' /requests' )
6
6
cy . get ( 'div.alert-heading' ) . contains ( 'Unauthorized' ) . then ( ( ) => {
7
- cy . log ( " A logged out user is not able to view requests." )
7
+ cy . log ( ' A logged out user is not able to view requests.' )
8
8
} )
9
9
} )
10
10
} )
11
11
12
12
describe ( 'as a logged in user' , ( ) => {
13
13
let scientistApiBaseURL = `https://${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_NAME' ) } .scientist.com/api/v2`
14
+ // declare variables that can be used to change how the response is intercepted.
14
15
let requestList
16
+ let loading
17
+ let error
15
18
16
19
beforeEach ( ( ) => {
17
20
// Call the custom cypress command to log in
18
21
cy . login ( Cypress . env ( 'TEST_SCIENTIST_USER' ) , Cypress . env ( 'TEST_SCIENTIST_PW' ) )
19
-
20
22
// Intercept the response from the endpoint to view all requests
23
+ // TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
21
24
cy . intercept ( 'GET' , `${ scientistApiBaseURL } /quote_groups/mine.json` , ( req ) => {
22
- if ( requestList === true ) {
23
- req . reply ( { fixture : 'all-requests/requests.json' } )
24
- } else {
25
- req . reply ( { fixture : 'all-requests/no-requests.json' } )
25
+ if ( ( requestList === undefined ) && ( loading === true ) ) {
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 ) ) {
29
+ // error will be defined
30
+ req . reply ( { statusCode : 500 } )
31
+ } else if ( requestList === true ) {
32
+ // 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' } )
26
36
}
27
- } ) . as ( 'useAllRequests' )
28
- cy . visit ( "/requests" )
37
+ } )
38
+ // 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' } )
40
+ cy . visit ( '/requests' )
29
41
} )
30
42
31
- context ( 'has requests' , ( ) => {
43
+
44
+ context ( 'request list is loading' , ( ) => {
32
45
before ( ( ) => {
33
- requestList = true
46
+ loading = true
34
47
} )
35
- it ( "shows the user's request list." , ( ) => {
36
- cy . get ( 'article.request-item' ) . should ( 'exist ' ) . then ( ( ) => {
37
- cy . log ( 'Successfully viewing request list .' )
48
+ it ( 'should show a loading spinner.' , ( ) => {
49
+ cy . get ( "[aria-label='tail-spin-loading']" ) . should ( 'be.visible ' ) . then ( ( ) => {
50
+ cy . log ( 'Loading spinner displays correctly .' )
38
51
} )
39
52
} )
40
53
} )
41
54
42
- context ( 'has 0 requests' , ( ) => {
43
- before ( ( ) => {
44
- requestList = false
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
+ // })
68
+
69
+ describe ( 'request components are loading successfully, &' , ( ) => {
70
+ context ( 'the user has requests' , ( ) => {
71
+ before ( ( ) => {
72
+ requestList = true
73
+ } )
74
+ it ( "should show the user's request list." , ( ) => {
75
+ cy . get ( 'article.request-item' ) . should ( 'exist' ) . then ( ( ) => {
76
+ cy . log ( 'Successfully viewing request list.' )
77
+ } )
78
+ } )
79
+ } )
80
+
81
+ context ( 'the user has 0 requests' , ( ) => {
82
+ before ( ( ) => {
83
+ requestList = [ ]
84
+ } )
85
+ it ( "should show a message notifying the user they don't have any requests." , ( ) => {
86
+ cy . get ( 'p.no-requests' ) . contains ( 'You do not have any requests yet.' ) . then ( ( ) => {
87
+ cy . log ( 'Successfully viewing request page with no requests.' )
88
+ } )
89
+ } )
45
90
} )
46
- it ( "shows a message notifying the user they don't have any requests." , ( ) => {
47
- cy . get ( 'p.no-requests' ) . contains ( 'You do not have any requests yet.' ) . then ( ( ) => {
48
- cy . log ( 'Successfully viewing request page with no requests.' )
91
+
92
+ context ( 'the user can see the <LinkedButton /> component' , ( ) => {
93
+ [ true , false ] . forEach ( ( value ) => {
94
+ before ( ( ) => {
95
+ requestList = value
96
+ } )
97
+ it ( `should show a button that links to the initialize request page for the default ware ${ value ? 'with a request list' : 'with 0 requests' } .` , ( ) => {
98
+ cy . get ( "a[data-cy='linked-button']" ) . should ( 'have.attr' , 'href' , `/requests/new/make-a-request?id=123` ) . then ( ( ) => {
99
+ cy . log ( 'The <LinkedButton /> component displays correctly' )
100
+ } )
101
+ } )
49
102
} )
50
103
} )
51
104
} )
0 commit comments