|
| 1 | +import { expect, test } from '@/fixtures/fixtures'; |
| 2 | +import { getDateByOffset, getToday } from '@/utils/DateUtils'; |
| 3 | +import { WorkbookUtils } from '@/utils/WorkbookUtils'; |
| 4 | + |
| 5 | +test.describe('Export all incomming items', () => { |
| 6 | + let INBOUND_ID: string; |
| 7 | + const workbooks: WorkbookUtils[] = []; |
| 8 | + |
| 9 | + test.afterEach(async ({ stockMovementService, stockMovementShowPage }) => { |
| 10 | + await stockMovementShowPage.goToPage(INBOUND_ID); |
| 11 | + await stockMovementShowPage.isLoaded(); |
| 12 | + await stockMovementShowPage.rollbackButton.click(); |
| 13 | + await stockMovementService.deleteStockMovement(INBOUND_ID); |
| 14 | + |
| 15 | + for (const workbook of workbooks) { |
| 16 | + workbook.delete(); |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + test('Export all incomming items should include items shipped not received', async ({ |
| 21 | + otherProductService, |
| 22 | + mainProductService, |
| 23 | + mainUserService, |
| 24 | + inboundListPage, |
| 25 | + supplierLocationService, |
| 26 | + createInboundPage, |
| 27 | + stockMovementShowPage, |
| 28 | + stockMovementService, |
| 29 | + }) => { |
| 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 | + ]; |
| 56 | + |
| 57 | + await test.step('Go to create stock movement', async () => { |
| 58 | + await createInboundPage.goToPage(); |
| 59 | + await createInboundPage.createStep.isLoaded(); |
| 60 | + }); |
| 61 | + |
| 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 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + await test.step('Go next step (Add items)', async () => { |
| 76 | + await createInboundPage.nextButton.click(); |
| 77 | + await createInboundPage.addItemsStep.isLoaded(); |
| 78 | + }); |
| 79 | + |
| 80 | + INBOUND_ID = createInboundPage.getId(); |
| 81 | + |
| 82 | + await createInboundPage.addItemsStep.addItems(ROWS); |
| 83 | + |
| 84 | + await test.step('Go to next step (Send)', async () => { |
| 85 | + await createInboundPage.nextButton.click(); |
| 86 | + await createInboundPage.sendStep.isLoaded(); |
| 87 | + }); |
| 88 | + |
| 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 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + await test.step('Send shipment', async () => { |
| 99 | + await createInboundPage.sendStep.sendShipmentButton.click(); |
| 100 | + await stockMovementShowPage.waitForUrl(); |
| 101 | + await stockMovementShowPage.isLoaded(); |
| 102 | + }); |
| 103 | + |
| 104 | + await test.step('Go to inbound list page', async () => { |
| 105 | + await inboundListPage.goToPage(); |
| 106 | + }); |
| 107 | + |
| 108 | + let filePath: string; |
| 109 | + let downloadedTemplateFile: WorkbookUtils; |
| 110 | + |
| 111 | + await test.step('Download file', async () => { |
| 112 | + const { fullFilePath } = await inboundListPage.downloadAllIncomingItems(); |
| 113 | + filePath = fullFilePath; |
| 114 | + }); |
| 115 | + |
| 116 | + await test.step('Read file', async () => { |
| 117 | + downloadedTemplateFile = WorkbookUtils.read(filePath); |
| 118 | + workbooks.push(downloadedTemplateFile); |
| 119 | + }); |
| 120 | + |
| 121 | + await test.step('Assert that both items from stock movement are included in the epxort file', async () => { |
| 122 | + const { data } = await stockMovementService.getStockMovement(INBOUND_ID); |
| 123 | + const fileData = downloadedTemplateFile.getData(); |
| 124 | + |
| 125 | + const stockMovementItemsFromFile = fileData.filter( |
| 126 | + (it) => it[5] === data.identifier |
| 127 | + ); |
| 128 | + expect(stockMovementItemsFromFile).toHaveLength(2); |
| 129 | + }); |
| 130 | + }); |
| 131 | +}); |
0 commit comments