Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBPIH-6703 and OBPIH-6704 Add tests for cancel remaining qty in receiving #42

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pages/receiving/components/CheckTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Row extends BasePageModel {
getItem(name: string) {
return this.row.getByTestId('label-field').getByText(name);
}

get cancelRemainingCheckbox() {
return this.row.getByTestId('checkbox');
}
}

export default CheckTable;
4 changes: 4 additions & 0 deletions src/pages/receiving/steps/CheckStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class CheckStep extends BasePageModel {
get deliveredOnField() {
return this.page.getByRole('textbox', { name: 'Delivered on' });
}

get cancelAllRemainingButton() {
return this.page.getByRole('button', { name: 'Cancel all remaining' });
}
}

export default CheckStep;
377 changes: 377 additions & 0 deletions src/tests/receiving/cancelRemainingQty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,377 @@
import { ShipmentType } from '@/constants/ShipmentType';
import { expect, test } from '@/fixtures/fixtures';
import { StockMovementResponse } from '@/types';

test.describe('Cancel qty in the middle of receipt', () => {
let STOCK_MOVEMENT: StockMovementResponse;

test.beforeEach(
async ({
supplierLocationService,
stockMovementService,
mainProductService,
otherProductService,
}) => {
const supplierLocation = await supplierLocationService.getLocation();
const PRODUCT_ONE = await mainProductService.getProduct();
const PRODUCT_TWO = await otherProductService.getProduct();

STOCK_MOVEMENT = await stockMovementService.createInbound({
originId: supplierLocation.id,
});

await stockMovementService.addItemsToInboundStockMovement(
STOCK_MOVEMENT.id,
[
{
productId: PRODUCT_ONE.id,
quantity: 100,
},
{ productId: PRODUCT_TWO.id, quantity: 10 },
]
);

await stockMovementService.sendInboundStockMovement(STOCK_MOVEMENT.id, {
shipmentType: ShipmentType.AIR,
});
}
);

test.afterEach(async ({ stockMovementShowPage, stockMovementService }) => {
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
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();
}

if (isRollbackButtonVisible) {
await stockMovementShowPage.rollbackButton.click();
}

await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id);
});

test('Cancel remaining qty when receive item partially', async ({
stockMovementShowPage,
receivingPage,
}) => {
await test.step('Go to stock movement show page', async () => {
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
await stockMovementShowPage.isLoaded();
});

await test.step('Go to shipment receiving page', async () => {
await stockMovementShowPage.receiveButton.click();
await receivingPage.receivingStep.isLoaded();
});

await test.step('Input receiving qty for both items', async () => {
await receivingPage.receivingStep.isLoaded();
await receivingPage.receivingStep.table
.row(1)
.receivingNowField.textbox.fill('50');
await receivingPage.receivingStep.table
.row(2)
.receivingNowField.textbox.fill('10');
});

await test.step('Go to check page and assert qty remaining', async () => {
await receivingPage.nextButton.click();
await receivingPage.checkStep.isLoaded();
await expect(
receivingPage.checkStep.table.getCellValue(1, 'Remaining')
).toHaveText('50');
await expect(
receivingPage.checkStep.table.getCellValue(2, 'Remaining')
).toHaveText('0');
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeEnabled();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeDisabled();
});

await test.step('Select cancel remaining qty checkbox and receive shipment', async () => {
await receivingPage.checkStep.table
.row(1)
.cancelRemainingCheckbox.check();
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeChecked();
await receivingPage.checkStep.receiveShipmentButton.click();
await stockMovementShowPage.isLoaded();
});

await test.step('Assert canceled qty on stock movement show page', async () => {
await expect(stockMovementShowPage.statusTag).toHaveText('Received');
await stockMovementShowPage.receiptTab.click();
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityCanceled
).toHaveText('50');
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityReceived
).toHaveText('50');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityCanceled
).toHaveText('0');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityReceived
).toHaveText('10');
});
});

test('Cancel remaining qty when receive items in 2nd receipt', async ({
stockMovementShowPage,
receivingPage,
}) => {
await test.step('Go to stock movement show page', async () => {
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
await stockMovementShowPage.isLoaded();
});

await test.step('Go to shipment receiving page', async () => {
await stockMovementShowPage.receiveButton.click();
await receivingPage.receivingStep.isLoaded();
});

await test.step('Input receiving qty for 1 item', async () => {
await receivingPage.receivingStep.isLoaded();
await receivingPage.receivingStep.table
.row(1)
.receivingNowField.textbox.fill('50');
});

await test.step('Go to check page and finish 1st receipt', async () => {
await receivingPage.nextButton.click();
await receivingPage.checkStep.isLoaded();
await expect(
receivingPage.checkStep.table.getCellValue(1, 'Remaining')
).toHaveText('50');
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeEnabled();
await receivingPage.checkStep.receiveShipmentButton.click();
await stockMovementShowPage.isLoaded();
});

await test.step('Assert canceled qty on stock movement show page', async () => {
await expect(stockMovementShowPage.statusTag).toHaveText('Receiving');
await stockMovementShowPage.receiptTab.click();
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityReceived
).toHaveText('50');
});

await test.step('Start 2nd receipt', async () => {
await stockMovementShowPage.receiveButton.click();
await receivingPage.receivingStep.isLoaded();
});

await test.step('Input receiving qty for both items', async () => {
await receivingPage.receivingStep.isLoaded();
await receivingPage.receivingStep.table
.row(1)
.receivingNowField.textbox.fill('25');
await receivingPage.receivingStep.table
.row(2)
.receivingNowField.textbox.fill('0');
});

await test.step('Go to check page and assert qty remaining', async () => {
await receivingPage.nextButton.click();
await receivingPage.checkStep.isLoaded();
await expect(
receivingPage.checkStep.table.getCellValue(1, 'Remaining')
).toHaveText('10');
await expect(
receivingPage.checkStep.table.getCellValue(2, 'Remaining')
).toHaveText('25');
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeEnabled();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeEnabled();
});

await test.step('Select cancel remaining qty checkbox and receive shipment', async () => {
await receivingPage.checkStep.table
.row(1)
.cancelRemainingCheckbox.check();
await receivingPage.checkStep.table
.row(2)
.cancelRemainingCheckbox.check();
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeChecked();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeChecked();
await receivingPage.checkStep.receiveShipmentButton.click();
await stockMovementShowPage.isLoaded();
});

await test.step('Assert canceled qty on stock movement show page', async () => {
await expect(stockMovementShowPage.statusTag).toHaveText('Received');
await stockMovementShowPage.receiptTab.click();
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityCanceled
).toHaveText('10');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityReceived
).toHaveText('0');
await expect(
stockMovementShowPage.receiptListTable.row(3).quantityCanceled
).toHaveText('25');
await expect(
stockMovementShowPage.receiptListTable.row(3).quantityReceived
).toHaveText('25');
});

await test.step('Rollback shipment received in 2 receipts', async () => {
await stockMovementShowPage.isLoaded();
await stockMovementShowPage.rollbackLastReceiptButton.click();
});
});

test('Assert remaining qty and disabled cancel remaining checkbox when receive qty bigger than shipped', async ({
stockMovementShowPage,
receivingPage,
}) => {
await test.step('Go to stock movement show page', async () => {
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
await stockMovementShowPage.isLoaded();
});

await test.step('Go to shipment receiving page', async () => {
await stockMovementShowPage.receiveButton.click();
await receivingPage.receivingStep.isLoaded();
});

await test.step('Input receiving qty for both items', async () => {
await receivingPage.receivingStep.isLoaded();
await receivingPage.receivingStep.table
.row(1)
.receivingNowField.textbox.fill('200');
await receivingPage.receivingStep.table
.row(2)
.receivingNowField.textbox.fill('100');
});

await test.step('Go to check page and assert qty remaining', async () => {
await receivingPage.nextButton.click();
await receivingPage.checkStep.isLoaded();
await expect(
receivingPage.checkStep.table.getCellValue(1, 'Remaining')
).toHaveText('-100');
await expect(
receivingPage.checkStep.table.getCellValue(2, 'Remaining')
).toHaveText('-90');
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeDisabled();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeDisabled();
});

await test.step('Receive shipment', async () => {
await receivingPage.checkStep.receiveShipmentButton.click();
await stockMovementShowPage.isLoaded();
});

await test.step('Assert canceled and received qty on stock movement show page', async () => {
await expect(stockMovementShowPage.statusTag).toHaveText('Received');
await stockMovementShowPage.receiptTab.click();
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityCanceled
).toHaveText('0');
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityReceived
).toHaveText('200');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityCanceled
).toHaveText('0');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityReceived
).toHaveText('100');
});
});

test('Cancel remaining qty using cancel all remaining button', async ({
stockMovementShowPage,
receivingPage,
}) => {
await test.step('Go to stock movement show page', async () => {
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
await stockMovementShowPage.isLoaded();
});

await test.step('Go to shipment receiving page', async () => {
await stockMovementShowPage.receiveButton.click();
await receivingPage.receivingStep.isLoaded();
});

await test.step('Input partial qty for both items', async () => {
await receivingPage.receivingStep.isLoaded();
await receivingPage.receivingStep.table
.row(1)
.receivingNowField.textbox.fill('50');
await receivingPage.receivingStep.table
.row(2)
.receivingNowField.textbox.fill('5');
});

await test.step('Go to check page and assert qty remaining', async () => {
await receivingPage.nextButton.click();
await receivingPage.checkStep.isLoaded();
await expect(
receivingPage.checkStep.table.getCellValue(1, 'Remaining')
).toHaveText('50');
await expect(
receivingPage.checkStep.table.getCellValue(2, 'Remaining')
).toHaveText('5');
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeEnabled();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeEnabled();
});

await test.step('Select cancel all remaining button', async () => {
await receivingPage.checkStep.cancelAllRemainingButton.click();
await expect(
receivingPage.checkStep.table.row(1).cancelRemainingCheckbox
).toBeChecked();
await expect(
receivingPage.checkStep.table.row(2).cancelRemainingCheckbox
).toBeChecked();
await receivingPage.checkStep.receiveShipmentButton.click();
await stockMovementShowPage.isLoaded();
});

await test.step('Assert canceled qty on stock movement show page', async () => {
await expect(stockMovementShowPage.statusTag).toHaveText('Received');
await stockMovementShowPage.receiptTab.click();
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityCanceled
).toHaveText('50');
await expect(
stockMovementShowPage.receiptListTable.row(1).quantityReceived
).toHaveText('50');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityCanceled
).toHaveText('5');
await expect(
stockMovementShowPage.receiptListTable.row(2).quantityReceived
).toHaveText('5');
});
});
});