diff --git a/src/tests/putaway/putawayToHoldBin.test.ts b/src/tests/putaway/putawayToHoldBin.test.ts new file mode 100644 index 0000000..ac7f418 --- /dev/null +++ b/src/tests/putaway/putawayToHoldBin.test.ts @@ -0,0 +1,195 @@ +import AppConfig from '@/config/AppConfig'; +import { ShipmentType } from '@/constants/ShipmentType'; +import { expect, test } from '@/fixtures/fixtures'; +import { StockMovementResponse } from '@/types'; +import BinLocationUtils from '@/utils/BinLocationUtils'; +import RefreshCachesUtils from '@/utils/RefreshCaches'; +import { + deleteReceivedShipment, + getShipmentId, + getShipmentItemId, +} from '@/utils/shipmentUtils'; +import UniqueIdentifier from '@/utils/UniqueIdentifier'; + +test.describe('Putaway item into hold bin', () => { + test.describe.configure({ timeout: 60000 }); + //timeout has been added for this test to make sure that the content on bin location tab will load as it can include a lot of data + let STOCK_MOVEMENT: StockMovementResponse; + const uniqueIdentifier = new UniqueIdentifier(); + const holdBinLocationName = uniqueIdentifier.generateUniqueString('holdbin'); + + test.beforeEach( + async ({ + supplierLocationService, + mainLocationService, + stockMovementService, + productService, + receivingService, + page, + locationListPage, + createLocationPage, + }) => { + const supplierLocation = await supplierLocationService.getLocation(); + productService.setProduct('5'); + const product = await productService.getProduct(); + + STOCK_MOVEMENT = await stockMovementService.createInbound({ + originId: supplierLocation.id, + }); + + await stockMovementService.addItemsToInboundStockMovement( + STOCK_MOVEMENT.id, + [{ productId: product.id, quantity: 10 }] + ); + + await stockMovementService.sendInboundStockMovement(STOCK_MOVEMENT.id, { + shipmentType: ShipmentType.AIR, + }); + + const { data: stockMovement } = + await stockMovementService.getStockMovement(STOCK_MOVEMENT.id); + const shipmentId = getShipmentId(stockMovement); + const { data: receipt } = await receivingService.getReceipt(shipmentId); + const receivingBin = + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier; + + await receivingService.createReceivingBin(shipmentId, receipt); + + await receivingService.updateReceivingItems(shipmentId, [ + { + shipmentItemId: getShipmentItemId(receipt, 0, 0), + quantityReceiving: 10, + binLocationName: receivingBin, + }, + ]); + await receivingService.completeReceipt(shipmentId); + + await test.step('Create bin location with hold stock activity for location', async () => { + await BinLocationUtils.createHoldBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + holdBinLocationName, + }); + }); + } + ); + + test.afterEach( + async ({ + navbar, + transactionListPage, + stockMovementShowPage, + stockMovementService, + page, + locationListPage, + mainLocationService, + createLocationPage, + oldViewShipmentPage, + }) => { + const receivingBin = + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier; + await navbar.configurationButton.click(); + await navbar.transactions.click(); + await transactionListPage.table.row(1).actionsButton.click(); + await transactionListPage.table.deleteButton.click(); + await expect(transactionListPage.successMessage).toBeVisible(); + await transactionListPage.table.row(1).actionsButton.click(); + await transactionListPage.table.deleteButton.click(); + await expect(transactionListPage.successMessage).toBeVisible(); + + await deleteReceivedShipment({ + stockMovementShowPage, + oldViewShipmentPage, + stockMovementService, + STOCK_MOVEMENT, + }); + + await test.step('Deactivate created bin location', async () => { + await BinLocationUtils.deactivateCreatedBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + binLocationName: holdBinLocationName, + }); + }); + + await BinLocationUtils.deactivateReceivingBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + receivingBin, + }); + } + ); + + test('Putaway to hold bin', async ({ + stockMovementShowPage, + createPutawayPage, + putawayDetailsPage, + navbar, + productShowPage, + productService, + }) => { + await test.step('Go to stock movement show page and assert received status', async () => { + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); + await stockMovementShowPage.isLoaded(); + await expect(stockMovementShowPage.statusTag).toHaveText('Received'); + await RefreshCachesUtils.refreshCaches({ + navbar, + }); + }); + + await test.step('Go to create putaway page', async () => { + await navbar.inbound.click(); + await navbar.createPutaway.click(); + await createPutawayPage.isLoaded(); + }); + + await test.step('Start putaway', async () => { + await createPutawayPage.table.row(0).checkbox.click(); + await createPutawayPage.startPutawayButton.click(); + await createPutawayPage.startStep.isLoaded(); + }); + + await test.step('Select bin to putaway', async () => { + await createPutawayPage.startStep.table.row(0).putawayBinSelect.click(); + await createPutawayPage.startStep.table + .row(0) + .getPutawayBin(holdBinLocationName) + .click(); + await createPutawayPage.startStep.nextButton.click(); + }); + + await test.step('Go to next page and complete putaway', async () => { + await createPutawayPage.completeStep.isLoaded(); + await createPutawayPage.completeStep.completePutawayButton.click(); + }); + + await test.step('Assert completing putaway', async () => { + await putawayDetailsPage.isLoaded(); + await expect(putawayDetailsPage.statusTag).toHaveText('Completed'); + }); + + await test.step('Assert putaway bin on stock card', async () => { + await putawayDetailsPage.summaryTab.click(); + productService.setProduct('5'); + const product = await productService.getProduct(); + await productShowPage.goToPage(product.id); + await productShowPage.inStockTab.click(); + await productShowPage.inStockTabSection.isLoaded(); + await expect( + productShowPage.inStockTabSection.row(1).binLocation + ).toHaveText(holdBinLocationName); + await expect( + productShowPage.inStockTabSection.row(1).row + ).toHaveAttribute('title', 'This bin has been restricted'); + await expect( + productShowPage.inStockTabSection.row(1).inventoryInformation + ).toHaveText('Hold'); + }); + }); +}); diff --git a/src/tests/receiving/receiveToHoldBin.test.ts b/src/tests/receiving/receiveToHoldBin.test.ts index 61ee06f..a5888e3 100644 --- a/src/tests/receiving/receiveToHoldBin.test.ts +++ b/src/tests/receiving/receiveToHoldBin.test.ts @@ -10,7 +10,7 @@ test.describe('Receive item into hold bin', () => { //timeout has been added for this test to make sure that the content on bin location tab will load as it can include a lot of data let STOCK_MOVEMENT: StockMovementResponse; const uniqueIdentifier = new UniqueIdentifier(); - const binLocationName = uniqueIdentifier.generateUniqueString('holdbin'); + const holdBinLocationName = uniqueIdentifier.generateUniqueString('holdbin'); test.beforeEach( async ({ @@ -23,7 +23,6 @@ test.describe('Receive item into hold bin', () => { createLocationPage, }) => { const supplierLocation = await supplierLocationService.getLocation(); - const mainLocation = await mainLocationService.getLocation(); productService.setProduct('1'); const PRODUCT_ONE = await productService.getProduct(); @@ -41,44 +40,13 @@ test.describe('Receive item into hold bin', () => { }); await test.step('Create bin location with hold stock activity for location', async () => { - await page.goto('./location/list'); - await locationListPage.searchByLocationNameField.fill( - mainLocation.name - ); - await locationListPage.findButton.click(); - await expect( - locationListPage.getLocationEditButton(mainLocation.name) - ).toBeVisible(); - await locationListPage.getLocationEditButton(mainLocation.name).click(); - await createLocationPage.binLocationTab.click(); - await createLocationPage.binLocationTabSection.isLoaded(); - await createLocationPage.binLocationTabSection.addBinLocationButton.click(); - await createLocationPage.binLocationTabSection.addBinLocationDialog.binLocationNameField.fill( - binLocationName - ); - await createLocationPage.binLocationTabSection.addBinLocationDialog.saveButton.click(); - await createLocationPage.binLocationTab.click(); - await createLocationPage.binLocationTabSection.searchField.fill( - binLocationName - ); - await createLocationPage.binLocationTabSection.searchField.press( - 'Enter' - ); - await createLocationPage.binLocationTabSection.isLoaded(); - await createLocationPage.binLocationTabSection.editBinButton.click(); - await createLocationPage.locationConfigurationTab.click(); - await createLocationPage.locationConfigurationTabSection.useDefaultSettingsCheckbox.uncheck(); - await createLocationPage.locationConfigurationTabSection - .removeSupportedActivitiesButton('Putaway stock') - .click(); - await createLocationPage.locationConfigurationTabSection - .removeSupportedActivitiesButton('Pick stock') - .click(); - await createLocationPage.locationConfigurationTabSection.supportedActivitiesSelect.click(); - await createLocationPage.locationConfigurationTabSection - .getSupportedActivitiesOption('Hold stock') - .click(); - await createLocationPage.locationConfigurationTabSection.saveButton.click(); + await BinLocationUtils.createHoldBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + holdBinLocationName, + }); }); } ); @@ -92,7 +60,6 @@ test.describe('Receive item into hold bin', () => { mainLocationService, createLocationPage, }) => { - const mainLocation = await mainLocationService.getLocation(); const receivingBin = AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier; await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); @@ -100,29 +67,14 @@ test.describe('Receive item into hold bin', () => { await stockMovementShowPage.rollbackButton.click(); await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id); - await test.step('Deactitave created bin location', async () => { - await page.goto('./location/list'); - await locationListPage.searchByLocationNameField.fill( - mainLocation.name - ); - await locationListPage.findButton.click(); - await expect( - locationListPage.getLocationEditButton(mainLocation.name) - ).toBeVisible(); - await locationListPage.getLocationEditButton(mainLocation.name).click(); - await createLocationPage.binLocationTab.click(); - await createLocationPage.binLocationTabSection.isLoaded(); - await createLocationPage.binLocationTabSection.searchField.fill( - binLocationName - ); - await createLocationPage.binLocationTabSection.searchField.press( - 'Enter' - ); - await createLocationPage.binLocationTabSection.isLoaded(); - await createLocationPage.binLocationTabSection.editBinButton.click(); - await createLocationPage.locationConfigurationTab.click(); - await createLocationPage.locationConfigurationTabSection.activeCheckbox.uncheck(); - await createLocationPage.locationConfigurationTabSection.saveButton.click(); + await test.step('Deactivate created bin location', async () => { + await BinLocationUtils.deactivateCreatedBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + binLocationName: holdBinLocationName, + }); }); await BinLocationUtils.deactivateReceivingBin({ @@ -155,7 +107,7 @@ test.describe('Receive item into hold bin', () => { await receivingPage.receivingStep.table.row(1).binLocationSelect.click(); await receivingPage.receivingStep.table .row(1) - .getBinLocation(binLocationName) + .getBinLocation(holdBinLocationName) .click(); await receivingPage.receivingStep.table .row(1) @@ -176,7 +128,7 @@ test.describe('Receive item into hold bin', () => { await test.step('Assert edited bin on Packing list', async () => { await expect( stockMovementShowPage.packingListTable.row(1).binLocation - ).toHaveText(binLocationName); + ).toHaveText(holdBinLocationName); }); await test.step('Go to product page and assert bin location', async () => { @@ -185,7 +137,7 @@ test.describe('Receive item into hold bin', () => { await productShowPage.inStockTabSection.isLoaded(); await expect( productShowPage.inStockTabSection.row(2).binLocation - ).toHaveText(binLocationName); + ).toHaveText(holdBinLocationName); await expect( productShowPage.inStockTabSection.row(2).row ).toHaveAttribute('title', 'This bin has been restricted'); diff --git a/src/utils/BinLocationUtils.ts b/src/utils/BinLocationUtils.ts index e41c53f..16a55d0 100644 --- a/src/utils/BinLocationUtils.ts +++ b/src/utils/BinLocationUtils.ts @@ -35,6 +35,84 @@ class BinLocationUtils { await createLocationPage.locationConfigurationTabSection.activeCheckbox.uncheck(); await createLocationPage.locationConfigurationTabSection.saveButton.click(); } + + static async createHoldBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + holdBinLocationName, + }: { + mainLocationService: LocationData; + locationListPage: LocationListPage; + createLocationPage: CreateLocationPage; + page: Page; + holdBinLocationName: string; + }) { + const mainLocation = await mainLocationService.getLocation(); + await page.goto('./location/list'); + await locationListPage.searchByLocationNameField.fill(mainLocation.name); + await locationListPage.findButton.click(); + await locationListPage.getLocationEditButton(mainLocation.name).click(); + await createLocationPage.binLocationTab.click(); + await createLocationPage.binLocationTabSection.isLoaded(); + await createLocationPage.binLocationTabSection.addBinLocationButton.click(); + await createLocationPage.binLocationTabSection.addBinLocationDialog.binLocationNameField.fill( + holdBinLocationName + ); + await createLocationPage.binLocationTabSection.addBinLocationDialog.saveButton.click(); + await createLocationPage.binLocationTab.click(); + await createLocationPage.binLocationTabSection.searchField.fill( + holdBinLocationName + ); + await createLocationPage.binLocationTabSection.searchField.press('Enter'); + await createLocationPage.binLocationTabSection.isLoaded(); + await createLocationPage.binLocationTabSection.editBinButton.click(); + await createLocationPage.locationConfigurationTab.click(); + await createLocationPage.locationConfigurationTabSection.useDefaultSettingsCheckbox.uncheck(); + await createLocationPage.locationConfigurationTabSection + .removeSupportedActivitiesButton('Putaway stock') + .click(); + await createLocationPage.locationConfigurationTabSection + .removeSupportedActivitiesButton('Pick stock') + .click(); + await createLocationPage.locationConfigurationTabSection.supportedActivitiesSelect.click(); + await createLocationPage.locationConfigurationTabSection + .getSupportedActivitiesOption('Hold stock') + .click(); + await createLocationPage.locationConfigurationTabSection.saveButton.click(); + } + + static async deactivateCreatedBin({ + mainLocationService, + locationListPage, + createLocationPage, + page, + binLocationName, + }: { + mainLocationService: LocationData; + locationListPage: LocationListPage; + createLocationPage: CreateLocationPage; + page: Page; + binLocationName: string; + }) { + const mainLocation = await mainLocationService.getLocation(); + await page.goto('./location/list'); + await locationListPage.searchByLocationNameField.fill(mainLocation.name); + await locationListPage.findButton.click(); + await locationListPage.getLocationEditButton(mainLocation.name).click(); + await createLocationPage.binLocationTab.click(); + await createLocationPage.binLocationTabSection.isLoaded(); + await createLocationPage.binLocationTabSection.searchField.fill( + binLocationName + ); + await createLocationPage.binLocationTabSection.searchField.press('Enter'); + await createLocationPage.binLocationTabSection.isLoaded(); + await createLocationPage.binLocationTabSection.editBinButton.click(); + await createLocationPage.locationConfigurationTab.click(); + await createLocationPage.locationConfigurationTabSection.activeCheckbox.uncheck(); + await createLocationPage.locationConfigurationTabSection.saveButton.click(); + } } export default BinLocationUtils;