diff --git a/src/frontend/tests/helpers.ts b/src/frontend/tests/helpers.ts index 970d7cbfd616..f76862592161 100644 --- a/src/frontend/tests/helpers.ts +++ b/src/frontend/tests/helpers.ts @@ -1,3 +1,5 @@ +import { baseUrl } from './defaults'; + /** * Open the filter drawer for the currently visible table * @param page - The page object @@ -62,3 +64,20 @@ export const setTableChoiceFilter = async (page, filter, value) => { export const getRowFromCell = async (cell) => { return cell.locator('xpath=ancestor::tr').first(); }; + +/** + * Navigate to the provided page, and wait for loading to complete + * @param page + * @param url + */ +export const navigate = async (page, url: string) => { + if (!url.startsWith(baseUrl)) { + if (url.startsWith('/')) { + url = url.slice(1); + } + + url = `${baseUrl}/${url}`; + } + + await page.goto(url, { waitUntil: 'domcontentloaded' }); +}; diff --git a/src/frontend/tests/login.ts b/src/frontend/tests/login.ts index 02c22cfe9757..18fd0e60faf9 100644 --- a/src/frontend/tests/login.ts +++ b/src/frontend/tests/login.ts @@ -1,5 +1,6 @@ import { expect } from './baseFixtures.js'; import { baseUrl, logoutUrl, user } from './defaults'; +import { navigate } from './helpers.js'; /* * Perform form based login operation from the "login" URL @@ -8,7 +9,7 @@ export const doLogin = async (page, username?: string, password?: string) => { username = username ?? user.username; password = password ?? user.password; - await page.goto(logoutUrl); + await navigate(page, logoutUrl); await expect(page).toHaveTitle(/^InvenTree.*$/); await page.waitForURL('**/platform/login'); await page.getByLabel('username').fill(username); @@ -31,7 +32,7 @@ export const doQuickLogin = async ( password = password ?? user.password; url = url ?? baseUrl; - await page.goto(`${url}/login/?login=${username}&password=${password}`); + await navigate(page, `${url}/login/?login=${username}&password=${password}`); await page.waitForURL('**/platform/home'); await page.getByLabel('navigation-menu').waitFor(); @@ -43,6 +44,6 @@ export const doQuickLogin = async ( }; export const doLogout = async (page) => { - await page.goto(`${baseUrl}/logout/`); + await navigate(page, 'logout'); await page.waitForURL('**/platform/login'); }; diff --git a/src/frontend/tests/pages/pui_build.spec.ts b/src/frontend/tests/pages/pui_build.spec.ts index 7572e87a56e8..0e39f7818680 100644 --- a/src/frontend/tests/pages/pui_build.spec.ts +++ b/src/frontend/tests/pages/pui_build.spec.ts @@ -1,8 +1,8 @@ import { test } from '../baseFixtures.ts'; -import { baseUrl } from '../defaults.ts'; import { clearTableFilters, getRowFromCell, + navigate, setTableChoiceFilter } from '../helpers.ts'; import { doQuickLogin } from '../login.ts'; @@ -10,7 +10,7 @@ import { doQuickLogin } from '../login.ts'; test('Build Order - Basic Tests', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/`); + await navigate(page, 'part/'); // Navigate to the correct build order await page.getByRole('tab', { name: 'Manufacturing', exact: true }).click(); @@ -90,7 +90,7 @@ test('Build Order - Basic Tests', async ({ page }) => { test('Build Order - Edit', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/manufacturing/build-order/22/`); + await navigate(page, 'manufacturing/build-order/22/'); // Check for expected text items await page.getByText('Building for sales order').first().waitFor(); @@ -117,7 +117,7 @@ test('Build Order - Edit', async ({ page }) => { test('Build Order - Build Outputs', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/manufacturing/index/`); + await navigate(page, 'manufacturing/index/'); await page.getByRole('tab', { name: 'Build Orders', exact: true }).click(); // We have now loaded the "Build Order" table. Check for some expected texts @@ -191,7 +191,7 @@ test('Build Order - Build Outputs', async ({ page }) => { test('Build Order - Allocation', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/manufacturing/build-order/1/line-items`); + await navigate(page, 'manufacturing/build-order/1/line-items'); // Expand the R_10K_0805 line item await page.getByText('R_10K_0805_1%').first().click(); @@ -291,7 +291,7 @@ test('Build Order - Allocation', async ({ page }) => { test('Build Order - Filters', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/manufacturing/index/buildorders`); + await navigate(page, 'manufacturing/index/buildorders'); await clearTableFilters(page); await page.getByText('1 - 24 / 24').waitFor(); diff --git a/src/frontend/tests/pages/pui_part.spec.ts b/src/frontend/tests/pages/pui_part.spec.ts index 09e2fcee7cc3..0678b9a0d97d 100644 --- a/src/frontend/tests/pages/pui_part.spec.ts +++ b/src/frontend/tests/pages/pui_part.spec.ts @@ -1,6 +1,5 @@ import { test } from '../baseFixtures'; -import { baseUrl } from '../defaults'; -import { clearTableFilters, getRowFromCell } from '../helpers'; +import { clearTableFilters, getRowFromCell, navigate } from '../helpers'; import { doQuickLogin } from '../login'; /** @@ -45,7 +44,7 @@ test('Parts - Tabs', async ({ page }) => { await page.getByRole('tab', { name: 'Used In' }).click(); await page.getByRole('tab', { name: 'Pricing' }).click(); - await page.goto(`${baseUrl}/part/category/index/parts`); + await navigate(page, 'part/category/index/parts'); await page.getByText('Blue Chair').click(); await page.getByRole('tab', { name: 'Bill of Materials' }).click(); await page.getByRole('tab', { name: 'Build Orders' }).click(); @@ -54,7 +53,7 @@ test('Parts - Tabs', async ({ page }) => { test('Parts - Manufacturer Parts', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/84/suppliers`); + await navigate(page, 'part/84/suppliers'); await page.getByRole('tab', { name: 'Suppliers' }).click(); await page.getByText('Hammond Manufacturing').click(); @@ -67,7 +66,7 @@ test('Parts - Manufacturer Parts', async ({ page }) => { test('Parts - Supplier Parts', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/15/suppliers`); + await navigate(page, 'part/15/suppliers'); await page.getByRole('tab', { name: 'Suppliers' }).click(); await page.getByRole('cell', { name: 'DIG-84670-SJI' }).click(); @@ -81,14 +80,14 @@ test('Parts - Locking', async ({ page }) => { await doQuickLogin(page); // Navigate to a known assembly which is *not* locked - await page.goto(`${baseUrl}/part/104/bom`); + await navigate(page, 'part/104/bom'); await page.getByRole('tab', { name: 'Bill of Materials' }).click(); await page.getByLabel('action-button-add-bom-item').waitFor(); await page.getByRole('tab', { name: 'Parameters' }).click(); await page.getByLabel('action-button-add-parameter').waitFor(); // Navigate to a known assembly which *is* locked - await page.goto(`${baseUrl}/part/100/bom`); + await navigate(page, 'part/100/bom'); await page.getByRole('tab', { name: 'Bill of Materials' }).click(); await page.getByLabel('part-lock-icon').waitFor(); await page.getByText('Part is Locked', { exact: true }).waitFor(); @@ -107,7 +106,7 @@ test('Parts - Allocations', async ({ page }) => { await doQuickLogin(page); // Let's look at the allocations for a single stock item - await page.goto(`${baseUrl}/stock/item/324/`); + await navigate(page, 'stock/item/324/'); await page.getByRole('tab', { name: 'Allocations' }).click(); await page.getByRole('button', { name: 'Build Order Allocations' }).waitFor(); @@ -115,7 +114,7 @@ test('Parts - Allocations', async ({ page }) => { await page.getByRole('cell', { name: 'Making tables for SO 0003' }).waitFor(); // Let's look at the allocations for an entire part - await page.goto(`${baseUrl}/part/74/details`); + await navigate(page, 'part/74/details'); // Check that the overall allocations are displayed correctly await page.getByText('11 / 825').waitFor(); @@ -174,7 +173,7 @@ test('Parts - Pricing (Nothing, BOM)', async ({ page }) => { await doQuickLogin(page); // Part with no history - await page.goto(`${baseUrl}/part/82/pricing`); + await navigate(page, 'part/82/pricing'); await page.getByText('Small plastic enclosure, black').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); @@ -186,7 +185,7 @@ test('Parts - Pricing (Nothing, BOM)', async ({ page }) => { await page.getByRole('button', { name: 'Supplier Pricing' }).isDisabled(); // Part with history - await page.goto(`${baseUrl}/part/108/pricing`); + await navigate(page, 'part/108/pricing'); await page.getByText('A chair - with blue paint').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); await page.getByLabel('Part Pricing').getByText('Part Pricing').waitFor(); @@ -224,7 +223,7 @@ test('Parts - Pricing (Supplier)', async ({ page }) => { await doQuickLogin(page); // Part - await page.goto(`${baseUrl}/part/55/pricing`); + await navigate(page, 'part/55/pricing'); await page.getByText('Ceramic capacitor, 100nF in').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); await page.getByLabel('Part Pricing').getByText('Part Pricing').waitFor(); @@ -250,7 +249,7 @@ test('Parts - Pricing (Variant)', async ({ page }) => { await doQuickLogin(page); // Part - await page.goto(`${baseUrl}/part/106/pricing`); + await navigate(page, 'part/106/pricing'); await page.getByText('A chair - available in multiple colors').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); await page.getByLabel('Part Pricing').getByText('Part Pricing').waitFor(); @@ -276,7 +275,7 @@ test('Parts - Pricing (Internal)', async ({ page }) => { await doQuickLogin(page); // Part - await page.goto(`${baseUrl}/part/65/pricing`); + await navigate(page, 'part/65/pricing'); await page.getByText('Socket head cap screw, M2').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); await page.getByLabel('Part Pricing').getByText('Part Pricing').waitFor(); @@ -301,7 +300,7 @@ test('Parts - Pricing (Purchase)', async ({ page }) => { await doQuickLogin(page); // Part - await page.goto(`${baseUrl}/part/69/pricing`); + await navigate(page, 'part/69/pricing'); await page.getByText('1.25mm Pitch, PicoBlade PCB').waitFor(); await page.getByRole('tab', { name: 'Part Pricing' }).click(); await page.getByLabel('Part Pricing').getByText('Part Pricing').waitFor(); @@ -322,7 +321,7 @@ test('Parts - Pricing (Purchase)', async ({ page }) => { test('Parts - Attachments', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/69/attachments`); + await navigate(page, 'part/69/attachments'); // Submit a new external link await page.getByLabel('action-button-add-external-').click(); @@ -344,7 +343,7 @@ test('Parts - Attachments', async ({ page }) => { test('Parts - Parameters', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/69/parameters`); + await navigate(page, 'part/69/parameters'); // Create a new template await page.getByLabel('action-button-add-parameter').click(); @@ -371,7 +370,7 @@ test('Parts - Parameters', async ({ page }) => { test('Parts - Notes', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/69/notes`); + await navigate(page, 'part/69/notes'); // Enable editing await page.getByLabel('Enable Editing').waitFor(); @@ -393,7 +392,7 @@ test('Parts - Notes', async ({ page }) => { test('Parts - 404', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/99999/`); + await navigate(page, 'part/99999/'); await page.getByText('Page Not Found', { exact: true }).waitFor(); // Clear out any console error messages @@ -403,7 +402,7 @@ test('Parts - 404', async ({ page }) => { test('Parts - Revision', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/part/906/details`); + await navigate(page, 'part/906/details'); await page.getByText('Revision of').waitFor(); await page.getByText('Select Part Revision').waitFor(); diff --git a/src/frontend/tests/pages/pui_purchase_order.spec.ts b/src/frontend/tests/pages/pui_purchase_order.spec.ts index 19ea8c10a3b5..99d8d78456a4 100644 --- a/src/frontend/tests/pages/pui_purchase_order.spec.ts +++ b/src/frontend/tests/pages/pui_purchase_order.spec.ts @@ -1,8 +1,8 @@ import { test } from '../baseFixtures.ts'; -import { baseUrl } from '../defaults.ts'; import { clearTableFilters, clickButtonIfVisible, + navigate, openFilterDrawer, setTableChoiceFilter } from '../helpers.ts'; @@ -39,7 +39,7 @@ test('Purchase Orders - List', async ({ page }) => { test('Purchase Orders - Barcodes', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/purchasing/purchase-order/13/detail`); + await navigate(page, 'purchasing/purchase-order/13/detail'); await page.getByRole('button', { name: 'Issue Order' }).waitFor(); // Display QR code @@ -211,7 +211,7 @@ test('Purchase Orders - Order Parts', async ({ page }) => { await page.getByRole('banner').getByRole('button').click(); // Order from the part detail page - await page.goto(`${baseUrl}/part/69/`); + await navigate(page, 'part/69/'); await page.waitForURL('**/part/69/**'); await page.getByLabel('action-menu-stock-actions').click(); diff --git a/src/frontend/tests/pages/pui_sales_order.spec.ts b/src/frontend/tests/pages/pui_sales_order.spec.ts index da47f188d23a..5899f7169602 100644 --- a/src/frontend/tests/pages/pui_sales_order.spec.ts +++ b/src/frontend/tests/pages/pui_sales_order.spec.ts @@ -1,12 +1,15 @@ import { test } from '../baseFixtures.ts'; -import { baseUrl } from '../defaults.ts'; -import { clearTableFilters, setTableChoiceFilter } from '../helpers.ts'; +import { + clearTableFilters, + navigate, + setTableChoiceFilter +} from '../helpers.ts'; import { doQuickLogin } from '../login.ts'; test('Sales Orders - Tabs', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/sales/index/`); + await navigate(page, 'sales/index/'); await page.waitForURL('**/platform/sales/**'); await page.getByRole('tab', { name: 'Sales Orders' }).click(); @@ -30,6 +33,9 @@ test('Sales Orders - Tabs', async ({ page }) => { // Sales Order Details await page.getByRole('tab', { name: 'Sales Orders' }).click(); + + await clearTableFilters(page); + await page.getByRole('cell', { name: 'SO0001' }).click(); await page .getByLabel('Order Details') @@ -57,7 +63,7 @@ test('Sales Orders - Tabs', async ({ page }) => { test('Sales Orders - Basic Tests', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/home`); + await navigate(page, 'home'); await page.getByRole('tab', { name: 'Sales' }).click(); await page.getByRole('tab', { name: 'Sales Orders' }).click(); @@ -100,12 +106,12 @@ test('Sales Orders - Basic Tests', async ({ page }) => { test('Sales Orders - Shipments', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/home`); + await navigate(page, 'home'); await page.getByRole('tab', { name: 'Sales' }).click(); await page.getByRole('tab', { name: 'Sales Orders' }).click(); + await clearTableFilters(page); // Click through to a particular sales order - await page.getByRole('tab', { name: 'Sales Orders' }).waitFor(); await page.getByRole('cell', { name: 'SO0006' }).first().click(); await page.getByRole('tab', { name: 'Shipments' }).click(); diff --git a/src/frontend/tests/pages/pui_scan.spec.ts b/src/frontend/tests/pages/pui_scan.spec.ts index 1e46ee131fbf..2f5fc2a7eb3c 100644 --- a/src/frontend/tests/pages/pui_scan.spec.ts +++ b/src/frontend/tests/pages/pui_scan.spec.ts @@ -1,5 +1,5 @@ import { test } from '../baseFixtures'; -import { baseUrl } from '../defaults'; +import { navigate } from '../helpers'; import { doQuickLogin } from '../login'; const scan = async (page, barcode) => { @@ -42,7 +42,7 @@ test('Scanning - Basic', async ({ page }) => { test('Scanning - Part', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"part": 1}'); @@ -53,7 +53,7 @@ test('Scanning - Part', async ({ page }) => { test('Scanning - Stockitem', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"stockitem": 408}'); await page.getByText('1551ABK').waitFor(); @@ -63,7 +63,7 @@ test('Scanning - Stockitem', async ({ page }) => { test('Scanning - StockLocation', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"stocklocation": 3}'); // stocklocation: 3 @@ -76,7 +76,7 @@ test('Scanning - StockLocation', async ({ page }) => { test('Scanning - SupplierPart', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"supplierpart": 204}'); // supplierpart: 204 @@ -87,7 +87,7 @@ test('Scanning - SupplierPart', async ({ page }) => { test('Scanning - PurchaseOrder', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"purchaseorder": 12}'); // purchaseorder: 12 @@ -100,7 +100,7 @@ test('Scanning - PurchaseOrder', async ({ page }) => { test('Scanning - SalesOrder', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"salesorder": 6}'); // salesorder: 6 @@ -111,7 +111,7 @@ test('Scanning - SalesOrder', async ({ page }) => { test('Scanning - Build', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/scan/`); + await navigate(page, 'scan/'); await scan(page, '{"build": 8}'); // build: 8 diff --git a/src/frontend/tests/pages/pui_stock.spec.ts b/src/frontend/tests/pages/pui_stock.spec.ts index 0d1fb20ecd8f..b42817b4b501 100644 --- a/src/frontend/tests/pages/pui_stock.spec.ts +++ b/src/frontend/tests/pages/pui_stock.spec.ts @@ -1,8 +1,8 @@ import { test } from '../baseFixtures.js'; -import { baseUrl } from '../defaults.js'; import { clearTableFilters, clickButtonIfVisible, + navigate, openFilterDrawer, setTableChoiceFilter } from '../helpers.js'; @@ -11,7 +11,7 @@ import { doQuickLogin } from '../login.js'; test('Stock - Basic Tests', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/stock/location/index/`); + await navigate(page, 'stock/location/index/'); await page.waitForURL('**/platform/stock/location/**'); await page.getByRole('tab', { name: 'Location Details' }).click(); @@ -29,7 +29,7 @@ test('Stock - Basic Tests', async ({ page }) => { await page.getByRole('tab', { name: 'Stock Items' }).click(); await page.getByRole('tab', { name: 'Location Details' }).click(); - await page.goto(`${baseUrl}/stock/item/1194/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 page.getByRole('tab', { name: 'Stock Tracking' }).click(); @@ -41,7 +41,7 @@ test('Stock - Basic Tests', async ({ page }) => { test('Stock - Location Tree', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/stock/location/index/`); + await navigate(page, 'stock/location/index/'); await page.waitForURL('**/platform/stock/location/**'); await page.getByRole('tab', { name: 'Location Details' }).click(); @@ -58,7 +58,7 @@ test('Stock - Location Tree', async ({ page }) => { test('Stock - Filters', async ({ page }) => { await doQuickLogin(page, 'steven', 'wizardstaff'); - await page.goto(`${baseUrl}/stock/location/index/`); + await navigate(page, 'stock/location/index/'); await page.getByRole('tab', { name: 'Stock Items' }).click(); await openFilterDrawer(page); @@ -169,7 +169,7 @@ test('Stock - Serial Numbers', async ({ page }) => { test('Stock - Stock Actions', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/stock/item/1225/details`); + await navigate(page, 'stock/item/1225/details'); // Helper function to launch a stock action const launchStockAction = async (action: string) => { @@ -223,7 +223,7 @@ test('Stock - Stock Actions', async ({ page }) => { await page.getByText('Incoming goods inspection').first().waitFor(); // Find an item which has been sent to a customer - await page.goto(`${baseUrl}/stock/item/1014/details`); + 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(); @@ -234,7 +234,7 @@ test('Stock - Tracking', async ({ page }) => { await doQuickLogin(page); // Navigate to the "stock item" page - await page.goto(`${baseUrl}/stock/item/176/details/`); + await navigate(page, 'stock/item/176/details/'); await page.getByRole('link', { name: 'Widget Assembly # 2' }).waitFor(); // Navigate to the "stock tracking" tab diff --git a/src/frontend/tests/pui_forms.spec.ts b/src/frontend/tests/pui_forms.spec.ts index 68d29df3efd3..e35a8f69ecce 100644 --- a/src/frontend/tests/pui_forms.spec.ts +++ b/src/frontend/tests/pui_forms.spec.ts @@ -1,12 +1,11 @@ /** Unit tests for form validation, rendering, etc */ import test from 'playwright/test'; - -import { baseUrl } from './defaults'; +import { navigate } from './helpers'; import { doQuickLogin } from './login'; test('Forms - Stock Item Validation', async ({ page }) => { await doQuickLogin(page, 'steven', 'wizardstaff'); - await page.goto(`${baseUrl}/stock/location/index/stock-items`); + await navigate(page, 'stock/location/index/stock-items'); await page.waitForURL('**/platform/stock/location/**'); // Create new stock item form @@ -77,7 +76,7 @@ test('Forms - Stock Item Validation', async ({ page }) => { test('Forms - Supplier Validation', async ({ page, request }) => { await doQuickLogin(page, 'steven', 'wizardstaff'); - await page.goto(`${baseUrl}/purchasing/index/suppliers`); + await navigate(page, 'purchasing/index/suppliers'); await page.waitForURL('**/purchasing/index/**'); await page.getByLabel('action-button-add-company').click(); @@ -113,7 +112,7 @@ test('Forms - Supplier Validation', async ({ page, request }) => { .waitFor(); // Now, try to create another new supplier with the same name - await page.goto(`${baseUrl}/purchasing/index/suppliers`); + await navigate(page, 'purchasing/index/suppliers'); await page.waitForURL('**/purchasing/index/**'); await page.getByLabel('action-button-add-company').click(); await page.getByLabel('text-field-name').fill(supplierName); diff --git a/src/frontend/tests/pui_general.spec.ts b/src/frontend/tests/pui_general.spec.ts index cf97c1180f04..b9340208b726 100644 --- a/src/frontend/tests/pui_general.spec.ts +++ b/src/frontend/tests/pui_general.spec.ts @@ -1,11 +1,11 @@ import { test } from './baseFixtures.js'; -import { baseUrl } from './defaults.js'; +import { navigate } from './helpers.js'; import { doQuickLogin } from './login.js'; test('Company', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/company/1/details`); + await navigate(page, 'company/1/details'); await page.getByLabel('Details').getByText('DigiKey Electronics').waitFor(); await page.getByRole('cell', { name: 'https://www.digikey.com/' }).waitFor(); await page.getByRole('tab', { name: 'Supplied Parts' }).click(); @@ -44,7 +44,7 @@ test('Company', async ({ page }) => { */ test('Admin Button', async ({ page }) => { await doQuickLogin(page, 'admin', 'inventree'); - await page.goto(`${baseUrl}/company/1/details`); + await navigate(page, 'company/1/details'); // Click on the admin button await page.getByLabel(/action-button-open-in-admin/).click(); diff --git a/src/frontend/tests/pui_login.spec.ts b/src/frontend/tests/pui_login.spec.ts index d1ab641021df..ad38a16b59f5 100644 --- a/src/frontend/tests/pui_login.spec.ts +++ b/src/frontend/tests/pui_login.spec.ts @@ -1,5 +1,6 @@ import { expect, test } from './baseFixtures.js'; -import { baseUrl, logoutUrl, user } from './defaults.js'; +import { logoutUrl, user } from './defaults.js'; +import { navigate } from './helpers.js'; import { doLogin, doQuickLogin } from './login.js'; test('Login - Basic Test', async ({ page }) => { @@ -25,13 +26,13 @@ test('Login - Quick Test', async ({ page }) => { await expect(page).toHaveTitle(/^InvenTree/); // Go to the dashboard - await page.goto(baseUrl); + await navigate(page, ''); await page.waitForURL('**/platform'); await page.getByText('InvenTree Demo Server - ').waitFor(); // Logout (via URL) - await page.goto(`${baseUrl}/logout/`); + await navigate(page, 'logout'); await page.waitForURL('**/platform/login'); await page.getByLabel('username'); }); @@ -48,7 +49,7 @@ test('Login - Failures', async ({ page }) => { }; // Navigate to the 'login' page - await page.goto(logoutUrl); + await navigate(page, logoutUrl); await expect(page).toHaveTitle(/^InvenTree.*$/); await page.waitForURL('**/platform/login'); @@ -81,7 +82,7 @@ test('Login - Change Password', async ({ page }) => { await doQuickLogin(page, 'noaccess', 'youshallnotpass'); // Navigate to the 'change password' page - await page.goto(`${baseUrl}/settings/user/account`); + await navigate(page, 'settings/user/account'); await page.getByLabel('action-menu-user-actions').click(); await page.getByLabel('action-menu-user-actions-change-password').click(); diff --git a/src/frontend/tests/pui_plugins.spec.ts b/src/frontend/tests/pui_plugins.spec.ts index 6e859632b036..6234421e0000 100644 --- a/src/frontend/tests/pui_plugins.spec.ts +++ b/src/frontend/tests/pui_plugins.spec.ts @@ -1,6 +1,6 @@ import test from 'playwright/test'; -import { baseUrl } from './defaults.js'; +import { navigate } from './helpers.js'; import { doQuickLogin } from './login.js'; import { setPluginState, setSettingState } from './settings.js'; @@ -26,7 +26,7 @@ test('Plugins - Panels', async ({ page, request }) => { await page.waitForTimeout(500); // Navigate to the "part" page - await page.goto(`${baseUrl}/part/69/`); + await navigate(page, 'part/69/'); // Ensure basic part tab is available await page.getByRole('tab', { name: 'Part Details' }).waitFor(); @@ -75,7 +75,7 @@ test('Plugins - Custom Admin', async ({ page, request }) => { }); // Navigate to the "admin" page - await page.goto(`${baseUrl}/settings/admin/plugin/`); + await navigate(page, 'settings/admin/plugin/'); // Open the plugin drawer, and ensure that the custom admin elements are visible await page.getByText('SampleUI').click(); @@ -108,7 +108,7 @@ test('Plugins - Locate Item', async ({ page, request }) => { await page.waitForTimeout(500); // Navigate to the "stock item" page - await page.goto(`${baseUrl}/stock/item/287/`); + await navigate(page, 'stock/item/287/'); // "Locate" this item await page.getByLabel('action-button-locate-item').click(); diff --git a/src/frontend/tests/pui_printing.spec.ts b/src/frontend/tests/pui_printing.spec.ts index 986274327fd5..a25ebb0909a0 100644 --- a/src/frontend/tests/pui_printing.spec.ts +++ b/src/frontend/tests/pui_printing.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from './baseFixtures.js'; -import { baseUrl } from './defaults.js'; +import { navigate } from './helpers.js'; import { doQuickLogin } from './login.js'; import { setPluginState } from './settings.js'; @@ -11,7 +11,7 @@ import { setPluginState } from './settings.js'; test('Label Printing', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/stock/location/index/`); + await navigate(page, 'stock/location/index/'); await page.waitForURL('**/platform/stock/location/**'); await page.getByRole('tab', { name: 'Stock Items' }).click(); @@ -55,7 +55,7 @@ test('Label Printing', async ({ page }) => { test('Report Printing', async ({ page }) => { await doQuickLogin(page); - await page.goto(`${baseUrl}/stock/location/index/`); + await navigate(page, 'stock/location/index/'); await page.waitForURL('**/platform/stock/location/**'); // Navigate to a specific PurchaseOrder diff --git a/src/frontend/tests/pui_settings.spec.ts b/src/frontend/tests/pui_settings.spec.ts index 81de59426731..8ca65aa22d34 100644 --- a/src/frontend/tests/pui_settings.spec.ts +++ b/src/frontend/tests/pui_settings.spec.ts @@ -1,5 +1,6 @@ import { expect, test } from './baseFixtures.js'; -import { apiUrl, baseUrl } from './defaults.js'; +import { apiUrl } from './defaults.js'; +import { navigate } from './helpers.js'; import { doQuickLogin } from './login.js'; import { setSettingState } from './settings.js'; @@ -165,7 +166,7 @@ test('Settings - Admin - Unauthorized', async ({ page }) => { // Try to access "admin" page with a non-staff user await doQuickLogin(page, 'allaccess', 'nolimits'); - await page.goto(`${baseUrl}/settings/admin/`); + await navigate(page, 'settings/admin/'); await page.waitForURL('**/settings/admin/**'); // Should get a permission denied message @@ -175,14 +176,14 @@ test('Settings - Admin - Unauthorized', async ({ page }) => { .waitFor(); // Try to access user settings page (should be accessible) - await page.goto(`${baseUrl}/settings/user/`); + await navigate(page, 'settings/user/'); await page.waitForURL('**/settings/user/**'); await page.getByRole('tab', { name: 'Display Options' }).click(); await page.getByRole('tab', { name: 'Account' }).click(); // Try to access global settings page - await page.goto(`${baseUrl}/settings/system/`); + await navigate(page, 'settings/system/'); await page.waitForURL('**/settings/system/**'); await page.getByText('Permission Denied').waitFor(); diff --git a/src/frontend/tests/pui_tables.spec.ts b/src/frontend/tests/pui_tables.spec.ts index eef38b6dd481..52957bef6044 100644 --- a/src/frontend/tests/pui_tables.spec.ts +++ b/src/frontend/tests/pui_tables.spec.ts @@ -1,13 +1,16 @@ import { test } from './baseFixtures.js'; -import { baseUrl } from './defaults.js'; -import { clearTableFilters, setTableChoiceFilter } from './helpers.js'; +import { + clearTableFilters, + navigate, + setTableChoiceFilter +} from './helpers.js'; import { doQuickLogin } from './login.js'; test('Tables - Filters', async ({ page }) => { await doQuickLogin(page); // Head to the "build order list" page - await page.goto(`${baseUrl}/manufacturing/index/`); + await navigate(page, 'manufacturing/index/'); await clearTableFilters(page); @@ -18,14 +21,14 @@ test('Tables - Filters', async ({ page }) => { await clearTableFilters(page); // Head to the "part list" page - await page.goto(`${baseUrl}/part/category/index/parts/`); + await navigate(page, 'part/category/index/parts/'); await setTableChoiceFilter(page, 'Assembly', 'Yes'); await clearTableFilters(page); // Head to the "purchase order list" page - await page.goto(`${baseUrl}/purchasing/index/purchaseorders/`); + await navigate(page, 'purchasing/index/purchaseorders/'); await clearTableFilters(page); @@ -42,7 +45,7 @@ test('Tables - Columns', async ({ page }) => { await doQuickLogin(page); // Go to the "stock list" page - await page.goto(`${baseUrl}/stock/location/index/stock-items`); + await navigate(page, 'stock/location/index/stock-items'); // Open column selector await page.getByLabel('table-select-columns').click(); @@ -52,7 +55,7 @@ test('Tables - Columns', async ({ page }) => { await page.getByRole('menuitem', { name: 'Stocktake' }).click(); await page.keyboard.press('Escape'); - await page.goto(`${baseUrl}/sales/index/salesorders`); + await navigate(page, '/sales/index/salesorders'); // Open column selector await page.getByLabel('table-select-columns').click(); diff --git a/src/frontend/tests/settings/selectionList.spec.ts b/src/frontend/tests/settings/selectionList.spec.ts index b7cc3166111c..cc6677819a32 100644 --- a/src/frontend/tests/settings/selectionList.spec.ts +++ b/src/frontend/tests/settings/selectionList.spec.ts @@ -1,5 +1,5 @@ import { test } from '../baseFixtures'; -import { baseUrl } from '../defaults'; +import { navigate } from '../helpers'; import { doQuickLogin } from '../login'; test('PUI - Admin - Parameter', async ({ page }) => { @@ -75,7 +75,7 @@ test('PUI - Admin - Parameter', async ({ page }) => { await page.getByRole('cell', { name: 'my custom parameter' }).click(); // Fill parameter - await page.goto(`${baseUrl}/part/104/parameters/`); + await navigate(page, 'part/104/parameters/'); await page.getByLabel('Parameters').getByText('Parameters').waitFor(); await page.waitForLoadState('networkidle'); await page.getByLabel('action-button-add-parameter').waitFor();