1
1
import {
2
2
requestUuid as uuid ,
3
- requestPageApiCalls as apiCalls ,
3
+ requestPageApiCalls ,
4
4
} from '../support/e2e'
5
5
6
6
describe ( 'Viewing one request' , ( ) => {
7
- // Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
8
-
9
7
describe ( 'as a logged out user' , ( ) => {
10
8
it ( 'should show an error message.' , ( ) => {
11
9
cy . visit ( `/requests/${ uuid } ` )
@@ -16,17 +14,22 @@ describe('Viewing one request', () => {
16
14
} )
17
15
18
16
describe ( 'as a logged in user' , ( ) => {
17
+ let apiCalls = Object . assign ( { } , requestPageApiCalls )
18
+
19
19
beforeEach ( ( ) => {
20
20
cy . login ( Cypress . env ( 'TEST_SCIENTIST_USER' ) , Cypress . env ( 'TEST_SCIENTIST_PW' ) )
21
21
22
- apiCalls . forEach ( ( item ) => {
23
- const key = Object . keys ( item ) [ 0 ]
24
- cy . customApiIntercept ( item [ key ] )
22
+ Object . entries ( apiCalls ) . forEach ( ( item ) => {
23
+ cy . customApiIntercept ( item [ 1 ] )
25
24
} )
26
-
27
25
cy . visit ( `/requests/${ uuid } ` )
28
26
} )
29
27
28
+ afterEach ( ( ) => {
29
+ // in order for the tests to not be order dependent, we need to reset the apiCalls object to the original state
30
+ apiCalls = Object . assign ( { } , requestPageApiCalls )
31
+ } )
32
+
30
33
describe ( 'makes a call to the api' , ( ) => {
31
34
context ( 'which when given an invalid uuid' , ( ) => {
32
35
before ( ( ) => {
@@ -52,11 +55,12 @@ describe('Viewing one request', () => {
52
55
53
56
context ( 'which when returns undefined error and data values' , ( ) => {
54
57
before ( ( ) => {
55
- apiCalls . forEach ( ( item ) => {
56
- const key = Object . keys ( item ) [ 0 ]
57
-
58
- item [ key ] . data = undefined
59
- item [ key ] . error = undefined
58
+ Object . entries ( apiCalls ) . forEach ( ( [ key , value ] ) => {
59
+ apiCalls [ key ] = {
60
+ ...value ,
61
+ data : undefined ,
62
+ error : undefined ,
63
+ }
60
64
} )
61
65
} )
62
66
@@ -82,53 +86,54 @@ describe('Viewing one request', () => {
82
86
83
87
context ( 'with messages' , ( ) => {
84
88
before ( ( ) => {
85
- cy . customApiIntercept ( {
86
- action : 'GET' ,
87
- alias : 'useAllMessages' ,
88
- requestURL : `/quote_groups/${ uuid } /messages.json` ,
89
- data : messages ,
90
- dataFixture : 'one-request/messages.json' ,
91
- emptyDataFixture : 'empty.json' ,
92
- loading,
93
- error
94
- } )
89
+ apiCalls [ 'useMessages' ] = {
90
+ ...apiCalls [ 'useMessages' ] ,
91
+ data : 'one-request/messages/index.json' ,
92
+ }
95
93
} )
96
94
97
- it ( 'displays the messages' , ( ) => { } )
95
+ it ( 'displays the messages' , ( ) => {
96
+ cy . get ( 'div.card-body p.card-text' )
97
+ . contains ( 'this is a message from the customer' )
98
+ . should ( 'be.visible' )
99
+ } )
98
100
} )
99
101
100
102
context ( 'with documents' , ( ) => {
101
103
before ( ( ) => {
102
- cy . customApiIntercept ( {
103
- action : 'GET' ,
104
- alias : 'useAllSOWs' ,
105
- requestURL : `/quote_groups/${ uuid } /proposals.json` ,
106
- data : proposals ,
107
- dataFixture : 'one-request/proposals.json' ,
108
- emptyDataFixture : 'empty.json' ,
109
- loading,
110
- error
111
- } )
104
+ apiCalls [ 'useAllSOWs' ] = {
105
+ ...apiCalls [ 'useAllSOWs' ] ,
106
+ data : 'one-request/sows/index.json' ,
107
+ }
108
+ apiCalls [ 'getAllPOs' ] = {
109
+ ...apiCalls [ 'getAllPOs' ] ,
110
+ data : 'one-request/pos/index.json' ,
111
+ }
112
112
} )
113
113
114
- it ( 'displays the documents' , ( ) => { } )
114
+ it ( 'displays the documents' , ( ) => {
115
+ cy . get ( 'div.document' ) . should ( 'have.length' , 2 )
116
+ cy . get ( 'div.badge' ) . contains ( 'SOW' ) . should ( 'be.visible' )
117
+ cy . get ( 'div.badge' ) . contains ( 'PO' ) . should ( 'be.visible' )
118
+ } )
115
119
} )
116
120
117
121
context ( 'with files' , ( ) => {
118
122
before ( ( ) => {
119
- cy . customApiIntercept ( {
120
- action : 'GET' ,
121
- alias : 'useAllFiles' ,
122
- requestURL : `/quote_groups/${ uuid } /notes.json` ,
123
- data : files ,
124
- dataFixture : 'one-request/notes.json' ,
125
- emptyDataFixture : 'empty.json' ,
126
- loading,
127
- error
128
- } )
123
+ apiCalls [ 'useFiles' ] = {
124
+ ...apiCalls [ 'useFiles' ] ,
125
+ data : 'one-request/files/index.json' ,
126
+ }
129
127
} )
130
128
131
- it ( 'displays the files' , ( ) => { } )
129
+ it ( 'displays the files' , ( ) => {
130
+ cy . get ( 'div.actions-group' )
131
+ . contains ( 'View Files' )
132
+ . click ( )
133
+ cy . get ( 'div#document-tabs-tabpane-files' )
134
+ . contains ( 'downtown.jpg' )
135
+ . should ( 'be.visible' )
136
+ } )
132
137
} )
133
138
} )
134
139
} )
0 commit comments