-
Notifications
You must be signed in to change notification settings - Fork 69
/
merchant-orders-status-change.spec.js
238 lines (200 loc) · 7.07 KB
/
merchant-orders-status-change.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* External dependencies
*/
import config from 'config';
/**
* Internal dependencies
*/
import { fillCardDetails, setupProductCheckout } from '../../../utils/payments';
const { merchant, shopper, uiUnblocked } = require( '@woocommerce/e2e-utils' );
const orderIdSelector = '.woocommerce-order-overview__order.order > strong';
const orderStatusDropdownSelector = 'select[name="order_status"]';
const cancelModalSelector = 'div.wcpay-confirmation-modal';
const refundModalSelector = 'div.refund-confirmation-modal';
const refundCancelSelector =
'.refund-confirmation-modal .wcpay-confirmation-modal__footer .is-secondary';
const refundConfirmSelector =
'.refund-confirmation-modal .wcpay-confirmation-modal__footer .is-primary';
const selectedOrderStatusSelector = '.wc-order-status > span';
let orderId;
describe( 'Order > Status Change', () => {
describe( 'Change Status of order to Cancelled', () => {
beforeAll( async () => {
// Place an order to change its status later
await setupProductCheckout(
config.get( 'addresses.customer.billing' )
);
const card = config.get( 'cards.basic' );
await fillCardDetails( page, card );
await shopper.placeOrder();
await expect( page ).toMatchTextContent( 'Order received' );
// Get the order ID so we can open it in the merchant view
const orderIdField = await page.$( orderIdSelector );
orderId = await orderIdField.evaluate( ( el ) => el.innerText );
// Login and open the order
await merchant.login();
await merchant.goToOrder( orderId );
} );
afterAll( async () => {
await merchant.logout();
} );
it( 'Show Cancel Confirmation modal, do not change status if Do Nothing selected', async () => {
// Select cancel from the order status dropdown.
await expect( page ).toSelect(
orderStatusDropdownSelector,
'Cancelled'
);
// Verify the confirmation modal shows.
await page.waitForSelector( cancelModalSelector, {
visible: true,
} );
// Click on Do Nothing.
await expect( page ).toClick( 'button', { text: 'Do Nothing' } );
// Verify the order status is set to processing.
const selectedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
selectedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Processing' );
//click Update Order button and wait for page reloaded.
await expect( page ).toClick( '.save_order' );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
// Verify the order status is set to processing.
const updatedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
updatedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Processing' );
} );
it( 'When Order Status changed to Cancel, show Cancel Confirmation modal, change status to Cancel if confirmed', async () => {
// Select cancel from the order status dropdown.
await expect( page ).toSelect(
orderStatusDropdownSelector,
'Cancelled'
);
// Verify the confirmation modal shows.
await page.waitForSelector( cancelModalSelector, {
visible: true,
} );
// Click on Cancel order.
await expect( page ).toClick( 'button', { text: 'Cancel order' } );
await page.waitForNavigation( { waitUntil: 'networkidle0' } );
// Verify the order status is set to cancel.
const selectedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
selectedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Cancelled' );
//click Update Order button.
await expect( page ).toClick( '.save_order' );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
// Verify the order status is set to processing.
const updatedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
updatedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Cancelled' );
} );
} );
describe( 'Change Status of order to Refunded', () => {
beforeAll( async () => {
// Place an order to change its status later
await setupProductCheckout(
config.get( 'addresses.customer.billing' )
);
const card = config.get( 'cards.basic' );
await fillCardDetails( page, card );
await shopper.placeOrder();
await expect( page ).toMatchTextContent( 'Order received' );
// Get the order ID so we can open it in the merchant view
const orderIdField = await page.$( orderIdSelector );
orderId = await orderIdField.evaluate( ( el ) => el.innerText );
// Login and open the order
await merchant.login();
await merchant.goToOrder( orderId );
} );
afterAll( async () => {
await merchant.logout();
} );
it( 'Show Refund Confirmation modal, do not change status if Cancel clicked', async () => {
// Select refunded from the order status dropdown.
await expect( page ).toSelect(
orderStatusDropdownSelector,
'Refunded'
);
// Verify the confirmation modal shows.
await page.waitForSelector( refundModalSelector, {
visible: true,
} );
// Click on Cancel.
await expect( page ).toClick( refundCancelSelector );
// Verify the order status is set to processing.
const selectedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
selectedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Processing' );
//click Update Order button and wait for page reloaded.
await expect( page ).toClick( '.save_order' );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
// Verify the order status is set to processing.
const updatedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
updatedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Processing' );
} );
it( 'Show Refund Confirmation modal, process Refund if confirmed', async () => {
// Select refunded from the order status dropdown.
await expect( page ).toSelect(
orderStatusDropdownSelector,
'Refunded'
);
// Verify the confirmation modal shows.
await page.waitForSelector( refundModalSelector, {
visible: true,
} );
// Click on Refund order.
await expect( page ).toClick( refundConfirmSelector );
// Wait for refund to be processed
await uiUnblocked();
await page.waitForNavigation( { waitUntil: 'networkidle0' } );
// Get the order price
const priceElement = await page.$(
'#woocommerce-order-items .total .woocommerce-Price-amount'
);
const orderAmount = await page.evaluate(
( el ) => el.textContent,
priceElement
);
//Verify the refund amount is equal to the order amount.
expect( page ).toMatchElement( '.refund > .line_cost', {
text: `-${ orderAmount }`,
} );
//click Update Order button.
await expect( page ).toClick( '.save_order' );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
// Verify the order status is set to refunded.
const updatedOrderStatus = await page.$(
selectedOrderStatusSelector
);
await expect(
updatedOrderStatus.evaluate( ( el ) => el.innerText )
).resolves.toBe( 'Refunded' );
} );
} );
} );