|
| 1 | +import _ from 'lodash'; |
| 2 | + |
| 3 | +import AppConfig from '@/config/AppConfig'; |
| 4 | +import { ShipmentType } from '@/constants/ShipmentType'; |
| 5 | +import { expect, test } from '@/fixtures/fixtures'; |
| 6 | +import { StockMovementResponse } from '@/types'; |
| 7 | +import { formatDate, getDateByOffset } from '@/utils/DateUtils'; |
| 8 | +import UniqueIdentifier from '@/utils/UniqueIdentifier'; |
| 9 | +import { WorkbookUtils } from '@/utils/WorkbookUtils'; |
| 10 | + |
| 11 | +test.describe('Export receiving template', () => { |
| 12 | + let STOCK_MOVEMENT: StockMovementResponse; |
| 13 | + const uniqueIdentifier = new UniqueIdentifier(); |
| 14 | + const workbooks: WorkbookUtils[] = []; |
| 15 | + const lot = uniqueIdentifier.generateUniqueString('lot'); |
| 16 | + |
| 17 | + test.beforeEach( |
| 18 | + async ({ |
| 19 | + supplierLocationService, |
| 20 | + stockMovementService, |
| 21 | + mainProductService, |
| 22 | + otherProductService, |
| 23 | + thirdProductService, |
| 24 | + }) => { |
| 25 | + const supplierLocation = await supplierLocationService.getLocation(); |
| 26 | + const PRODUCT_ONE = await mainProductService.getProduct(); |
| 27 | + const PRODUCT_TWO = await otherProductService.getProduct(); |
| 28 | + const PRODUCT_THREE = await thirdProductService.getProduct(); |
| 29 | + |
| 30 | + STOCK_MOVEMENT = await stockMovementService.createInbound({ |
| 31 | + originId: supplierLocation.id, |
| 32 | + }); |
| 33 | + |
| 34 | + await stockMovementService.addItemsToInboundStockMovement( |
| 35 | + STOCK_MOVEMENT.id, |
| 36 | + [ |
| 37 | + { |
| 38 | + productId: PRODUCT_ONE.id, |
| 39 | + quantity: 20, |
| 40 | + lotNumber: lot, |
| 41 | + expirationDate: getDateByOffset(new Date(), 3), |
| 42 | + }, |
| 43 | + { productId: PRODUCT_TWO.id, quantity: 12 }, |
| 44 | + { productId: PRODUCT_THREE.id, quantity: 50 }, |
| 45 | + ] |
| 46 | + ); |
| 47 | + |
| 48 | + await stockMovementService.sendInboundStockMovement(STOCK_MOVEMENT.id, { |
| 49 | + shipmentType: ShipmentType.AIR, |
| 50 | + }); |
| 51 | + } |
| 52 | + ); |
| 53 | + |
| 54 | + test.afterEach(async ({ stockMovementShowPage, stockMovementService }) => { |
| 55 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 56 | + await stockMovementShowPage.rollbackLastReceiptButton.click(); |
| 57 | + await stockMovementShowPage.rollbackButton.click(); |
| 58 | + await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id); |
| 59 | + |
| 60 | + for (const workbook of workbooks) { |
| 61 | + workbook.delete(); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + test('Export receiving template', async ({ |
| 66 | + stockMovementShowPage, |
| 67 | + receivingPage, |
| 68 | + mainProductService, |
| 69 | + otherProductService, |
| 70 | + thirdProductService |
| 71 | + }) => { |
| 72 | + let filePath: string; |
| 73 | + let downloadedExportTemplateFile: WorkbookUtils; |
| 74 | + |
| 75 | + const PRODUCT_ONE = await mainProductService.getProduct(); |
| 76 | + const PRODUCT_TWO = await otherProductService.getProduct(); |
| 77 | + const PRODUCT_THREE = await thirdProductService.getProduct(); |
| 78 | + |
| 79 | + const ROWS = [ |
| 80 | + { |
| 81 | + productCode: PRODUCT_ONE.productCode, |
| 82 | + productName: PRODUCT_ONE.name, |
| 83 | + lotNumber: lot, |
| 84 | + expirationDate: formatDate(getDateByOffset(new Date(), 3)), |
| 85 | + binLocation: |
| 86 | + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier, |
| 87 | + quantityShipped: '20', |
| 88 | + quantityReceived: '20', |
| 89 | + quantityToReceive: '20', |
| 90 | + }, |
| 91 | + { |
| 92 | + productCode: PRODUCT_THREE.productCode, |
| 93 | + productName: PRODUCT_THREE.name, |
| 94 | + binLocation: |
| 95 | + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier, |
| 96 | + quantityShipped: '50', |
| 97 | + quantityReceived: '25', |
| 98 | + quantityToReceive: '50', |
| 99 | + }, |
| 100 | + { |
| 101 | + productCode: PRODUCT_TWO.productCode, |
| 102 | + productName: PRODUCT_TWO.name, |
| 103 | + binLocation: |
| 104 | + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier, |
| 105 | + quantityShipped: '12', |
| 106 | + quantityToReceive: '12', |
| 107 | + receivingNowQty: '12', |
| 108 | + comment: 'e2e_comment', |
| 109 | + }, |
| 110 | + ]; |
| 111 | + |
| 112 | + await test.step('Go to stock movement show page', async () => { |
| 113 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 114 | + await stockMovementShowPage.isLoaded(); |
| 115 | + }); |
| 116 | + |
| 117 | + await test.step('Go to receiving page', async () => { |
| 118 | + await stockMovementShowPage.receiveButton.click(); |
| 119 | + await receivingPage.receivingStep.isLoaded(); |
| 120 | + }); |
| 121 | + |
| 122 | + await test.step('Download export template', async () => { |
| 123 | + const { fullFilePath } = |
| 124 | + await receivingPage.receivingStep.downloadExportTemplate(); |
| 125 | + filePath = fullFilePath; |
| 126 | + }); |
| 127 | + |
| 128 | + let parsedDocumentData: unknown[][]; |
| 129 | + |
| 130 | + await test.step('Read downloaded file', async () => { |
| 131 | + downloadedExportTemplateFile = WorkbookUtils.read(filePath); |
| 132 | + workbooks.push(downloadedExportTemplateFile); |
| 133 | + parsedDocumentData = downloadedExportTemplateFile.getData(); |
| 134 | + }); |
| 135 | + |
| 136 | + await test.step('Assert template columns', async () => { |
| 137 | + expect(downloadedExportTemplateFile.getHeaders()).toStrictEqual([ |
| 138 | + 'Receipt item id', |
| 139 | + 'Shipment item id', |
| 140 | + 'Code', |
| 141 | + 'Name', |
| 142 | + 'Lot/Serial No.', |
| 143 | + 'Expiration date', |
| 144 | + 'Bin Location', |
| 145 | + 'Recipient', |
| 146 | + 'Shipped (each)', |
| 147 | + 'Received', |
| 148 | + 'To receive', |
| 149 | + 'Receiving now (each)', |
| 150 | + 'Comment', |
| 151 | + ]); |
| 152 | + }); |
| 153 | + |
| 154 | + await test.step('Assert exported item count in the template', async () => { |
| 155 | + expect(parsedDocumentData).toHaveLength(3); |
| 156 | + }); |
| 157 | + |
| 158 | + for (let i = 0; i < ROWS.length; i++) { |
| 159 | + await test.step(`Assert data of exported template on row: ${i}`, async () => { |
| 160 | + const documentRow = parsedDocumentData[i]; |
| 161 | + const row = ROWS[i]; |
| 162 | + |
| 163 | + expect(_.toString(documentRow[2])).toEqual(row.productCode); |
| 164 | + expect(documentRow[3]).toEqual(row.productName); |
| 165 | + expect(documentRow[4]).toEqual(row.lotNumber); |
| 166 | + expect(documentRow[5]).toEqual(row.expirationDate); |
| 167 | + expect(documentRow[6]).toEqual(row.binLocation); |
| 168 | + expect(_.toString(documentRow[8])).toEqual(row.quantityShipped); |
| 169 | + expect(_.toString(documentRow[10])).toEqual(row.quantityToReceive); |
| 170 | + }); |
| 171 | + } |
| 172 | + |
| 173 | + await test.step('Select item to receive', async () => { |
| 174 | + await receivingPage.receivingStep.isLoaded(); |
| 175 | + await receivingPage.receivingStep.table |
| 176 | + .row(1) |
| 177 | + .receivingNowField.textbox.fill('20'); |
| 178 | + await receivingPage.receivingStep.table |
| 179 | + .row(2) |
| 180 | + .receivingNowField.textbox.fill('25'); |
| 181 | + }); |
| 182 | + |
| 183 | + await test.step('Go to Check page', async () => { |
| 184 | + await receivingPage.nextButton.click(); |
| 185 | + }); |
| 186 | + |
| 187 | + await test.step('Receive shipment', async () => { |
| 188 | + await receivingPage.checkStep.isLoaded(); |
| 189 | + await receivingPage.checkStep.receiveShipmentButton.click(); |
| 190 | + await stockMovementShowPage.isLoaded(); |
| 191 | + }); |
| 192 | + |
| 193 | + await test.step('Go to receiving page', async () => { |
| 194 | + await stockMovementShowPage.receiveButton.click(); |
| 195 | + await receivingPage.receivingStep.isLoaded(); |
| 196 | + }); |
| 197 | + |
| 198 | + await test.step('Download export template', async () => { |
| 199 | + const { fullFilePath } = |
| 200 | + await receivingPage.receivingStep.downloadExportTemplate(); |
| 201 | + filePath = fullFilePath; |
| 202 | + }); |
| 203 | + |
| 204 | + await test.step('Read downloaded file', async () => { |
| 205 | + downloadedExportTemplateFile = WorkbookUtils.read(filePath); |
| 206 | + workbooks.push(downloadedExportTemplateFile); |
| 207 | + parsedDocumentData = downloadedExportTemplateFile.getData(); |
| 208 | + }); |
| 209 | + |
| 210 | + await test.step('Assert data of exported template on 1st row', async () => { |
| 211 | + const documentRow = parsedDocumentData[0]; |
| 212 | + expect(_.toString(documentRow[8])).toEqual(ROWS[0].quantityShipped); |
| 213 | + expect(_.toString(documentRow[9])).toEqual(ROWS[0].quantityReceived); |
| 214 | + }); |
| 215 | + |
| 216 | + await test.step('Assert data of exported template on 2nd row:', async () => { |
| 217 | + const documentRow = parsedDocumentData[1]; |
| 218 | + expect(_.toString(documentRow[8])).toEqual(ROWS[1].quantityShipped); |
| 219 | + expect(_.toString(documentRow[9])).toEqual(ROWS[1].quantityReceived); |
| 220 | + expect(_.toString(documentRow[10])).toEqual(ROWS[1].quantityReceived); |
| 221 | + }); |
| 222 | + |
| 223 | + await test.step('Assert data of exported template on 3rd row:', async () => { |
| 224 | + const documentRow = parsedDocumentData[2]; |
| 225 | + expect(_.toString(documentRow[8])).toEqual(ROWS[2].quantityShipped); |
| 226 | + expect(_.toString(documentRow[10])).toEqual(ROWS[2].quantityToReceive); |
| 227 | + }); |
| 228 | + |
| 229 | + await test.step('Input qty to receive and comment', async () => { |
| 230 | + await receivingPage.receivingStep.isLoaded(); |
| 231 | + await receivingPage.receivingStep.table |
| 232 | + .row(3) |
| 233 | + .receivingNowField.textbox.fill('12'); |
| 234 | + await receivingPage.receivingStep.table |
| 235 | + .row(3) |
| 236 | + .commentField.textbox.fill('e2e_comment'); |
| 237 | + await receivingPage.receivingStep.saveButton.click(); |
| 238 | + }); |
| 239 | + |
| 240 | + await test.step('Download export template after input data', async () => { |
| 241 | + const { fullFilePath } = |
| 242 | + await receivingPage.receivingStep.downloadExportTemplate(); |
| 243 | + filePath = fullFilePath; |
| 244 | + }); |
| 245 | + |
| 246 | + await test.step('Read downloaded file', async () => { |
| 247 | + downloadedExportTemplateFile = WorkbookUtils.read(filePath); |
| 248 | + workbooks.push(downloadedExportTemplateFile); |
| 249 | + parsedDocumentData = downloadedExportTemplateFile.getData(); |
| 250 | + }); |
| 251 | + |
| 252 | + await test.step('Assert saved input data in export template on row:', async () => { |
| 253 | + const documentRow = parsedDocumentData[2]; |
| 254 | + expect(_.toString(documentRow[11])).toEqual(ROWS[2].receivingNowQty); |
| 255 | + expect(_.toString(documentRow[12])).toEqual(ROWS[2].comment); |
| 256 | + }); |
| 257 | + }); |
| 258 | +}); |
0 commit comments