@@ -2,112 +2,257 @@ import { expect, test } from '@/fixtures/fixtures';
22import { getDateByOffset , getToday } from '@/utils/DateUtils' ;
33import { WorkbookUtils } from '@/utils/WorkbookUtils' ;
44
5- test . describe ( 'Export all incomming items' , ( ) => {
5+ test . describe ( 'Export all incoming items' , ( ) => {
66 let INBOUND_ID : string ;
77 const workbooks : WorkbookUtils [ ] = [ ] ;
88
9+ test . beforeEach (
10+ async ( {
11+ supplierLocationService,
12+ createInboundPage,
13+ mainProductService,
14+ mainUserService,
15+ otherProductService,
16+ stockMovementShowPage
17+ } ) => {
18+ const ORIGIN = await supplierLocationService . getLocation ( ) ;
19+ const DESCRIPTION = 'some description' ;
20+ const USER = await mainUserService . getUser ( ) ;
21+ const TODAY = getToday ( ) ;
22+
23+ const PRODUCT_ONE = await mainProductService . getProduct ( ) ;
24+ const PRODUCT_TWO = await otherProductService . getProduct ( ) ;
25+ const SHIPMENT_TYPE = 'Land' ;
26+ const EXPECTED_DELIVERY_DATE = getDateByOffset ( TODAY , 1 ) ;
27+
28+ const ROWS = [
29+ {
30+ product : {
31+ productCode : PRODUCT_ONE . productCode ,
32+ productName : PRODUCT_ONE . name ,
33+ } ,
34+ quantity : '12' ,
35+ } ,
36+ {
37+ product : {
38+ productCode : PRODUCT_TWO . productCode ,
39+ productName : PRODUCT_TWO . name ,
40+ } ,
41+ quantity : '12' ,
42+ } ,
43+ ] ;
44+
45+ await test . step ( 'Go to create stock movement' , async ( ) => {
46+ await createInboundPage . goToPage ( ) ;
47+ await createInboundPage . createStep . isLoaded ( ) ;
48+ } ) ;
49+
50+ await test . step ( 'Create Stock Movement step' , async ( ) => {
51+ await createInboundPage . createStep . originSelect . findAndSelectOption (
52+ ORIGIN . name
53+ ) ;
54+ await createInboundPage . createStep . requestedBySelect . findAndSelectOption (
55+ USER . name
56+ ) ;
57+ await createInboundPage . createStep . dateRequestedDatePicker . fill ( TODAY ) ;
58+ await createInboundPage . createStep . descriptionField . textbox . fill (
59+ DESCRIPTION
60+ ) ;
61+ } ) ;
62+
63+ await test . step ( 'Go next step (Add items)' , async ( ) => {
64+ await createInboundPage . nextButton . click ( ) ;
65+ await createInboundPage . addItemsStep . isLoaded ( ) ;
66+ } ) ;
67+
68+ INBOUND_ID = createInboundPage . getId ( ) ;
69+
70+ await createInboundPage . addItemsStep . addItems ( ROWS ) ;
71+
72+ await test . step ( 'Go to next step (Send)' , async ( ) => {
73+ await createInboundPage . nextButton . click ( ) ;
74+ await createInboundPage . sendStep . isLoaded ( ) ;
75+ } ) ;
76+
77+ await test . step ( 'Fill shipment fields (Send)' , async ( ) => {
78+ await createInboundPage . sendStep . shipmentTypeSelect . findAndSelectOption (
79+ SHIPMENT_TYPE
80+ ) ;
81+ await createInboundPage . sendStep . expectedDeliveryDatePicker . fill (
82+ EXPECTED_DELIVERY_DATE
83+ ) ;
84+ } ) ;
85+
86+ await test . step ( 'Send shipment' , async ( ) => {
87+ await createInboundPage . sendStep . sendShipmentButton . click ( ) ;
88+ await stockMovementShowPage . waitForUrl ( ) ;
89+ await stockMovementShowPage . isLoaded ( ) ;
90+ } ) ;
91+
92+ }
93+ ) ;
94+
995 test . afterEach ( async ( { stockMovementService, stockMovementShowPage } ) => {
1096 await stockMovementShowPage . goToPage ( INBOUND_ID ) ;
1197 await stockMovementShowPage . isLoaded ( ) ;
12- await stockMovementShowPage . rollbackButton . click ( ) ;
98+ const isRollbackLastReceiptButtonVisible =
99+ await stockMovementShowPage . rollbackLastReceiptButton . isVisible ( ) ;
100+ const isRollbackButtonVisible =
101+ await stockMovementShowPage . rollbackButton . isVisible ( ) ;
102+
103+ // due to failed test, shipment might not be received which will not show the button
104+ if ( isRollbackLastReceiptButtonVisible ) {
105+ await stockMovementShowPage . rollbackLastReceiptButton . click ( ) ;
106+ }
107+
108+ if ( isRollbackButtonVisible ) {
109+ await stockMovementShowPage . rollbackButton . click ( ) ;
110+ }
111+
13112 await stockMovementService . deleteStockMovement ( INBOUND_ID ) ;
14113
15114 for ( const workbook of workbooks ) {
16115 workbook . delete ( ) ;
17116 }
18117 } ) ;
19118
20- test ( 'Export all incomming items should include items shipped not received' , async ( {
21- otherProductService,
22- mainProductService,
23- mainUserService,
119+ test ( 'Export all incoming items should include shipped items' , async ( {
24120 inboundListPage,
25- supplierLocationService,
26- createInboundPage,
27121 stockMovementShowPage,
28122 stockMovementService,
29123 } ) => {
30- const ORIGIN = await supplierLocationService . getLocation ( ) ;
31- const DESCRIPTION = 'some description' ;
32- const USER = await mainUserService . getUser ( ) ;
33- const TODAY = getToday ( ) ;
34-
35- const PRODUCT_ONE = await mainProductService . getProduct ( ) ;
36- const PRODUCT_TWO = await otherProductService . getProduct ( ) ;
37- const SHIPMENT_TYPE = 'Land' ;
38- const EXPECTED_DELIVERY_DATE = getDateByOffset ( TODAY , 1 ) ;
39-
40- const ROWS = [
41- {
42- product : {
43- productCode : PRODUCT_ONE . productCode ,
44- productName : PRODUCT_ONE . name ,
45- } ,
46- quantity : '12' ,
47- } ,
48- {
49- product : {
50- productCode : PRODUCT_TWO . productCode ,
51- productName : PRODUCT_TWO . name ,
52- } ,
53- quantity : '12' ,
54- } ,
55- ] ;
124+ await test . step ( 'Go to inbound list page' , async ( ) => {
125+ await inboundListPage . goToPage ( ) ;
126+ } ) ;
56127
57- await test . step ( 'Go to create stock movement' , async ( ) => {
58- await createInboundPage . goToPage ( ) ;
59- await createInboundPage . createStep . isLoaded ( ) ;
128+ let filePath : string ;
129+ let downloadedTemplateFile : WorkbookUtils ;
130+
131+ await test . step ( 'Download file' , async ( ) => {
132+ const { fullFilePath } = await inboundListPage . downloadAllIncomingItems ( ) ;
133+ filePath = fullFilePath ;
60134 } ) ;
61135
62- await test . step ( 'Create Stock Movement step' , async ( ) => {
63- await createInboundPage . createStep . originSelect . findAndSelectOption (
64- ORIGIN . name
65- ) ;
66- await createInboundPage . createStep . requestedBySelect . findAndSelectOption (
67- USER . name
68- ) ;
69- await createInboundPage . createStep . dateRequestedDatePicker . fill ( TODAY ) ;
70- await createInboundPage . createStep . descriptionField . textbox . fill (
71- DESCRIPTION
72- ) ;
136+ await test . step ( 'Read file' , async ( ) => {
137+ downloadedTemplateFile = WorkbookUtils . read ( filePath ) ;
138+ workbooks . push ( downloadedTemplateFile ) ;
73139 } ) ;
74140
75- await test . step ( 'Go next step (Add items)' , async ( ) => {
76- await createInboundPage . nextButton . click ( ) ;
77- await createInboundPage . addItemsStep . isLoaded ( ) ;
141+ await test . step ( 'Assert that both items from stock movement are included in the export file' , async ( ) => {
142+ const { data } = await stockMovementService . getStockMovement ( INBOUND_ID ) ;
143+ const fileData = downloadedTemplateFile . getData ( ) ;
144+
145+ const stockMovementItemsFromFile = fileData . filter (
146+ ( it ) => it [ 5 ] === data . identifier
147+ ) ;
148+ expect ( stockMovementItemsFromFile ) . toHaveLength ( 2 ) ;
78149 } ) ;
150+ } ) ;
79151
80- INBOUND_ID = createInboundPage . getId ( ) ;
152+ test ( 'Export all incoming items should include shipped items not received items' , async ( {
153+ inboundListPage,
154+ stockMovementShowPage,
155+ stockMovementService,
156+ receivingPage,
157+ } ) => {
158+ let filePath : string ;
159+ let downloadedTemplateFile : WorkbookUtils ;
81160
82- await createInboundPage . addItemsStep . addItems ( ROWS ) ;
161+ await test . step ( 'Go to inbound view page' , async ( ) => {
162+ await stockMovementShowPage . goToPage ( INBOUND_ID ) ;
163+ await stockMovementShowPage . isLoaded ( ) ;
164+ } ) ;
83165
84- await test . step ( 'Go to next step (Send) ' , async ( ) => {
85- await createInboundPage . nextButton . click ( ) ;
86- await createInboundPage . sendStep . isLoaded ( ) ;
166+ await test . step ( 'Go to shipment receiving page ' , async ( ) => {
167+ await stockMovementShowPage . receiveButton . click ( ) ;
168+ await receivingPage . receivingStep . isLoaded ( ) ;
87169 } ) ;
88170
89- await test . step ( 'Fill shipment fields (Send)' , async ( ) => {
90- await createInboundPage . sendStep . shipmentTypeSelect . findAndSelectOption (
91- SHIPMENT_TYPE
92- ) ;
93- await createInboundPage . sendStep . expectedDeliveryDatePicker . fill (
94- EXPECTED_DELIVERY_DATE
95- ) ;
171+ await test . step ( 'Select item to receive' , async ( ) => {
172+ await receivingPage . receivingStep . isLoaded ( ) ;
173+ await receivingPage . receivingStep . table
174+ . row ( 1 )
175+ . receivingNowField . textbox . fill ( '12' ) ;
176+ } ) ;
177+
178+ await test . step ( 'Go to Check page' , async ( ) => {
179+ await receivingPage . nextButton . click ( ) ;
96180 } ) ;
97181
98- await test . step ( 'Send shipment' , async ( ) => {
99- await createInboundPage . sendStep . sendShipmentButton . click ( ) ;
100- await stockMovementShowPage . waitForUrl ( ) ;
182+ await test . step ( 'Receive shipment partially ' , async ( ) => {
183+ await receivingPage . checkStep . isLoaded ( ) ;
184+ await receivingPage . checkStep . receiveShipmentButton . click ( ) ;
101185 await stockMovementShowPage . isLoaded ( ) ;
102186 } ) ;
103187
104188 await test . step ( 'Go to inbound list page' , async ( ) => {
105189 await inboundListPage . goToPage ( ) ;
106190 } ) ;
107191
192+ await test . step ( 'Download file' , async ( ) => {
193+ const { fullFilePath } = await inboundListPage . downloadAllIncomingItems ( ) ;
194+ filePath = fullFilePath ;
195+ } ) ;
196+
197+ await test . step ( 'Read file' , async ( ) => {
198+ downloadedTemplateFile = WorkbookUtils . read ( filePath ) ;
199+ workbooks . push ( downloadedTemplateFile ) ;
200+ } ) ;
201+
202+ await test . step ( 'Assert 1 item from stock movement is included in the export file' , async ( ) => {
203+ const { data } = await stockMovementService . getStockMovement ( INBOUND_ID ) ;
204+ const fileData = downloadedTemplateFile . getData ( ) ;
205+
206+ const stockMovementItemsFromFile = fileData . filter (
207+ ( it ) => it [ 5 ] === data . identifier
208+ ) ;
209+ expect ( stockMovementItemsFromFile ) . toHaveLength ( 1 ) ;
210+ } ) ;
211+ } ) ;
212+
213+ test ( 'Export all incoming items should not include received items' , async ( {
214+ inboundListPage,
215+ stockMovementShowPage,
216+ stockMovementService,
217+ receivingPage,
218+ } ) => {
108219 let filePath : string ;
109220 let downloadedTemplateFile : WorkbookUtils ;
110221
222+ await test . step ( 'Go to inbound view page' , async ( ) => {
223+ await stockMovementShowPage . goToPage ( INBOUND_ID ) ;
224+ await stockMovementShowPage . isLoaded ( ) ;
225+ } ) ;
226+
227+ await test . step ( 'Go to shipment receiving page' , async ( ) => {
228+ await stockMovementShowPage . receiveButton . click ( ) ;
229+ await receivingPage . receivingStep . isLoaded ( ) ;
230+ } ) ;
231+
232+ await test . step ( 'Select item to receive' , async ( ) => {
233+ await receivingPage . receivingStep . isLoaded ( ) ;
234+ await receivingPage . receivingStep . table
235+ . row ( 1 )
236+ . receivingNowField . textbox . fill ( '12' ) ;
237+ await receivingPage . receivingStep . table
238+ . row ( 2 )
239+ . receivingNowField . textbox . fill ( '12' ) ;
240+ } ) ;
241+
242+ await test . step ( 'Go to Check page' , async ( ) => {
243+ await receivingPage . nextButton . click ( ) ;
244+ } ) ;
245+
246+ await test . step ( 'Receive shipment' , async ( ) => {
247+ await receivingPage . checkStep . isLoaded ( ) ;
248+ await receivingPage . checkStep . receiveShipmentButton . click ( ) ;
249+ await stockMovementShowPage . isLoaded ( ) ;
250+ } ) ;
251+
252+ await test . step ( 'Go to inbound list page' , async ( ) => {
253+ await inboundListPage . goToPage ( ) ;
254+ } ) ;
255+
111256 await test . step ( 'Download file' , async ( ) => {
112257 const { fullFilePath } = await inboundListPage . downloadAllIncomingItems ( ) ;
113258 filePath = fullFilePath ;
@@ -118,14 +263,16 @@ test.describe('Export all incomming items', () => {
118263 workbooks . push ( downloadedTemplateFile ) ;
119264 } ) ;
120265
121- await test . step ( 'Assert that both items from stock movement are included in the epxort file' , async ( ) => {
266+ await test . step ( 'Assert received items from stock movement are not included in the export file' , async ( ) => {
122267 const { data } = await stockMovementService . getStockMovement ( INBOUND_ID ) ;
123268 const fileData = downloadedTemplateFile . getData ( ) ;
124269
125270 const stockMovementItemsFromFile = fileData . filter (
126271 ( it ) => it [ 5 ] === data . identifier
127272 ) ;
128- expect ( stockMovementItemsFromFile ) . toHaveLength ( 2 ) ;
273+ expect ( stockMovementItemsFromFile ) . toHaveLength ( 0 ) ;
129274 } ) ;
130275 } ) ;
276+
277+
131278} ) ;
0 commit comments