|
| 1 | +import { ShipmentType } from '@/constants/ShipmentType'; |
| 2 | +import { expect, test } from '@/fixtures/fixtures'; |
| 3 | +import { StockMovementResponse } from '@/types'; |
| 4 | +import { formatDate, getToday } from '@/utils/DateUtils'; |
| 5 | +import { WorkbookUtils } from '@/utils/WorkbookUtils'; |
| 6 | + |
| 7 | +test.describe('Export stock movements', () => { |
| 8 | + let INBOUND1: StockMovementResponse; |
| 9 | + let INBOUND2: StockMovementResponse; |
| 10 | + const workbooks: WorkbookUtils[] = []; |
| 11 | + const TODAY = getToday(); |
| 12 | + |
| 13 | + test.beforeEach( |
| 14 | + async ({ |
| 15 | + supplierLocationService, |
| 16 | + stockMovementService, |
| 17 | + mainProductService, |
| 18 | + otherProductService, |
| 19 | + }) => { |
| 20 | + const supplierLocation = await supplierLocationService.getLocation(); |
| 21 | + const PRODUCT_ONE = await mainProductService.getProduct(); |
| 22 | + const PRODUCT_TWO = await otherProductService.getProduct(); |
| 23 | + |
| 24 | + INBOUND1 = await stockMovementService.createInbound({ |
| 25 | + originId: supplierLocation.id, |
| 26 | + }); |
| 27 | + |
| 28 | + await stockMovementService.addItemsToInboundStockMovement(INBOUND1.id, [ |
| 29 | + { |
| 30 | + productId: PRODUCT_ONE.id, |
| 31 | + quantity: 50, |
| 32 | + }, |
| 33 | + { productId: PRODUCT_TWO.id, quantity: 100 }, |
| 34 | + ]); |
| 35 | + |
| 36 | + await stockMovementService.sendInboundStockMovement(INBOUND1.id, { |
| 37 | + shipmentType: ShipmentType.AIR, |
| 38 | + }); |
| 39 | + |
| 40 | + INBOUND2 = await stockMovementService.createInbound({ |
| 41 | + originId: supplierLocation.id, |
| 42 | + }); |
| 43 | + |
| 44 | + await stockMovementService.addItemsToInboundStockMovement(INBOUND2.id, [ |
| 45 | + { |
| 46 | + productId: PRODUCT_ONE.id, |
| 47 | + quantity: 50, |
| 48 | + }, |
| 49 | + ]); |
| 50 | + } |
| 51 | + ); |
| 52 | + |
| 53 | + test.afterEach(async ({ stockMovementService, stockMovementShowPage }) => { |
| 54 | + await stockMovementShowPage.goToPage(INBOUND1.id); |
| 55 | + await stockMovementShowPage.isLoaded(); |
| 56 | + await stockMovementShowPage.rollbackButton.click(); |
| 57 | + await stockMovementService.deleteStockMovement(INBOUND1.id); |
| 58 | + await stockMovementShowPage.goToPage(INBOUND2.id); |
| 59 | + await stockMovementShowPage.isLoaded(); |
| 60 | + await stockMovementService.deleteStockMovement(INBOUND2.id); |
| 61 | + |
| 62 | + for (const workbook of workbooks) { |
| 63 | + workbook.delete(); |
| 64 | + } |
| 65 | + }); |
| 66 | + |
| 67 | + test('Export Stock Movements', async ({ inboundListPage }) => { |
| 68 | + await test.step('Go to inbound list page', async () => { |
| 69 | + await inboundListPage.goToPage(); |
| 70 | + }); |
| 71 | + |
| 72 | + let filePath: string; |
| 73 | + let exportStockMovements: WorkbookUtils; |
| 74 | + |
| 75 | + const ROWS = [ |
| 76 | + { |
| 77 | + status: 'CHECKING', |
| 78 | + receiptStatus: 'PENDING', |
| 79 | + identifier: INBOUND2.identifier, |
| 80 | + name: INBOUND2.description, |
| 81 | + origin: INBOUND2.origin.name, |
| 82 | + destination: INBOUND2.destination.name, |
| 83 | + stocklist: undefined, |
| 84 | + requestedBy: INBOUND2.requestedBy.name, |
| 85 | + dateRequested: INBOUND2.dateRequested.replace(/\//g, '-'), |
| 86 | + dateCreated: INBOUND2.dateCreated.replace(/\//g, '-'), |
| 87 | + dateShipped: formatDate(TODAY, 'MM-DD-YYYY'), |
| 88 | + }, |
| 89 | + { |
| 90 | + status: 'ISSUED', |
| 91 | + receiptStatus: 'SHIPPED', |
| 92 | + identifier: INBOUND1.identifier, |
| 93 | + name: INBOUND1.description, |
| 94 | + origin: INBOUND1.origin.name, |
| 95 | + destination: INBOUND1.destination.name, |
| 96 | + stocklist: undefined, |
| 97 | + requestedBy: INBOUND1.requestedBy.name, |
| 98 | + dateRequested: INBOUND1.dateRequested.replace(/\//g, '-'), |
| 99 | + dateCreated: INBOUND1.dateCreated.replace(/\//g, '-'), |
| 100 | + dateShipped: formatDate(TODAY, 'MM-DD-YYYY'), |
| 101 | + }, |
| 102 | + ]; |
| 103 | + |
| 104 | + await test.step('Download file', async () => { |
| 105 | + const { fullFilePath } = await inboundListPage.exportStockMovements(); |
| 106 | + filePath = fullFilePath; |
| 107 | + }); |
| 108 | + |
| 109 | + let parsedDocumentData: unknown[][]; |
| 110 | + |
| 111 | + await test.step('Read file', async () => { |
| 112 | + exportStockMovements = WorkbookUtils.read(filePath); |
| 113 | + workbooks.push(exportStockMovements); |
| 114 | + parsedDocumentData = exportStockMovements.getData(); |
| 115 | + }); |
| 116 | + |
| 117 | + await test.step('Assert template columns', async () => { |
| 118 | + expect(exportStockMovements.getHeaders()).toStrictEqual([ |
| 119 | + 'Status', |
| 120 | + 'Receipt Status', |
| 121 | + 'Identifier', |
| 122 | + 'Name', |
| 123 | + 'Origin', |
| 124 | + 'Destination', |
| 125 | + 'Stocklist', |
| 126 | + 'Requested by', |
| 127 | + 'Date Requested', |
| 128 | + 'Date Created', |
| 129 | + 'Date Shipped', |
| 130 | + ]); |
| 131 | + }); |
| 132 | + |
| 133 | + for (let i = 0; i < ROWS.length; i++) { |
| 134 | + await test.step(`Assert data of exported template on row: ${i}`, async () => { |
| 135 | + const documentRow = parsedDocumentData[i]; |
| 136 | + const row = ROWS[i]; |
| 137 | + |
| 138 | + expect(documentRow[0]).toEqual(row.status); |
| 139 | + expect(documentRow[1]).toEqual(row.receiptStatus); |
| 140 | + expect(documentRow[2]).toEqual(row.identifier); |
| 141 | + expect(documentRow[3]).toEqual(row.name); |
| 142 | + expect(documentRow[4]).toEqual(row.origin); |
| 143 | + expect(documentRow[5]).toEqual(row.destination); |
| 144 | + expect(documentRow[6]).toEqual(row.stocklist); |
| 145 | + expect(documentRow[7]).toEqual(row.requestedBy); |
| 146 | + expect(documentRow[8]).toEqual(row.dateRequested); |
| 147 | + expect(documentRow[9]).toEqual(row.dateCreated); |
| 148 | + expect(documentRow[10]).toEqual(row.dateShipped); |
| 149 | + }); |
| 150 | + } |
| 151 | + |
| 152 | + await test.step('Use search bar and apply filtering', async () => { |
| 153 | + await inboundListPage.filters.searchField.textbox.fill( |
| 154 | + INBOUND2.identifier |
| 155 | + ); |
| 156 | + await inboundListPage.search(); |
| 157 | + }); |
| 158 | + |
| 159 | + await test.step('Download filtered file', async () => { |
| 160 | + const { fullFilePath } = await inboundListPage.exportStockMovements(); |
| 161 | + filePath = fullFilePath; |
| 162 | + }); |
| 163 | + |
| 164 | + await test.step('Read file', async () => { |
| 165 | + exportStockMovements = WorkbookUtils.read(filePath); |
| 166 | + workbooks.push(exportStockMovements); |
| 167 | + parsedDocumentData = exportStockMovements.getData(); |
| 168 | + expect(parsedDocumentData).toHaveLength(1); |
| 169 | + }); |
| 170 | + |
| 171 | + await test.step('Assert filtered file', async () => { |
| 172 | + const documentRow = parsedDocumentData[0]; |
| 173 | + expect(documentRow[2]).toEqual(ROWS[0].identifier); |
| 174 | + }); |
| 175 | + }); |
| 176 | +}); |
0 commit comments