1
- import { scientistApiBaseURL } from '../support/e2e'
2
-
3
1
describe ( 'Viewing all requests' , ( ) => {
4
2
describe ( 'as a logged out user' , ( ) => {
5
- it ( 'should show an error message.' , ( ) => {
6
- // Visit a protected route in order to allow cypress to set the cookie and mock the login
3
+ it ( 'shows an error message.' , ( ) => {
7
4
cy . visit ( '/requests' )
8
5
cy . get ( 'div.alert-heading' ) . contains ( 'Unauthorized' ) . then ( ( ) => {
9
6
cy . log ( 'A logged out user is not able to view requests.' )
10
7
} )
11
8
} )
12
9
} )
13
-
10
+
14
11
describe ( 'as a logged in user' , ( ) => {
15
12
// declare variables that can be used to change how the response is intercepted.
16
- let requestList
17
- let loading
13
+ let data
18
14
let error
19
15
20
16
beforeEach ( ( ) => {
21
- // Call the custom cypress command to log in
22
17
cy . login ( Cypress . env ( 'TEST_SCIENTIST_USER' ) , Cypress . env ( 'TEST_SCIENTIST_PW' ) )
23
- // Intercept the response from the endpoint to view all requests
24
- cy . customApiIntercept ( {
25
- action : 'GET' ,
26
- alias : 'useAllRequests' ,
27
- requestURL : `/quote_groups/mine.json` ,
28
- data : requestList ,
29
- defaultFixture : 'all-requests/requests.json' ,
30
- emptyFixture : 'all-requests/no-requests.json' ,
31
- loading,
32
- error
33
- } )
34
- // Intercept the response from the endpoint that gets the default ware ID
35
- cy . customApiIntercept ( {
36
- action : 'GET' ,
37
- alias : 'useDefaultWare' ,
38
- requestURL : `/wares.json?q=make-a-request` ,
39
- defaultFixture : 'all-requests/make-a-request.json' ,
40
- error
41
- } )
42
- cy . visit ( '/requests' )
43
18
} )
44
19
20
+ describe ( 'makes a call to the api' , ( ) => {
21
+ beforeEach ( ( ) => {
22
+ cy . customApiIntercept ( {
23
+ alias : 'useAllRequests' ,
24
+ data,
25
+ error,
26
+ requestURL : `/quote_groups/mine.json` ,
27
+ } )
45
28
46
- context ( 'request list is loading' , ( ) => {
47
- before ( ( ) => {
48
- loading = true
29
+ cy . visit ( '/requests' )
49
30
} )
50
- it ( 'should show a loading spinner.' , ( ) => {
51
- cy . get ( "[aria-label='tail-spin-loading']" ) . should ( 'be.visible' ) . then ( ( ) => {
52
- cy . log ( 'Loading spinner displays correctly.' )
31
+
32
+ context ( 'which when given an invalid access token' , ( ) => {
33
+ before ( ( ) => {
34
+ error = {
35
+ body : {
36
+ message : 'No access token provided.' ,
37
+ } ,
38
+ statusCode : 403 ,
39
+ }
53
40
} )
54
- } )
55
- } )
56
41
57
- context ( 'error while making a request to the api' , ( ) => {
58
- before ( ( ) => {
59
- requestList = undefined
60
- loading = false
61
- error = true
62
- } )
63
- it ( 'should show an error message.' , ( ) => {
64
- cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
65
- cy . log ( 'Successfully hits an error.' )
42
+ it ( 'shows an error message.' , ( ) => {
43
+ cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
44
+ cy . log ( 'Successfully hits an error.' )
45
+ } )
46
+ cy . get ( "div[role='alert']" ) . contains ( 'No access token provided.' )
66
47
} )
67
48
} )
68
- } )
69
49
70
- describe ( 'request components are loading successfully, &' , ( ) => {
71
- context ( 'the user has requests' , ( ) => {
72
- before ( ( ) => {
73
- requestList = true
74
- error = false
75
- } )
76
- it ( "should show the user's request list." , ( ) => {
77
- cy . get ( 'article.request-item' ) . should ( 'exist' ) . then ( ( ) => {
78
- cy . log ( 'Successfully viewing request list.' )
50
+ context ( 'which when returns undefined error and data values' , ( ) => {
51
+ it ( 'shows a loading spinner.' , ( ) => {
52
+ cy . get ( "[aria-label='tail-spin-loading']" ) . should ( 'be.visible' ) . then ( ( ) => {
53
+ cy . log ( 'Loading spinner displays correctly.' )
79
54
} )
80
55
} )
81
56
} )
82
57
83
- context ( 'the user has 0 requests ', ( ) => {
58
+ describe ( 'which when returns a data object ', ( ) => {
84
59
before ( ( ) => {
85
- requestList = false
60
+ data = 'all-requests/requests.json'
61
+ cy . customApiIntercept ( {
62
+ alias : 'useDefaultWare' ,
63
+ data : 'all-requests/make-a-request.json' ,
64
+ error,
65
+ requestURL : '/wares.json' ,
66
+ } )
67
+ } )
68
+
69
+ it ( 'renders the "New Request" button for the default service' , ( ) => {
70
+ cy . get ( "a[data-cy='linked-button']" )
71
+ . should ( 'have.attr' , 'href' , `/requests/new/make-a-request?id=123` )
72
+ . and ( 'have.text' , 'Initiate a New Request' )
73
+ . then ( ( ) => {
74
+ cy . log ( 'The <LinkedButton /> component displays correctly' )
75
+ } )
86
76
} )
87
- it ( "should show a message notifying the user they don't have any requests." , ( ) => {
88
- cy . get ( 'p.no-requests' ) . contains ( 'You do not have any requests yet.' ) . then ( ( ) => {
89
- cy . log ( 'Successfully viewing request page with no requests.' )
77
+
78
+ context ( 'with values' , ( ) => {
79
+ it ( "shows the user's request list." , ( ) => {
80
+ cy . get ( 'article.request-item' )
81
+ . should ( 'exist' )
82
+ . and ( 'have.length' , 3 )
83
+ . then ( ( ) => {
84
+ cy . log ( 'Successfully viewing request list.' )
85
+ } )
90
86
} )
91
87
} )
92
- } )
93
88
94
- context ( 'the user can see the <LinkedButton /> component' , ( ) => {
95
- [ true , false ] . forEach ( ( value ) => {
89
+ context ( 'with no values' , ( ) => {
96
90
before ( ( ) => {
97
- requestList = value
91
+ data = 'all-requests/no-requests.json'
98
92
} )
99
- it ( `should show a button that links to the initialize request page for the default ware ${ value ? 'with a request list' : 'with 0 requests' } .` , ( ) => {
100
- cy . get ( "a[data-cy='linked-button']" ) . should ( 'have.attr' , 'href' , `/requests/new/make-a-request?id=123` ) . then ( ( ) => {
101
- cy . log ( 'The <LinkedButton /> component displays correctly' )
93
+
94
+ it ( "shows a message notifying the user they don't have any requests." , ( ) => {
95
+ cy . get ( 'p.no-requests' ) . contains ( 'You do not have any requests yet.' ) . then ( ( ) => {
96
+ cy . log ( 'Successfully viewing request page with no requests.' )
102
97
} )
103
98
} )
104
99
} )
105
100
} )
106
101
} )
107
102
} )
108
- } )
103
+ } )
0 commit comments