1
|
|
|
// / <reference types="Cypress" /> |
2
|
|
|
const uuid = require('uuid/v4'); |
3
|
|
|
|
4
|
|
|
describe('Customer: Test pagination and the corosponding URL parameters', () => { |
5
|
|
|
before(() => { |
6
|
|
|
let countryId, paymentMethodId, salesChannelId, groupId, salutationId; |
7
|
|
|
cy.setToInitialState().then(() => { |
|
|
|
|
8
|
|
|
cy.searchViaAdminApi({ |
|
|
|
|
9
|
|
|
endpoint: 'country', data: { |
10
|
|
|
field: 'iso', |
11
|
|
|
type: 'equals', |
12
|
|
|
value: 'DE' |
13
|
|
|
} |
14
|
|
|
}).then(data => { |
15
|
|
|
countryId = data.id; |
16
|
|
|
return cy.searchViaAdminApi({ |
|
|
|
|
17
|
|
|
endpoint: 'payment-method', |
18
|
|
|
data: { |
19
|
|
|
field: 'name', |
20
|
|
|
type: 'equals', |
21
|
|
|
value: 'Invoice' |
22
|
|
|
} |
23
|
|
|
}) |
24
|
|
|
}).then(data => { |
25
|
|
|
paymentMethodId = data.id |
26
|
|
|
return cy.searchViaAdminApi({ |
|
|
|
|
27
|
|
|
endpoint: 'sales-channel', data: { |
28
|
|
|
field: 'name', |
29
|
|
|
type: 'equals', |
30
|
|
|
value: 'Storefront' |
31
|
|
|
} |
32
|
|
|
}) |
33
|
|
|
}).then(data => { |
34
|
|
|
salesChannelId = data.id; |
35
|
|
|
return cy.searchViaAdminApi({ |
|
|
|
|
36
|
|
|
endpoint: 'customer-group', data: { |
37
|
|
|
field: 'name', |
38
|
|
|
type: 'equals', |
39
|
|
|
value: 'Standard customer group' |
40
|
|
|
} |
41
|
|
|
}) |
42
|
|
|
}).then(data => { |
43
|
|
|
groupId = data.id; |
44
|
|
|
return cy.searchViaAdminApi({ |
|
|
|
|
45
|
|
|
endpoint: 'salutation', data: { |
46
|
|
|
field: 'displayName', |
47
|
|
|
type: 'equals', |
48
|
|
|
value: 'Mr.' |
49
|
|
|
} |
50
|
|
|
}) |
51
|
|
|
}).then(data => { |
52
|
|
|
salutationId = data.id; |
53
|
|
|
return cy.authenticate() |
|
|
|
|
54
|
|
|
}).then(auth => { |
55
|
|
|
|
56
|
|
|
let customers = []; |
57
|
|
|
for (let i = 1; i <= 26; i++) { |
58
|
|
|
const standInId = uuid().replace(/-/g, ''); |
59
|
|
|
customers.push( |
60
|
|
|
{ |
61
|
|
|
firstName: 'Pep', |
62
|
|
|
lastName: `Eroni-${i}`, |
63
|
|
|
defaultPaymentMethodId: paymentMethodId, |
64
|
|
|
defaultBillingAddressId: standInId, |
65
|
|
|
defaultShippingAddressId: standInId, |
66
|
|
|
customerNumber: uuid().replace(/-/g, ''), |
67
|
|
|
email: `test-${i}@example.com` |
68
|
|
|
} |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
customers = customers.map(customer => Object.assign({ countryId, salesChannelId, salutationId, groupId }, customer)); |
72
|
|
|
return cy.request({ |
|
|
|
|
73
|
|
|
headers: { |
74
|
|
|
Accept: 'application/vnd.api+json', |
75
|
|
|
Authorization: `Bearer ${auth.access}`, |
76
|
|
|
'Content-Type': 'application/json' |
77
|
|
|
}, |
78
|
|
|
method: 'POST', |
79
|
|
|
url: '/api/v3/_action/sync', |
80
|
|
|
qs: { |
81
|
|
|
response: true |
82
|
|
|
}, |
83
|
|
|
body: { |
84
|
|
|
'write-customer': { |
85
|
|
|
'entity': 'customer', |
86
|
|
|
'action': 'upsert', |
87
|
|
|
'payload': customers |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
}) |
92
|
|
|
}); |
93
|
|
|
}); |
94
|
|
|
|
95
|
|
|
}) |
96
|
|
|
|
97
|
|
|
it('@Customer: check that the url parameters get set', () => { |
98
|
|
|
cy.loginViaApi(); |
|
|
|
|
99
|
|
|
|
100
|
|
|
cy.openInitialPage(`${Cypress.env('admin')}#/sw/customer/index`); |
|
|
|
|
101
|
|
|
|
102
|
|
|
// use the search box and check if term gets set (in the function) |
103
|
|
|
cy.get('.sw-search-bar__input').typeAndCheckSearchField('Pep'); |
104
|
|
|
|
105
|
|
|
cy.testListing({ |
106
|
|
|
searchTerm: 'Pep', |
107
|
|
|
sorting: { |
108
|
|
|
text: 'Customer number', |
109
|
|
|
propertyName: 'customerNumber', |
110
|
|
|
sortDirection: 'DESC', |
111
|
|
|
location: 4 |
112
|
|
|
}, |
113
|
|
|
page: 1, |
114
|
|
|
limit: 25 |
115
|
|
|
}); |
116
|
|
|
|
117
|
|
|
cy.log('change Sorting direction from DESC to ASC') |
118
|
|
|
cy.get('.sw-data-grid__cell--4 > .sw-data-grid__cell-content').click('right'); |
119
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
120
|
|
|
|
121
|
|
|
cy.testListing({ |
122
|
|
|
searchTerm: 'Pep', |
123
|
|
|
sorting: { |
124
|
|
|
text: 'Customer number', |
125
|
|
|
propertyName: 'customerNumber', |
126
|
|
|
sortDirection: 'ASC', |
127
|
|
|
location: 4 |
128
|
|
|
}, |
129
|
|
|
page: 1, |
130
|
|
|
limit: 25 |
131
|
|
|
}); |
132
|
|
|
|
133
|
|
|
cy.log('change items per page to 10'); |
134
|
|
|
cy.get('#perPage').select("10"); |
135
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
136
|
|
|
|
137
|
|
|
cy.testListing({ |
138
|
|
|
searchTerm: 'Pep', |
139
|
|
|
sorting: { |
140
|
|
|
text: 'Customer number', |
141
|
|
|
propertyName: 'customerNumber', |
142
|
|
|
sortDirection: 'ASC', |
143
|
|
|
location: 4 |
144
|
|
|
}, |
145
|
|
|
page: 1, |
146
|
|
|
limit: 10 |
147
|
|
|
}); |
148
|
|
|
|
149
|
|
|
cy.log('go to second page') |
150
|
|
|
cy.get(':nth-child(2) > .sw-pagination__list-button').click(); |
151
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
152
|
|
|
|
153
|
|
|
cy.testListing({ |
154
|
|
|
searchTerm: 'Pep', |
155
|
|
|
sorting: { |
156
|
|
|
text: 'Customer number', |
157
|
|
|
propertyName: 'customerNumber', |
158
|
|
|
sortDirection: 'ASC', |
159
|
|
|
location: 4 |
160
|
|
|
}, |
161
|
|
|
page: 2, |
162
|
|
|
limit: 10 |
163
|
|
|
}); |
164
|
|
|
|
165
|
|
|
cy.log('change sorting to Name') |
166
|
|
|
cy.get('.sw-data-grid__cell--0 > .sw-data-grid__cell-content').click('right'); |
167
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
168
|
|
|
|
169
|
|
|
cy.testListing({ |
170
|
|
|
searchTerm: 'Pep', |
171
|
|
|
sorting: { |
172
|
|
|
text: 'Name', |
173
|
|
|
propertyName: 'lastName,firstName', |
174
|
|
|
sortDirection: 'ASC', |
175
|
|
|
location: 0 |
176
|
|
|
}, |
177
|
|
|
page: 2, |
178
|
|
|
limit: 10 |
179
|
|
|
}); |
180
|
|
|
}); |
181
|
|
|
|
182
|
|
|
it('@Customer: check that the url parameters get applied after a reload', () => { |
183
|
|
|
cy.loginViaApi(); |
|
|
|
|
184
|
|
|
|
185
|
|
|
cy.openInitialPage(`${Cypress.env('admin')}#/sw/customer/index?term=Pep&page=2&limit=10&sortBy=lastName,firstName&sortDirection=ASC&naturalSorting=false`) |
|
|
|
|
186
|
|
|
|
187
|
|
|
cy.testListing({ |
188
|
|
|
searchTerm: 'Pep', |
189
|
|
|
sorting: { |
190
|
|
|
text: 'Name', |
191
|
|
|
propertyName: 'lastName,firstName', |
192
|
|
|
sortDirection: 'ASC', |
193
|
|
|
location: 0 |
194
|
|
|
}, |
195
|
|
|
page: 2, |
196
|
|
|
limit: 10 |
197
|
|
|
}); |
198
|
|
|
|
199
|
|
|
cy.reload(); |
200
|
|
|
|
201
|
|
|
cy.testListing({ |
202
|
|
|
searchTerm: 'Pep', |
203
|
|
|
sorting: { |
204
|
|
|
text: 'Name', |
205
|
|
|
propertyName: 'lastName,firstName', |
206
|
|
|
sortDirection: 'ASC', |
207
|
|
|
location: 0 |
208
|
|
|
}, |
209
|
|
|
page: 2, |
210
|
|
|
limit: 10 |
211
|
|
|
}); |
212
|
|
|
}); |
213
|
|
|
}); |
214
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.