diff --git a/src/fixtures/fixtures.ts b/src/fixtures/fixtures.ts index a9241a4..348724e 100644 --- a/src/fixtures/fixtures.ts +++ b/src/fixtures/fixtures.ts @@ -14,6 +14,8 @@ import AppConfig, { } from '@/config/AppConfig'; import CreateInbound from '@/pages/inbound/create/CreateInboundPage'; import InboundListPage from '@/pages/inbound/list/InboundListPage'; +import CreateInvoicePage from '@/pages/invoice/CreateInvoicePage'; +import InvoiceListPage from '@/pages/invoice/InvoiceListPage'; import CreateLocationPage from '@/pages/location/createLocation/CreateLocationPage'; import LocationListPage from '@/pages/location/LocationListPage'; import CreateLocationGroupPage from '@/pages/locationGroup/CreateLocationGroupPage'; @@ -33,8 +35,6 @@ import UserListPage from '@/pages/user/UserListPage'; import LocationData from '@/utils/LocationData'; import ProductData from '@/utils/ProductData'; import UserData from '@/utils/UserData'; -import CreateInvoicePage from '@/pages/invoice/CreateInvoicePage'; -import InvoiceListPage from '@/pages/invoice/InvoiceListPage'; type Fixtures = { // PAGES diff --git a/src/pages/inbound/list/InboundStockMovementTable.ts b/src/pages/inbound/list/InboundStockMovementTable.ts index ca0c93a..e0e3094 100644 --- a/src/pages/inbound/list/InboundStockMovementTable.ts +++ b/src/pages/inbound/list/InboundStockMovementTable.ts @@ -26,6 +26,10 @@ class InboundStockMovementTable extends BasePageModel { get allDateCreatedColumnCells() { return this.table.locator('[role="row"] [role="gridcell"]:nth-child(9)'); } + + get emptyInboundList() { + return this.table.locator('.rt-noData'); + } } class Row extends BasePageModel { diff --git a/src/tests/inbound/createInbound/exportItems.test.ts b/src/tests/inbound/createInbound/exportItems.test.ts index ec2615a..e0f35fb 100644 --- a/src/tests/inbound/createInbound/exportItems.test.ts +++ b/src/tests/inbound/createInbound/exportItems.test.ts @@ -4,6 +4,7 @@ import { WorkbookUtils } from '@/utils/WorkbookUtils'; test.describe('Export all incoming items', () => { let INBOUND_ID: string; + let INBOUND2_ID: string; const workbooks: WorkbookUtils[] = []; test.beforeEach( @@ -13,19 +14,20 @@ test.describe('Export all incoming items', () => { mainProductService, mainUserService, otherProductService, - stockMovementShowPage + stockMovementShowPage, + inboundListPage, }) => { const ORIGIN = await supplierLocationService.getLocation(); const DESCRIPTION = 'some description'; const USER = await mainUserService.getUser(); const TODAY = getToday(); - + const PRODUCT_ONE = await mainProductService.getProduct(); const PRODUCT_TWO = await otherProductService.getProduct(); const SHIPMENT_TYPE = 'Land'; const EXPECTED_DELIVERY_DATE = getDateByOffset(TODAY, 1); - - const ROWS = [ + + const ROWS1 = [ { product: { productCode: PRODUCT_ONE.productCode, @@ -42,11 +44,62 @@ test.describe('Export all incoming items', () => { }, ]; + const ROWS2 = [ + { + product: { + productCode: PRODUCT_ONE.productCode, + productName: PRODUCT_ONE.name, + }, + quantity: '10', + }, + ]; + + await inboundListPage.goToPage(); + const ifInboundListPageIsEmpty = + await inboundListPage.table.emptyInboundList.isVisible(); + + if (ifInboundListPageIsEmpty) { + await test.step('Create and ship stock movement when inbound list is empty', async () => { + await createInboundPage.goToPage(); + await createInboundPage.createStep.originSelect.findAndSelectOption( + ORIGIN.name + ); + await createInboundPage.createStep.requestedBySelect.findAndSelectOption( + USER.name + ); + await createInboundPage.createStep.dateRequestedDatePicker.fill( + TODAY + ); + await createInboundPage.createStep.descriptionField.textbox.fill( + DESCRIPTION + ); + await createInboundPage.nextButton.click(); + await createInboundPage.addItemsStep.isLoaded(); + await createInboundPage.wizzardSteps.assertActiveStep('Add items'); + + INBOUND2_ID = createInboundPage.getId(); + + await createInboundPage.addItemsStep.addItems(ROWS2); + await createInboundPage.nextButton.click(); + await createInboundPage.sendStep.isLoaded(); + + await createInboundPage.sendStep.shipmentTypeSelect.findAndSelectOption( + SHIPMENT_TYPE + ); + await createInboundPage.sendStep.expectedDeliveryDatePicker.fill( + EXPECTED_DELIVERY_DATE + ); + await createInboundPage.sendStep.sendShipmentButton.click(); + await stockMovementShowPage.waitForUrl(); + await stockMovementShowPage.isLoaded(); + }); + } + await test.step('Go to create stock movement', async () => { await createInboundPage.goToPage(); await createInboundPage.createStep.isLoaded(); }); - + await test.step('Create Stock Movement step', async () => { await createInboundPage.createStep.originSelect.findAndSelectOption( ORIGIN.name @@ -59,21 +112,21 @@ test.describe('Export all incoming items', () => { DESCRIPTION ); }); - + await test.step('Go next step (Add items)', async () => { await createInboundPage.nextButton.click(); await createInboundPage.addItemsStep.isLoaded(); }); - + INBOUND_ID = createInboundPage.getId(); - - await createInboundPage.addItemsStep.addItems(ROWS); - + + await createInboundPage.addItemsStep.addItems(ROWS1); + await test.step('Go to next step (Send)', async () => { await createInboundPage.nextButton.click(); await createInboundPage.sendStep.isLoaded(); }); - + await test.step('Fill shipment fields (Send)', async () => { await createInboundPage.sendStep.shipmentTypeSelect.findAndSelectOption( SHIPMENT_TYPE @@ -88,37 +141,44 @@ test.describe('Export all incoming items', () => { await stockMovementShowPage.waitForUrl(); await stockMovementShowPage.isLoaded(); }); - } ); - test.afterEach(async ({ stockMovementService, stockMovementShowPage }) => { - await stockMovementShowPage.goToPage(INBOUND_ID); - await stockMovementShowPage.isLoaded(); - const isRollbackLastReceiptButtonVisible = - await stockMovementShowPage.rollbackLastReceiptButton.isVisible(); - const isRollbackButtonVisible = - await stockMovementShowPage.rollbackButton.isVisible(); - - // due to failed test, shipment might not be received which will not show the button - if (isRollbackLastReceiptButtonVisible) { - await stockMovementShowPage.rollbackLastReceiptButton.click(); - } + test.afterEach( + async ({ stockMovementService, stockMovementShowPage, page }) => { + await stockMovementShowPage.goToPage(INBOUND_ID); + await stockMovementShowPage.isLoaded(); + const isRollbackLastReceiptButtonVisible = + await stockMovementShowPage.rollbackLastReceiptButton.isVisible(); + const isRollbackButtonVisible = + await stockMovementShowPage.rollbackButton.isVisible(); - if (isRollbackButtonVisible) { - await stockMovementShowPage.rollbackButton.click(); - } + // due to failed test, shipment might not be received which will not show the button + if (isRollbackLastReceiptButtonVisible) { + await stockMovementShowPage.rollbackLastReceiptButton.click(); + } + + if (isRollbackButtonVisible) { + await stockMovementShowPage.rollbackButton.click(); + } + + await stockMovementService.deleteStockMovement(INBOUND_ID); - await stockMovementService.deleteStockMovement(INBOUND_ID); + for (const workbook of workbooks) { + workbook.delete(); + } - for (const workbook of workbooks) { - workbook.delete(); + if (INBOUND2_ID) { + await stockMovementShowPage.goToPage(INBOUND2_ID); + await stockMovementShowPage.isLoaded(); + await stockMovementShowPage.rollbackButton.click(); + await stockMovementService.deleteStockMovement(INBOUND2_ID); + } } - }); + ); test('Export all incoming items should include shipped items', async ({ inboundListPage, - stockMovementShowPage, stockMovementService, }) => { await test.step('Go to inbound list page', async () => { @@ -211,7 +271,7 @@ test.describe('Export all incoming items', () => { }); // TODO: Adjust to rely on the empty database (on empty db it fails, because there is 404 No shipment items found) - test.skip('Export all incoming items should not include received items', async ({ + test('Export all incoming items should not include received items', async ({ inboundListPage, stockMovementShowPage, stockMovementService, @@ -233,8 +293,8 @@ test.describe('Export all incoming items', () => { await test.step('Select item to receive', async () => { await receivingPage.receivingStep.isLoaded(); await receivingPage.receivingStep.table - .row(1) - .receivingNowField.textbox.fill('12'); + .row(1) + .receivingNowField.textbox.fill('12'); await receivingPage.receivingStep.table .row(2) .receivingNowField.textbox.fill('12'); @@ -274,6 +334,4 @@ test.describe('Export all incoming items', () => { expect(stockMovementItemsFromFile).toHaveLength(0); }); }); - - });