Files
InvenTree/src/frontend/tests/pages/pui_stock.spec.ts
T
432d5a5ce6 Check for allocated stock on transfer action (#13302) (#13314)
* Check for allocated stock on transfer action

- Prevent partial transfer of allocated stock

* Check allocation on more actions: serialize / install

* Additional stock detail badges

* include transfer order allocations

* fix playwright test

(cherry picked from commit de39c1626c)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
Co-authored-by: Matthias Mair <code@mjmair.com>
2026-11-18 10:14:26 +11:00

768 lines
27 KiB
TypeScript

import { expect, test } from '../baseFixtures.js';
import { adminuser, stevenuser } from '../defaults.js';
import {
clearTableFilters,
clickButtonIfVisible,
loadTab,
navigate,
openFilterDrawer,
setTableChoiceFilter
} from '../helpers.js';
import { doCachedLogin } from '../login.js';
test('Stock - Basic Tests', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/location/index/' });
await page.waitForURL('**/web/stock/location/**');
await loadTab(page, 'Stock Items');
await page.getByText('1551ABK').first().click();
await page.getByRole('tab', { name: 'Stock', exact: true }).click();
await page.waitForURL('**/web/stock/**');
await loadTab(page, 'Stock Locations');
await page.getByRole('cell', { name: 'Electronics Lab' }).first().click();
await loadTab(page, 'Default Parts');
await loadTab(page, 'Sublocations');
await loadTab(page, 'Stock Items');
await loadTab(page, 'Location Details');
await navigate(page, 'stock/item/1194/details');
await page.getByText('D.123 | Doohickey').waitFor();
await page.getByText('Batch Code: BX-123-2024-2-7').waitFor();
await loadTab(page, 'Test Results');
await page.getByText('395c6d5586e5fb656901d047be27e1f7').waitFor();
await loadTab(page, 'Installed Items');
// Let's create a new stock item
await navigate(page, 'part/822/stock');
await page
.getByRole('button', { name: 'action-button-add-stock-item' })
.click();
await page
.getByRole('textbox', { name: 'number-field-quantity' })
.fill('987');
await page.getByRole('button', { name: 'Submit' }).click();
// Automatically navigate through to the newly created stock item
await page.getByText('Quantity: 987').first().waitFor();
});
test('Stock - Location Tree', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/location/index/' });
await page.waitForURL('**/web/stock/location/**');
await page.getByLabel('nav-breadcrumb-action').click();
await page.getByLabel('nav-tree-toggle-1}').click();
await expect(page.getByLabel('nav-tree-item-2')).toHaveAttribute(
'href',
/\/web\/stock\/location\/2\/?$/
);
await page.getByLabel('nav-tree-item-2').click();
await expect(
page.getByRole('link', { name: 'breadcrumb-1-factory' })
).toHaveAttribute('href', /\/web\/stock\/location\/1\/?$/);
await page.getByLabel('breadcrumb-2-storage-room-a').waitFor();
await page.getByLabel('breadcrumb-1-factory').click();
await page.getByRole('cell', { name: 'Factory' }).first().waitFor();
// Load the tree again - from a deeply nested location
// We expect it to auto-expand to the current location
await navigate(page, 'stock/location/17/stock-items');
await page.getByLabel('nav-breadcrumb-action').click();
for (let ii = 0; ii <= 5; ii++) {
await page
.locator('div')
.filter({ hasText: `Location ${ii}` })
.first()
.waitFor();
}
// Let's search for a particular location
await page.getByRole('textbox', { name: 'nav-tree-search' }).fill('room');
await page.getByText('Storage Room A').first().waitFor();
await page.getByText('Storage Room B').first().waitFor();
});
test('Stock - Location Delete', async ({ browser }) => {
const page = await doCachedLogin(browser, {
url: 'stock/location/38/sublocations'
});
const loc_1 = `loc-1-${Math.floor(Math.random() * 1000)}`;
const loc_2 = `loc-2-${Math.floor(Math.random() * 1000)}`;
// Create a sub-location
await page
.getByRole('button', { name: 'action-button-add-stock-location' })
.click();
await page.getByRole('textbox', { name: 'text-field-name' }).fill(loc_1);
await page.getByRole('button', { name: 'Submit' }).click();
// Create a secondary sub-location
await loadTab(page, 'Sublocations');
await page
.getByRole('button', { name: 'action-button-add-stock-location' })
.click();
await page.getByRole('textbox', { name: 'text-field-name' }).fill(loc_2);
await page.getByRole('button', { name: 'Submit' }).click();
// Navigate up to parent
await page.getByRole('link', { name: `breadcrumb-2-${loc_1}` }).click();
await loadTab(page, 'Sublocations');
await page.getByRole('cell', { name: loc_2, exact: true }).waitFor();
// Delete this location, and all child locations
await page
.getByRole('button', { name: 'action-menu-location-actions' })
.first()
.click();
await page
.getByRole('menuitem', { name: 'action-menu-location-actions-delete' })
.click();
await page
.getByRole('combobox', { name: 'choice-field-delete_stock_items' })
.click();
await page
.getByRole('option', { name: 'Move items to parent location' })
.click();
await page
.getByRole('combobox', { name: 'choice-field-delete_sub_locations' })
.click();
await page.getByRole('option', { name: 'Delete items' }).click();
await page.getByRole('button', { name: 'Delete' }).click();
// Confirm we are on the right page
await page.getByText('External PCB assembler').waitFor();
await loadTab(page, 'Sublocations');
await page.getByText('No records found').first().waitFor();
});
test('Stock - Filters', async ({ browser }) => {
const page = await doCachedLogin(browser, {
user: stevenuser,
url: '/stock/location/index/'
});
await loadTab(page, 'Stock Items');
await openFilterDrawer(page);
await clickButtonIfVisible(page, 'Clear Filters');
// Filter by updated date
await page.getByRole('button', { name: 'Add Filter' }).click();
await page.getByPlaceholder('Select filter').fill('updated');
await page.getByText('Updated After').click();
await page.getByPlaceholder('Select date value').fill('2010-01-01');
await page.getByText('Show items updated after this date').waitFor();
// Filter by batch code
await page.getByRole('button', { name: 'Add Filter' }).click();
await page.getByPlaceholder('Select filter').fill('batch');
await page
.getByRole('option', { name: 'Batch Code', exact: true })
.locator('span')
.click();
await page.getByPlaceholder('Enter filter value').fill('TABLE-B02');
await page.getByLabel('apply-text-filter').click();
// Close dialog
await page.keyboard.press('Escape');
// Ensure correct result is displayed
await page
.getByRole('cell', { name: 'A round table - with blue paint' })
.waitFor();
// Filter by custom status code
await clearTableFilters(page);
await setTableChoiceFilter(page, 'Status', 'Incoming goods inspection');
await page.getByRole('cell', { name: '1551AGY' }).first().waitFor();
await page.getByPlaceholder('Search').clear();
await page.getByPlaceholder('Search').fill('blue');
await page.getByRole('cell', { name: 'widget.blue' }).first().waitFor();
await page.getByPlaceholder('Search').clear();
await page.getByPlaceholder('Search').fill('002.01');
await page.getByRole('cell', { name: '002.01-PCBA' }).first().waitFor();
await clearTableFilters(page);
});
test('Stock - Serial Numbers', async ({ browser }) => {
const page = await doCachedLogin(browser);
// Use the "global search" functionality to find a part we are interested in
// This is to exercise the search functionality and ensure it is working as expected
await page.getByLabel('open-search').click();
await page.getByLabel('global-search-input').clear();
await page.waitForTimeout(250);
await page.getByLabel('global-search-input').fill('widget green');
await page.waitForTimeout(250);
// Remove the "stock item" results group
await page.getByLabel('remove-search-group-stockitem').click();
await page
.getByText(/widget\.green/)
.first()
.click();
await page
.getByLabel('panel-tabs-part')
.getByRole('tab', { name: 'Stock', exact: true })
.click();
await page.getByLabel('action-button-add-stock-item').click();
// Initially fill with invalid serial/quantity combinations
await page
.getByLabel('text-field-serial_numbers', { exact: true })
.fill('200-250');
await page.getByLabel('number-field-quantity').fill('10');
// Add delay to account to field debounce
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Submit' }).click();
// Expected error messages
await page.getByText('Errors exist for one or more form fields').waitFor();
await page
.getByText(/exceeds allowed quantity/)
.first()
.waitFor();
// Now, with correct quantity
await page.getByLabel('number-field-quantity').fill('51');
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForTimeout(250);
await page
.getByText(
/The following serial numbers already exist or are invalid : 200,201,202,203,204/
)
.first()
.waitFor();
// Expected error messages
await page.getByText('Errors exist for one or more form fields').waitFor();
// Close the form
await page.getByRole('button', { name: 'Cancel' }).click();
});
// Test navigation by serial number
test('Stock - Serial Navigation', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'part/79/details' });
await page.getByLabel('action-menu-stock-actions').click();
await page.getByLabel('action-menu-stock-actions-search').click();
await page.getByLabel('text-field-serial', { exact: true }).fill('359');
await page.getByRole('button', { name: 'Submit' }).click();
// Start at serial 359
await page.getByText('359', { exact: true }).first().waitFor();
await page.getByLabel('next-serial-number').waitFor();
await page.getByLabel('previous-serial-number').click();
// Navigate to serial 358
await page.getByText('358', { exact: true }).first().waitFor();
await page.getByLabel('action-button-find-serial').click();
await page.getByLabel('text-field-serial', { exact: true }).fill('200');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('Serial Number: 200').waitFor();
await page.getByText('200', { exact: true }).first().waitFor();
await page.getByText('199', { exact: true }).first().waitFor();
await page.getByText('201', { exact: true }).first().waitFor();
});
test('Stock - Serialize', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/item/232/details' });
// Fill out with faulty serial numbers to check buttons and forms
await page.getByLabel('action-menu-stock-operations').click();
await page.getByLabel('action-menu-stock-operations-serialize').click();
// Check for expected placeholder value
await expect(
page.getByRole('textbox', {
name: 'text-field-serial_numbers',
exact: true
})
).toHaveAttribute('placeholder', '365+');
await page
.getByLabel('text-field-serial_numbers', { exact: true })
.fill('200-250');
await page.getByRole('button', { name: 'Submit' }).click();
// Initially - quantity too high for available stock
await page
.getByText(
'Stock item is allocated: quantity must not exceed the unallocated quantity'
)
.waitFor();
// Reduce quantity and re-submit
await page.getByRole('textbox', { name: 'number-field-quantity' }).fill('90');
await page.getByRole('button', { name: 'Submit' }).click();
await page
.getByText('Number of unique serial numbers (51) must match quantity (90)')
.waitFor();
await page
.getByLabel('text-field-serial_numbers', { exact: true })
.fill('1, 2, 3');
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Submit' }).click();
await page
.getByText('Number of unique serial numbers (3) must match quantity (90)')
.waitFor();
await page.getByRole('button', { name: 'Cancel' }).click();
});
/**
* Test various 'actions' on the stock detail page
*/
test('Stock - Stock Actions', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/item/1225/details' });
// Helper function to launch a stock action
const launchStockAction = async (action: string) => {
await page.getByLabel('action-menu-stock-operations').click();
await page.getByLabel(`action-menu-stock-operations-${action}`).click();
};
const setStockStatus = async (status: string) => {
await page.getByLabel('action-button-change-status').click();
await page.getByLabel('choice-field-status').click();
await page.getByRole('option', { name: status }).click();
};
// Duplicate the stock item first - prevent impacting other tests
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-duplicate' })
.click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForLoadState('networkidle');
// Check for required values
await page.getByText('Status', { exact: true }).waitFor();
await page.getByText('Custom Status', { exact: true }).waitFor();
await page.getByText('Attention needed').first().waitFor();
await page
.getByLabel('Stock Details')
.getByText('Incoming goods inspection')
.waitFor();
await page.getByText('123').first().waitFor();
// Check barcode actions
await page.getByLabel('action-menu-barcode-actions').click();
await page
.getByLabel('action-menu-barcode-actions-scan-into-location')
.click();
await page
.getByPlaceholder('Enter barcode data')
.fill('{"stocklocation": 12}');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
await page.getByText('Scanned stock item into location').waitFor();
// Add "zero" stock - ensure the quantity stays the same
await launchStockAction('add');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('Quantity: 123').first().waitFor();
// Add stock, and change status
await launchStockAction('add');
await page.getByLabel('number-field-quantity').fill('12');
await setStockStatus('Lost');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('Lost').first().waitFor();
await page.getByText('Unavailable').first().waitFor();
await page.getByText('135').first().waitFor();
// Remove "zero" stock - ensure the quantity stays the same
await launchStockAction('remove');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('Quantity: 135').first().waitFor();
// Remove stock, and change status
await launchStockAction('remove');
await page.getByLabel('number-field-quantity').fill('99');
await setStockStatus('Damaged');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('36').first().waitFor();
await page.getByText('Damaged').first().waitFor();
// Count stock and change status (reverting to original value)
await launchStockAction('count');
await page.getByLabel('number-field-quantity').fill('123');
await setStockStatus('Incoming goods inspection');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('123').first().waitFor();
await page.getByText('Custom Status').first().waitFor();
await page.getByText('Incoming goods inspection').first().waitFor();
// Find an item which has been sent to a customer
await navigate(page, 'stock/item/1014/details');
await page.getByText('Batch Code: 2022-11-12').waitFor();
await page.getByText('Unavailable').waitFor();
await page.getByLabel('action-menu-stock-operations').click();
await page.getByLabel('action-menu-stock-operations-return').click();
});
// Test conversion between part variants
test('Stock - Convert', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'part/78/stock' });
// Create a brand new stock item
await page
.getByRole('button', { name: 'action-button-add-stock-item' })
.click();
await page
.getByRole('textbox', { name: 'text-field-batch' })
.fill('BATCH_TEST');
await page.waitForTimeout(200);
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForTimeout(2500);
await page.getByText('widget.red.00 | Red Widget |').first().waitFor();
await page.getByText('BATCH_TEST', { exact: true }).first().waitFor();
// Convert to widget.red.02
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-convert' })
.click();
await page.getByRole('combobox', { name: 'related-field-part' }).fill('red');
await page.getByText('widget.red.02 | Red Widget |').click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('widget.red.02 | Red Widget |').waitFor();
// Convert to widget.red.00
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-convert' })
.click();
await page.getByRole('combobox', { name: 'related-field-part' }).fill('red');
await page.getByText('widget.red.00 | Red Widget |').click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('widget.red.00 | Red Widget |').waitFor();
});
test('Stock - Return Items', async ({ browser }) => {
const page = await doCachedLogin(browser, {
url: 'sales/customer/32/assigned-stock'
});
// Return stock items assigned to customer
await page.getByRole('checkbox', { name: 'Select all records' }).check();
await page.getByRole('button', { name: 'action-menu-stock-actions' }).click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-actions-return-stock' })
.click();
await page.getByText('Return selected items into stock').first().waitFor();
await page.getByRole('button', { name: 'Cancel' }).click();
// Location detail
await navigate(page, 'stock/item/1253');
// Allow some settling time for this page
await page.waitForLoadState('networkidle');
await page.waitForTimeout(100);
await page
.getByRole('button', { name: 'action-menu-stock-operations' })
.click();
await page
.getByRole('menuitem', {
name: 'action-menu-stock-operations-return-stock'
})
.click();
await page.getByText('#128').waitFor();
await page.getByText('Merge into existing stock').waitFor();
await page.getByRole('textbox', { name: 'number-field-quantity' }).fill('0');
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByRole('alert', { name: 'Form Error' }).waitFor();
await page.getByText('Quantity must be greater than zero').first().waitFor();
await page.getByText('This field is required.').first().waitFor();
});
test('Stock - History (Stock Item)', async ({ browser }) => {
// Note: The 'admin' user has the "Show Change History" setting enabled
const page = await doCachedLogin(browser, {
user: adminuser,
url: 'stock/item/193/history'
});
await page.getByText('widget.purple | Purple Widget').first().waitFor();
// Stock tracking events are displayed in the "History" tab
await page.getByText('Installed into assembly').first().waitFor();
await page.getByText('Assigned serial number').first().waitFor();
await page.getByText('Stock item created').first().waitFor();
// Event deltas link to the related stock item
await page.getByText('Widget Board (assembled) #159').first().waitFor();
});
test('Stock - History (Part)', async ({ browser }) => {
// Note: The 'admin' user has the "Show Change History" setting enabled
const page = await doCachedLogin(browser, {
user: adminuser,
url: 'part/76/history'
});
await page.getByText('widget.purple | Purple Widget').first().waitFor();
// The history of the part includes stock tracking events for its stock items
await page.getByText('Shipped against Sales Order').first().waitFor();
await page.getByText('Customer D').first().waitFor();
await page.getByText('SO0009').first().waitFor();
await page.getByText('Installed into assembly').first().waitFor();
await page.getByText('Purple Widget #35').first().waitFor();
// ...as well as changes to the part itself (e.g. parameters)
await page.getByText('Color: Purple').first().waitFor();
});
test('Stock - History', async ({ browser }) => {
// Note: The 'admin' user has the "Show Change History" setting enabled
const page = await doCachedLogin(browser, {
user: adminuser,
url: 'stock/item/176/details'
});
await page.getByRole('link', { name: 'Widget Assembly # 2' }).waitFor();
/* Add some more stock items and history information:
* - Duplicate this stock item
* - Give it a unique serial number
* - Ensure the creation of the new item is recorded
* - Delete the new stock item
* - Ensure that the history is retained against the base part
*/
// Duplicate the stock item
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-duplicate' })
.click();
await page
.getByRole('textbox', { name: 'text-field-serial_numbers' })
.fill('9876');
await page.getByRole('button', { name: 'Submit' }).click();
// Check that the creation of the new item is recorded
await page.getByText('Serial Number: 9876').first().waitFor();
await loadTab(page, 'History', true);
await page.getByText('Stock item created').first().waitFor();
// Delete this stock item
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-delete' })
.click();
await page.getByRole('button', { name: 'Delete' }).click();
// The history of the deleted item is retained against the base part
await loadTab(page, 'History', true);
await page.getByText('Object was deleted').first().waitFor();
await page.getByText('Stock item created').first().waitFor();
});
test('Stock - Location', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/location/12/' });
await loadTab(page, 'Default Parts');
await loadTab(page, 'Stock Items');
await loadTab(page, 'Sublocations');
await loadTab(page, 'Location Details');
await page.getByLabel('action-menu-barcode-actions').click();
await page
.getByLabel('action-menu-barcode-actions-scan-in-stock-items')
.waitFor();
await page
.getByLabel('action-menu-barcode-actions-scan-in-container')
.click();
// Attempt to scan in the same location (should fail)
await page
.getByPlaceholder('Enter barcode data')
.fill('{"stocklocation": 12}');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
await page.getByText('Error scanning stock location').waitFor();
// Attempt to scan bad data (no match)
await page
.getByPlaceholder('Enter barcode data')
.fill('{"stocklocation": 1234}');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
await page.getByText('No match found for barcode data').waitFor();
});
// Test disassembly of an assembled stock item
test('Stock - Disassembly', async ({ browser }) => {
const page = await doCachedLogin(browser, { url: 'stock/item/1387/details' });
// Duplicate this stock item to avoid impacting other tests
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-duplicate' })
.click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForTimeout(100);
await page.waitForLoadState('networkidle');
// Disassemble this stock item
await page
.getByRole('button', { name: 'action-menu-stock-operations' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-operations-disassemble' })
.click();
// Perform partial disassembly
await page
.getByRole('textbox', {
name: 'number-field-quantity',
description: 'Number of assemblies to disassemble'
})
.fill('6');
// Set custom status for one item
await page
.getByRole('row', { name: 'Thumbnail XT90-M 10 60 action' })
.getByLabel('action-button-change-status')
.click();
await page
.getByRole('combobox', { name: 'choice-field-status' })
.fill('damaged');
await page.getByRole('option', { name: 'Damaged' }).click();
// Specify different location for one item
await page
.getByRole('row', { name: 'Thumbnail XT90-F 10 60' })
.getByLabel('action-button-set-location')
.click();
await page
.getByRole('cell', { name: 'Location Custom location for' })
.getByPlaceholder('Select location')
.fill('factory');
await page.getByRole('listbox').getByText('Factory', { exact: true }).click();
await page.getByRole('button', { name: 'Submit' }).click();
// Quantity of this assembly has been reduced
await page.getByText('Quantity: 4').first().waitFor();
await loadTab(page, 'Child Items');
await page.getByText('1 - 2 / 2').waitFor();
await page.getByRole('cell', { name: 'Thumbnail XT90-F' }).waitFor();
await page.getByRole('cell', { name: 'Thumbnail XT90-M' }).waitFor();
});
// Test that the "location" field is correctly pre-filled when creating new stock items
test('Stock - Default Location', async ({ browser }) => {
const page = await doCachedLogin(browser, {
url: 'stock/location/12/stock-items'
});
// The stock item location is rendered via a "tree field" (backed by a real input)
const locationField = () =>
page.getByRole('textbox', { name: 'tree-field-location' });
// Scenario 1: Creating a new stock item from within a location should default to that location
await page
.getByRole('button', { name: 'action-button-add-stock-item' })
.click();
await expect(locationField()).toHaveValue('Location 0');
await page.getByRole('button', { name: 'Cancel' }).click();
// Scenario 2: Duplicating a stock item should retain its original location
await navigate(page, 'stock/item/2/details');
await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle');
await page
.getByRole('button', { name: 'action-menu-stock-item-actions' })
.click();
await page
.getByRole('menuitem', { name: 'action-menu-stock-item-actions-duplicate' })
.click();
await expect(locationField()).toHaveValue('Electronics Lab/Reel Storage');
await page.getByRole('button', { name: 'Cancel' }).click();
// Scenario 3: Creating a new stock item for a part with a specified default location
// First, assign a default location to the part
await navigate(page, 'part/86/details');
await page.getByText('1553WDBK').first().waitFor();
await page.keyboard.press('Control+E');
await page.getByPlaceholder('Select location').fill('Mechanical Lab');
await page
.getByRole('listbox')
.getByText('Mechanical Lab', { exact: true })
.click();
await page.waitForTimeout(250);
// The "Submit" button is only enabled if the value actually changed - if a
// previous test run already left this part with the same default location,
// there is nothing to save, so just close the form instead
const submitButton = page.getByRole('button', { name: 'Submit' });
if (await submitButton.isEnabled()) {
await submitButton.click();
await page.waitForLoadState('networkidle');
} else {
await page.getByRole('button', { name: 'Cancel' }).click();
}
// Now, create a new stock item for this part, and check the location is pre-filled
await navigate(page, 'part/86/stock');
await page
.getByRole('button', { name: 'action-button-add-stock-item' })
.click();
await expect(locationField()).toHaveValue('Factory/Mechanical Lab');
await page.getByRole('button', { name: 'Cancel' }).click();
});