2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-14 16:29:57 +00:00

Add playwright test for company parameters

This commit is contained in:
Oliver Walters
2025-12-03 13:59:49 +00:00
parent fb8a2014ac
commit b71d56654d
3 changed files with 50 additions and 22 deletions

View File

@@ -1,11 +1,20 @@
import { expect } from '@playwright/test'; import { type Page, expect } from '@playwright/test';
import { createApi } from './api'; import { createApi } from './api';
export const clickOnParamFilter = async (page: Page, name: string) => {
const button = await page
.getByRole('button', { name: `${name} Not sorted` })
.getByRole('button')
.first();
await button.scrollIntoViewIfNeeded();
await button.click();
};
/** /**
* Open the filter drawer for the currently visible table * Open the filter drawer for the currently visible table
* @param page - The page object * @param page - The page object
*/ */
export const openFilterDrawer = async (page) => { export const openFilterDrawer = async (page: Page) => {
await page.getByLabel('table-select-filters').click(); await page.getByLabel('table-select-filters').click();
}; };
@@ -13,7 +22,7 @@ export const openFilterDrawer = async (page) => {
* Close the filter drawer for the currently visible table * Close the filter drawer for the currently visible table
* @param page - The page object * @param page - The page object
*/ */
export const closeFilterDrawer = async (page) => { export const closeFilterDrawer = async (page: Page) => {
await page.getByLabel('filter-drawer-close').click(); await page.getByLabel('filter-drawer-close').click();
}; };
@@ -22,7 +31,11 @@ export const closeFilterDrawer = async (page) => {
* @param page - The page object * @param page - The page object
* @param name - The name of the button to click * @param name - The name of the button to click
*/ */
export const clickButtonIfVisible = async (page, name, timeout = 500) => { export const clickButtonIfVisible = async (
page: Page,
name: string,
timeout = 500
) => {
await page.waitForTimeout(timeout); await page.waitForTimeout(timeout);
if (await page.getByRole('button', { name }).isVisible()) { if (await page.getByRole('button', { name }).isVisible()) {
@@ -34,14 +47,14 @@ export const clickButtonIfVisible = async (page, name, timeout = 500) => {
* Clear all filters from the currently visible table * Clear all filters from the currently visible table
* @param page - The page object * @param page - The page object
*/ */
export const clearTableFilters = async (page) => { export const clearTableFilters = async (page: Page) => {
await openFilterDrawer(page); await openFilterDrawer(page);
await clickButtonIfVisible(page, 'Clear Filters', 250); await clickButtonIfVisible(page, 'Clear Filters', 250);
await closeFilterDrawer(page); await closeFilterDrawer(page);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
}; };
export const setTableChoiceFilter = async (page, filter, value) => { export const setTableChoiceFilter = async (page: Page, filter, value) => {
await openFilterDrawer(page); await openFilterDrawer(page);
await page.getByRole('button', { name: 'Add Filter' }).click(); await page.getByRole('button', { name: 'Add Filter' }).click();
@@ -103,7 +116,7 @@ export const navigate = async (
/** /**
* CLick on the 'tab' element with the provided name * CLick on the 'tab' element with the provided name
*/ */
export const loadTab = async (page, tabName, exact?) => { export const loadTab = async (page: Page, tabName, exact?) => {
await page await page
.getByLabel(/panel-tabs-/) .getByLabel(/panel-tabs-/)
.getByRole('tab', { name: tabName, exact: exact ?? false }) .getByRole('tab', { name: tabName, exact: exact ?? false })
@@ -113,13 +126,13 @@ export const loadTab = async (page, tabName, exact?) => {
}; };
// Activate "table" view in certain contexts // Activate "table" view in certain contexts
export const activateTableView = async (page) => { export const activateTableView = async (page: Page) => {
await page.getByLabel('segmented-icon-control-table').click(); await page.getByLabel('segmented-icon-control-table').click();
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
}; };
// Activate "calendar" view in certain contexts // Activate "calendar" view in certain contexts
export const activateCalendarView = async (page) => { export const activateCalendarView = async (page: Page) => {
await page.getByLabel('segmented-icon-control-calendar').click(); await page.getByLabel('segmented-icon-control-calendar').click();
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
}; };
@@ -127,7 +140,7 @@ export const activateCalendarView = async (page) => {
/** /**
* Perform a 'global search' on the provided page, for the provided query text * Perform a 'global search' on the provided page, for the provided query text
*/ */
export const globalSearch = async (page, query) => { export const globalSearch = async (page: Page, query) => {
await page.getByLabel('open-search').click(); await page.getByLabel('open-search').click();
await page.getByLabel('global-search-input').clear(); await page.getByLabel('global-search-input').clear();
await page.getByPlaceholder('Enter search text').fill(query); await page.getByPlaceholder('Enter search text').fill(query);

View File

@@ -1,5 +1,5 @@
import { test } from '../baseFixtures.js'; import { test } from '../baseFixtures.js';
import { loadTab, navigate } from '../helpers.js'; import { clickOnParamFilter, loadTab, navigate } from '../helpers.js';
import { doCachedLogin } from '../login.js'; import { doCachedLogin } from '../login.js';
test('Company', async ({ browser }) => { test('Company', async ({ browser }) => {
@@ -40,3 +40,26 @@ test('Company', async ({ browser }) => {
await page.getByText('Enter a valid URL.').waitFor(); await page.getByText('Enter a valid URL.').waitFor();
await page.getByRole('button', { name: 'Cancel' }).click(); await page.getByRole('button', { name: 'Cancel' }).click();
}); });
test('Company - Parameters', async ({ browser }) => {
const page = await doCachedLogin(browser, {
username: 'steven',
password: 'wizardstaff',
url: 'purchasing/index/suppliers'
});
// Show parametric view
await page
.getByRole('button', { name: 'segmented-icon-control-parametric' })
.click();
await page.getByText('1 - 14 / 14').waitFor();
// Filter by "payment terms" parameter value
await clickOnParamFilter(page, 'Payment Terms');
await page.getByRole('option', { name: 'NET-30' }).click();
await page.getByText('1 - 2 / 2').waitFor();
await page.getByRole('cell', { name: 'Arrow Electronics' }).waitFor();
await page.getByRole('cell', { name: 'PCB assembly house' }).waitFor();
});

View File

@@ -1,6 +1,7 @@
import { test } from '../baseFixtures'; import { test } from '../baseFixtures';
import { import {
clearTableFilters, clearTableFilters,
clickOnParamFilter,
clickOnRowMenu, clickOnRowMenu,
deletePart, deletePart,
getRowFromCell, getRowFromCell,
@@ -570,24 +571,15 @@ test('Parts - Parameter Filtering', async ({ browser }) => {
// All parts should be available (no filters applied) // All parts should be available (no filters applied)
await page.getByText(/\/ 42\d/).waitFor(); await page.getByText(/\/ 42\d/).waitFor();
const clickOnParamFilter = async (name: string) => {
const button = await page
.getByRole('button', { name: `${name} Not sorted` })
.getByRole('button')
.first();
await button.scrollIntoViewIfNeeded();
await button.click();
};
const clearParamFilter = async (name: string) => { const clearParamFilter = async (name: string) => {
await clickOnParamFilter(name); await clickOnParamFilter(page, name);
await page.getByLabel(`clear-filter-${name}`).waitFor(); await page.getByLabel(`clear-filter-${name}`).waitFor();
await page.getByLabel(`clear-filter-${name}`).click(); await page.getByLabel(`clear-filter-${name}`).click();
// await page.getByLabel(`clear-filter-${name}`).click(); // await page.getByLabel(`clear-filter-${name}`).click();
}; };
// Let's filter by color // Let's filter by color
await clickOnParamFilter('Color'); await clickOnParamFilter(page, 'Color');
await page.getByRole('option', { name: 'Red' }).click(); await page.getByRole('option', { name: 'Red' }).click();
// Only 10 parts available // Only 10 parts available