2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00
Files
InvenTree/src/frontend/tests/pui_settings.spec.ts
Oliver afad866d1d [PUI] form error fix (#7689)
* Make initial data query wait until options query is complete

* Fix form error issues

- Form fields were being re-constructed

* Update playwright tests - check for form error message

* Prevent reconstruction of form fields

* Hide form elements until OPTIONS request is complete

* Fix for <ChoiceField />

- "value" must be stringified!

* Handle undefined choice values

* Add "batch code" to stock detail page

* Fix for initial focus

* Allow form field definition to change externally

* Force override of fetched data

* Update playwright tests

* Add backup value

* Cleanup initialdataquery

* Unit test updates

* Test updates

* Tweak API Form

* Adjust playwright test
2024-07-21 14:27:18 +10:00

118 lines
5.1 KiB
TypeScript

import { expect, test } from './baseFixtures.js';
import { baseUrl } from './defaults.js';
import { doQuickLogin } from './login.js';
test('PUI - Admin', async ({ page }) => {
// Note here we login with admin access
await doQuickLogin(page, 'admin', 'inventree');
// User settings
await page.getByRole('button', { name: 'admin' }).click();
await page.getByRole('menuitem', { name: 'Account settings' }).click();
await page.getByRole('tab', { name: 'Security' }).click();
await page.getByRole('tab', { name: 'Display Options' }).click();
await page.getByText('Date Format').waitFor();
await page.getByRole('tab', { name: 'Search' }).click();
await page.getByText('Regex Search').waitFor();
await page.getByRole('tab', { name: 'Notifications' }).click();
await page.getByRole('tab', { name: 'Reporting' }).click();
await page.getByText('Inline report display').waitFor();
// System Settings
await page.getByRole('link', { name: 'Switch to System Setting' }).click();
await page.getByText('Base URL', { exact: true }).waitFor();
await page.getByRole('tab', { name: 'Login' }).click();
await page.getByRole('tab', { name: 'Barcodes' }).click();
await page.getByRole('tab', { name: 'Notifications' }).click();
await page.getByRole('tab', { name: 'Pricing' }).click();
await page.getByRole('tab', { name: 'Labels' }).click();
await page.getByRole('tab', { name: 'Reporting' }).click();
await page.getByRole('tab', { name: 'Stocktake' }).click();
await page.getByRole('tab', { name: 'Build Orders' }).click();
await page.getByRole('tab', { name: 'Purchase Orders' }).click();
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.getByRole('tab', { name: 'Return Orders' }).click();
// Admin Center
await page.getByRole('button', { name: 'admin' }).click();
await page.getByRole('menuitem', { name: 'Admin Center' }).click();
await page.getByRole('tab', { name: 'Background Tasks' }).click();
await page.getByRole('tab', { name: 'Error Reports' }).click();
await page.getByRole('tab', { name: 'Currencies' }).click();
await page.getByRole('tab', { name: 'Project Codes' }).click();
await page.getByRole('tab', { name: 'Custom Units' }).click();
await page.getByRole('tab', { name: 'Part Parameters' }).click();
await page.getByRole('tab', { name: 'Category Parameters' }).click();
await page.getByRole('tab', { name: 'Label Templates' }).click();
await page.getByRole('tab', { name: 'Report Templates' }).click();
await page.getByRole('tab', { name: 'Plugins' }).click();
// Adjust some "location type" items
await page.getByRole('tab', { name: 'Location Types' }).click();
// Edit first item
await page.getByLabel('row-action-menu-0').click();
await page.getByRole('menuitem', { name: 'Edit' }).click();
await expect(page.getByLabel('text-field-name')).toHaveValue('Room');
await expect(page.getByLabel('text-field-description')).toHaveValue('A room');
await page.getByLabel('text-field-name').fill('Large Room');
await page.waitForTimeout(500);
await page.getByLabel('text-field-description').fill('A large room');
await page.waitForTimeout(500);
await page.getByRole('button', { name: 'Submit' }).click();
// Edit second item
await page.getByLabel('row-action-menu-1').click();
await page.getByRole('menuitem', { name: 'Edit' }).click();
await expect(page.getByLabel('text-field-name')).toHaveValue('Box (Large)');
await expect(page.getByLabel('text-field-description')).toHaveValue(
'Large cardboard box'
);
await page.getByRole('button', { name: 'Cancel' }).click();
// Edit first item again (revert values)
await page.getByLabel('row-action-menu-0').click();
await page.getByRole('menuitem', { name: 'Edit' }).click();
await expect(page.getByLabel('text-field-name')).toHaveValue('Large Room');
await expect(page.getByLabel('text-field-description')).toHaveValue(
'A large room'
);
await page.getByLabel('text-field-name').fill('Room');
await page.waitForTimeout(500);
await page.getByLabel('text-field-description').fill('A room');
await page.waitForTimeout(500);
await page.getByRole('button', { name: 'Submit' }).click();
});
test('PUI - 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 page.waitForURL('**/settings/admin/**');
// Should get a permission denied message
await page.getByText('Permission Denied').waitFor();
await page
.getByRole('button', { name: 'Return to the index page' })
.waitFor();
// Try to access user settings page (should be accessible)
await page.goto(`${baseUrl}/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 page.waitForURL('**/settings/system/**');
await page.getByText('Permission Denied').waitFor();
await page
.getByRole('button', { name: 'Return to the index page' })
.waitFor();
});