diff --git a/src/pages/manageCycleCount/ManageCycleCountPage.ts b/src/pages/manageCycleCount/ManageCycleCountPage.ts index 9cea97e..79808c9 100644 --- a/src/pages/manageCycleCount/ManageCycleCountPage.ts +++ b/src/pages/manageCycleCount/ManageCycleCountPage.ts @@ -96,6 +96,38 @@ class ManageCycleCountPage extends BasePageModel { return this.page.locator(`#${describedBy}`); } + get binLocationFilterGroup() { + return this.page.locator('.filter-group', { + has: this.page.locator('label[for="internalLocations"]'), + }); + } + + get binLocationSelect() { + return this.binLocationFilterGroup.getByTestId('custom-select-element'); + } + + get binLocationSelectDropdown() { + return this.page.getByTestId('custom-select-dropdown-menu'); + } + + get binLocationSelectHasValue() { + return this.binLocationSelect.locator('.filter-select-has-value'); + } + + getBinLocationOption(binLocationName: string) { + return this.binLocationSelectDropdown + .getByRole('listitem') + .filter({ hasText: binLocationName }); + } + + // selects the option but doesn't submit the filter - call filterButton + // afterwards to apply it, same as the other filters on this page + async selectBinLocationFilter(binLocationName: string) { + await this.binLocationSelect.click(); + await this.binLocationSelect.getByRole('textbox').fill(binLocationName); + await this.getBinLocationOption(binLocationName).click({ timeout: 5_000 }); + } + // ACTIONS get markAsToCountButton() { return this.page.getByRole('button', { name: 'Mark as To Count' }); diff --git a/src/tests/cycleCount/changeLocationOnAllProductTab.test.ts b/src/tests/cycleCount/changeLocationOnAllProductTab.test.ts new file mode 100644 index 0000000..dcf5c32 --- /dev/null +++ b/src/tests/cycleCount/changeLocationOnAllProductTab.test.ts @@ -0,0 +1,129 @@ +import AppConfig from '@/config/AppConfig'; +import { expect, test } from '@/fixtures/fixtures'; +import { StockMovementResponse } from '@/types'; +import { deleteShipment, receiveInbound } from '@/utils/shipmentUtils'; + +test.describe('Change location on All Products tab', () => { + const productCode = '8'; + const productName = AppConfig.instance.products[productCode].name; + + let STOCK_MOVEMENT: StockMovementResponse; + + test.beforeEach( + async ({ supplierLocationService, stockMovementService, receivingService }) => { + const supplierLocation = await supplierLocationService.getLocation(); + const productId = AppConfig.instance.products[productCode].readId(); + + STOCK_MOVEMENT = await stockMovementService.createInbound({ + originId: supplierLocation.id, + }); + await stockMovementService.addItemsToInboundStockMovement( + STOCK_MOVEMENT.id, + [{ productId, quantity: 15 }] + ); + await receiveInbound( + { stockMovementService, receivingService }, + STOCK_MOVEMENT, + [15] + ); + } + ); + + test.afterEach(async ({ stockMovementService }) => { + await deleteShipment({ stockMovementService, STOCK_MOVEMENT }); + }); + + test('Change location on All Products tab', async ({ + page, + manageCycleCountPage, + depotLocationService, + ccDepotService, + }) => { + // several filter-apply/reload retries on top of the normal step time, + // comfortably over the default 60s test timeout + test.setTimeout(120_000); + + const binLocationName = + AppConfig.instance.receivingBinPrefix + STOCK_MOVEMENT.identifier; + + const applyBinLocationFilter = async () => { + await manageCycleCountPage.selectBinLocationFilter(binLocationName); + await manageCycleCountPage.filterButton.click(); + await manageCycleCountPage.allProductsTable.isLoaded(); + }; + + await test.step('Filter All Products tab by the new Bin Location and select the product', async () => { + await expect(async () => { + await manageCycleCountPage.goToPage(); + await manageCycleCountPage.isLoaded(); + await manageCycleCountPage.openAllProductsTab(); + await applyBinLocationFilter(); + await expect(manageCycleCountPage.allProductsTable.rows).toHaveCount(1); + }).toPass({ timeout: 30_000, intervals: [2000, 3000, 5000] }); + + const row = manageCycleCountPage.allProductsTable.row(0); + await expect(row.product).toContainText(productName); + // the All Products tab's Bin Location column renders the name in + // lowercase, unlike the real Location.name or the filter's own options + await expect(row.binLocation).toContainText( + new RegExp(binLocationName, 'i') + ); + + await row.checkbox.check(); + await expect(manageCycleCountPage.markAsToCountButton).toBeEnabled(); + }); + + await test.step('Switch to depot location and assert the Bin Location filter is empty', async () => { + await depotLocationService.switchLocation(); + await manageCycleCountPage.goToPage(); + await manageCycleCountPage.isLoaded(); + await manageCycleCountPage.openAllProductsTab(); + + await expect(manageCycleCountPage.binLocationSelectHasValue).toHaveCount(0); + }); + + await test.step('Assert the product is not selected and not present on All Products tab in depot', async () => { + await expect( + manageCycleCountPage.allProductsTable.rows.filter({ hasText: productName }) + ).toHaveCount(0); + await expect(manageCycleCountPage.markAsToCountButton).toBeDisabled(); + }); + + await test.step('Assert the new Bin Location is not selectable in the filter in depot', async () => { + await manageCycleCountPage.binLocationSelect.click(); + await manageCycleCountPage.binLocationSelect + .getByRole('textbox') + .fill(binLocationName); + await expect( + manageCycleCountPage.getBinLocationOption(binLocationName) + ).toHaveCount(0); + }); + + await test.step('Switch back to the CC location and reapply the Bin Location filter', async () => { + await ccDepotService.switchLocation(); + + await expect(async () => { + await manageCycleCountPage.goToPage(); + await manageCycleCountPage.isLoaded(); + await manageCycleCountPage.openAllProductsTab(); + await applyBinLocationFilter(); + await expect(manageCycleCountPage.allProductsTable.rows).toHaveCount(1); + }).toPass({ timeout: 30_000, intervals: [2000, 3000, 5000] }); + + await expect(manageCycleCountPage.binLocationSelectHasValue).toBeVisible(); + }); + + await test.step('Reload the page and assert the Bin Location filter value is not reset', async () => { + await expect(async () => { + await page.reload(); + await manageCycleCountPage.isLoaded(); + await manageCycleCountPage.allProductsTable.isLoaded(); + await expect(manageCycleCountPage.allProductsTable.rows).toHaveCount(1); + }).toPass({ timeout: 30_000, intervals: [2000, 3000, 5000] }); + + await expect(manageCycleCountPage.binLocationSelectHasValue).toBeVisible(); + const row = manageCycleCountPage.allProductsTable.row(0); + await expect(row.product).toContainText(productName); + }); + }); +});