Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/api/PutawayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PUTAWAY_BY_ID,
STOCK_TRANSFER_BY_ID,
} from '@/constants/apiUrls';
import { MIGRATION_URL } from '@/constants/applicationUrls';
import { ApiResponse, PutawayCandidate, PutawayResponse } from '@/types';
import { parseRequestToJSON } from '@/utils/ServiceUtils';

Expand All @@ -29,6 +30,24 @@ class PutawayService extends BaseServiceModel {
}
}

/**
Recalculates product_availability for a location from the transaction
ledger. Putaway candidates are read from product_availability rather than
the ledger directly, so a candidate can go stale (stuck at a quantity the
ledger no longer backs) after a shipment gets rolled back and deleted;
this is the app's own admin action for reconciling it.
*/
Comment on lines +33 to +39

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is about putaways, and the service is related to putaways, but the method should be generic. It's not only for putaways, so it should be in a different file, with a more generic comment

async refreshProductAvailability(locationId: string) {
const apiResponse = await this.request.post(
MIGRATION_URL.refreshProductAvailability(locationId)
);
if (!apiResponse.ok()) {
throw new Error(
`Problem refreshing product availability for location: ${locationId}`
);
}
}

/**
Fetches a putaway order by id. Returns null when the order does not exist.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/constants/applicationUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ const ORDER_URL = {
`${ORDER_URL.list()}?orderType=PUTAWAY_ORDER&status=${status}`,
};

const MIGRATION_URL = {
base: './migration',
refreshProductAvailability: (locationId: string) =>
`${MIGRATION_URL.base}/refreshProductAvailability?location.id=${locationId}`,
};

export {
AUTH_URL,
CYCLE_COUNT_URL,
Expand All @@ -103,6 +109,7 @@ export {
INVOICE_URL,
LOCATION_GROUP_URL,
LOCATION_URL,
MIGRATION_URL,
ORDER_URL,
ORGANIZATION_URL,
PERSON_URL,
Expand Down
16 changes: 9 additions & 7 deletions src/pages/receiving/ReceivingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReceivingPage extends BasePageModel {
}

get wizzardTitle() {
return this.page.getByTestId('wizardTitle');
return this.page.getByTestId('wizard-title');
}

async assertHeaderIsVisible({
Expand All @@ -54,14 +54,16 @@ class ReceivingPage extends BasePageModel {
return this.page.getByRole('tooltip');
}

assertColumnHeaderTooltipOnReceivingStep = async (columnName: string) => {
await this.receivingStep.table.getColumnHeader(columnName).hover();
await expect(this.tooltip).toContainText(columnName);
assertColumnHeaderIsVisibleOnReceivingStep = async (columnName: string) => {
await expect(
this.receivingStep.table.getColumnHeader(columnName)
).toBeVisible();
};

assertColumnHeaderTooltipOnCheckingStep = async (columnName: string) => {
await this.checkStep.table.getColumnHeader(columnName).hover();
await expect(this.tooltip).toContainText(columnName);
assertColumnHeaderIsVisibleOnCheckingStep = async (columnName: string) => {
await expect(
this.checkStep.table.getColumnHeader(columnName)
).toBeVisible();
};
}

Expand Down
28 changes: 13 additions & 15 deletions src/pages/receiving/components/CheckTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ class CheckTable extends BasePageModel {
}

get table() {
return this.page.getByTestId('items-table');
return this.page.getByTestId('confirm-receipt-table');
}

get rows() {
return this.table.getByRole('row');
}

// rows are 1-indexed by convention (row 1 is the first item). Unlike the
// old table, the header row no longer carries role="row", so it doesn't
// occupy index 0 on its own.
row(index: number) {
return new Row(this.page, this.rows.nth(index));
return new Row(this.page, this.rows.nth(index - 1));
}

// rows mixes container rows with item rows (e.g. the first item is at
// row(1), and multi-container shipments leave gaps), so it can't be indexed
// by item position.
get itemRows() {
return this.rows.filter({
has: this.page
.getByTestId('label-field')
.and(this.page.getByLabel('Code', { exact: true })),
has: this.page.locator('[aria-label="Code"]'),
});
}

Expand All @@ -36,15 +37,12 @@ class CheckTable extends BasePageModel {

getColumnHeader(columnName: string) {
return this.table
.locator('.table-header')
.locator('.rt-thead')
.getByText(columnName, { exact: true });
}

getCellValue(row: number, column: string) {
return this.table
.getByRole('row')
.nth(row)
.getByRole('cell', { name: column, exact: true });
return this.rows.nth(row - 1).locator(`[aria-label="${column}"]`);
}
}

Expand All @@ -57,17 +55,17 @@ class Row extends BasePageModel {
}

getItem(name: string) {
return this.row.getByTestId('label-field').getByText(name);
return this.row.locator('[aria-label="Product"]').getByText(name);
}

get code() {
return this.row
.getByTestId('label-field')
.and(this.row.getByLabel('Code', { exact: true }));
return this.row.locator('[aria-label="Code"]');
}

get cancelRemainingCheckbox() {
return this.row.getByTestId('form-field').getByTestId('checkbox');
return this.row
.locator('[data-column-id="cancelRemaining"]')
.getByRole('checkbox');
}
}

Expand Down
48 changes: 13 additions & 35 deletions src/pages/receiving/components/ReceivingTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,51 @@ class ReceivingTable extends BasePageModel {
}

get table() {
return this.page.getByTestId('items-table');
return this.page.getByTestId('receiving-table');
}

get rows() {
return this.table.getByRole('row');
}

// rows are 1-indexed by convention (row 1 is the first item), matching the
// rest of the receiving page objects. Unlike the old table, the header row
// no longer carries role="row", so it doesn't occupy index 0 on its own.
row(index: number) {
return new Row(this.page, this.rows.nth(index));
return new Row(this.page, this.rows.nth(index - 1));
}

getColumnHeader(columnName: string) {
return this.table.locator('.table-header').getByText(columnName);
return this.table
.locator('.rt-thead')
.getByText(columnName, { exact: true });
}

getCellValue(row: number, column: string) {
return this.table
.getByRole('row')
.nth(row)
.getByRole('cell', { name: column });
return this.rows.nth(row - 1).locator(`[aria-label="${column}"]`);
}
}

class Row extends BasePageModel {
row: Locator;
receivingNowField: TextField;
commentField: TextField;

constructor(page: Page, row: Locator) {
super(page);
this.row = row;
this.receivingNowField = new TextField(page, 'Receiving now', row);
this.commentField = new TextField(page, 'Comment', row);
}

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

get editButton() {
return this.row.getByRole('button', { name: 'Edit' });
}

getItem(name: string) {
return this.row.getByTestId('label-field').getByText(name);
}

get binLocationSelect() {
return this.row.getByRole('cell', { name: 'Bin Location' });
}

getBinLocation(binLocation: string) {
return this.page
.getByTestId('custom-select-dropdown-menu')
.getByRole('listitem')
.getByText(binLocation, { exact: true });
get commentButton() {
return this.row.getByRole('button', { name: 'Comment' });
}

getZoneLocation(zoneLocation: string) {
return this.page
.getByTestId('custom-select-dropdown-menu')
.locator('.css-5ih5ya-group react-select__group-heading')
.getByText(zoneLocation, { exact: true });
}

get recipientField() {
return this.row.getByRole('cell', { name: 'Recipient' });
getItem(name: string) {
return this.row.locator('[aria-label="Product"]').getByText(name);
}
}

Expand Down
23 changes: 17 additions & 6 deletions src/pages/receiving/steps/CheckStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,41 @@ class CheckStep extends BasePageModel {

async isLoaded() {
await expect(this.table.table).toBeVisible();
await expect(this.table.table.getByText('Loading...')).toBeHidden({
timeout: 20_000,
});
}

get receiveShipmentButton() {
return this.page.getByRole('button', { name: 'Receive shipment' });
return this.page
.locator('.submit-buttons')
.getByRole('button', { name: 'Complete Receipt' });
}

get shimpentInformation() {
return this.page.locator('.form-title');
return this.page.getByTestId('confirm-receipt-details');
}

get originField() {
return this.page.getByRole('textbox', { name: 'Origin' });
return this.shimpentInformation.locator(
'.item-details__field:has-text("Origin:") .item-details__value'
);
Comment on lines +35 to +37

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should change that

}

get destinationField() {
return this.page.getByRole('textbox', { name: 'Destination' });
return this.shimpentInformation.locator(
'.item-details__field:has-text("Destination:") .item-details__value'
);
}

get shippedOnField() {
return this.page.getByRole('textbox', { name: 'Shipped on' });
return this.shimpentInformation.locator(
'.item-details__field:has-text("Shipped on:") .item-details__value'
);
}

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

get validationOnDeliveredOnPastDatePopup() {
Expand Down
15 changes: 9 additions & 6 deletions src/pages/receiving/steps/ReceivingStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class ReceivingStep extends BasePageModel {

async isLoaded() {
await expect(this.table.table).toBeVisible();
await expect(this.table.table.getByText('Loading...')).toBeHidden({
timeout: 20_000,
});
}

async waitForData() {
Expand All @@ -35,8 +38,12 @@ class ReceivingStep extends BasePageModel {
return this.page.getByRole('button', { name: 'Autofill quantities' });
}

get autosaveStatus() {
return this.page.getByTestId('receiving-autosave-status');
}

get confirmReceivingDialog() {
return this.page.locator('.react-confirm-alert-body');
return this.page.getByTestId('zero-lines-confirm-modal');
}

get rejectConfirmReceivingDialog() {
Expand All @@ -47,12 +54,8 @@ class ReceivingStep extends BasePageModel {
return this.confirmReceivingDialog.getByRole('button', { name: 'Yes' });
}

get saveButton() {
return this.page.getByRole('button', { name: 'Save', exact: true });
}

get saveAndExitButton() {
return this.page.getByRole('button').getByText('Save and Exit');
return this.page.getByRole('button', { name: 'Save & Exit' });
}

get exportTemplateButton() {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/stockMovementShow/StockMovementShowPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StockMovementShowPage extends BasePageModel {
}

async isLoaded() {
await expect(this.summary).toBeVisible();
await expect(this.summary).toBeVisible({ timeout: 15_000 });
}

get summary() {
Expand Down
13 changes: 12 additions & 1 deletion src/setup/validateCleanState.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@
const mainLocation = AppConfig.instance.locations['main'];
const { data: putawayCandidates } =
await putawayService.getPutawayCandidates(mainLocation.readId());
assertNoPutawayCandidates(mainLocation, putawayCandidates);

if (putawayCandidates.length > 0) {

Check warning on line 67 in src/setup/validateCleanState.setup.ts

View workflow job for this annotation

GitHub Actions / test

Avoid having conditionals in tests
// a candidate can be a stale product_availability row left behind by a
// shipment that was rolled back and deleted after it had already been
// received; refreshing recalculates it from the transaction ledger, so a
// genuine leftover still fails the assertion below while a stale one
// clears on its own
await putawayService.refreshProductAvailability(mainLocation.readId());
}
const { data: refreshedPutawayCandidates } =
await putawayService.getPutawayCandidates(mainLocation.readId());
assertNoPutawayCandidates(mainLocation, refreshedPutawayCandidates);

// validate there are no leftover inbound stock movements at any location
const locations = Object.values(AppConfig.instance.locations).filter(
Expand Down
Loading
Loading