mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-06 05:30:56 +00:00
[PUI] Form error fix (#8204)
* Handle simple string error message * Add playwright test for form validation * Render stock unit price / total value * Fix for TextField: - Prevent unnecessary value change - This was removing the field error * Add playwright test for supplier form validation
This commit is contained in:
127
src/frontend/tests/pui_forms.spec.ts
Normal file
127
src/frontend/tests/pui_forms.spec.ts
Normal file
@ -0,0 +1,127 @@
|
||||
/** Unit tests for form validation, rendering, etc */
|
||||
import test from 'playwright/test';
|
||||
|
||||
import { baseUrl } from './defaults';
|
||||
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 page.waitForURL('**/platform/stock/location/**');
|
||||
|
||||
// Create new stock item form
|
||||
await page.getByLabel('action-button-add-stock-item').click();
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
// Check for validation errors
|
||||
await page.getByText('Form Error').waitFor();
|
||||
await page.getByText('Errors exist for one or more form fields').waitFor();
|
||||
await page.getByText('Valid part must be supplied').waitFor();
|
||||
|
||||
// Adjust other field - the errors should persist
|
||||
await page.getByLabel('text-field-batch').fill('BATCH-123');
|
||||
await page.waitForTimeout(250);
|
||||
|
||||
await page.getByText('Valid part must be supplied').waitFor();
|
||||
|
||||
// Fill out fields
|
||||
await page.getByLabel('number-field-quantity').fill('-1');
|
||||
await page.getByLabel('related-field-part').click();
|
||||
await page.getByRole('option', { name: /1551AGY/ }).click();
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
// Check for validation errors
|
||||
await page.getByText('Errors exist for one or more form fields').waitFor();
|
||||
await page
|
||||
.getByText(/Ensure this value is greater than or equal to 0/)
|
||||
.first()
|
||||
.waitFor();
|
||||
|
||||
// Set location
|
||||
await page.getByLabel('related-field-location').click();
|
||||
await page.getByRole('option', { name: /Electronics Lab/ }).click();
|
||||
|
||||
// Create the stock item
|
||||
await page.getByLabel('number-field-quantity').fill('123');
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
// Edit the resulting stock item
|
||||
await page.getByLabel('action-menu-stock-item-actions').click();
|
||||
await page.getByLabel('action-menu-stock-item-actions-edit').click();
|
||||
|
||||
await page.getByLabel('number-field-purchase_price').fill('-1');
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
await page.getByText('Errors exist for one or more form fields').waitFor();
|
||||
await page
|
||||
.getByText('Ensure this value is greater than or equal to 0')
|
||||
.waitFor();
|
||||
|
||||
// Check the error message still persists after editing a different field
|
||||
await page.getByLabel('text-field-packaging').fill('a box');
|
||||
await page.waitForTimeout(250);
|
||||
await page
|
||||
.getByText('Ensure this value is greater than or equal to 0')
|
||||
.waitFor();
|
||||
|
||||
// Correct the price
|
||||
await page.getByLabel('number-field-purchase_price').fill('1.2345');
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
await page.getByText('Item Updated').waitFor();
|
||||
|
||||
// Ensure the stock item has been updated correctly
|
||||
await page.getByText('$151.8435').waitFor();
|
||||
await page.getByText('$151.8435').waitFor();
|
||||
await page.getByText('a box').waitFor();
|
||||
await page.getByRole('cell', { name: 'Electronics Lab' }).waitFor();
|
||||
});
|
||||
|
||||
test('Forms - Supplier Validation', async ({ page, request }) => {
|
||||
await doQuickLogin(page, 'steven', 'wizardstaff');
|
||||
await page.goto(`${baseUrl}/purchasing/index/suppliers`);
|
||||
await page.waitForURL('**/purchasing/index/**');
|
||||
|
||||
await page.getByLabel('action-button-add-company').click();
|
||||
await page.getByLabel('text-field-website').fill('not-a-website');
|
||||
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
// Check for validation errors
|
||||
await page.getByText('Form Error').waitFor();
|
||||
await page.getByText('Errors exist for one or more').waitFor();
|
||||
await page.getByText('This field may not be blank.').waitFor();
|
||||
await page.getByText('Enter a valid URL.').waitFor();
|
||||
|
||||
// Fill out another field, expect that the errors persist
|
||||
await page.getByLabel('text-field-description').fill('A description');
|
||||
await page.waitForTimeout(250);
|
||||
await page.getByText('This field may not be blank.').waitFor();
|
||||
await page.getByText('Enter a valid URL.').waitFor();
|
||||
|
||||
// Generate a unique supplier name
|
||||
const supplierName = `Supplier ${new Date().getTime()}`;
|
||||
|
||||
// Fill with good data
|
||||
await page
|
||||
.getByLabel('text-field-website')
|
||||
.fill('https://www.test-website.co.uk');
|
||||
await page.getByLabel('text-field-name').fill(supplierName);
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
await page.getByText(supplierName).waitFor();
|
||||
await page
|
||||
.getByRole('link', { name: 'https://www.test-website.co.uk' })
|
||||
.waitFor();
|
||||
|
||||
// Now, try to create another new supplier with the same name
|
||||
await page.goto(`${baseUrl}/purchasing/index/suppliers`);
|
||||
await page.waitForURL('**/purchasing/index/**');
|
||||
await page.getByLabel('action-button-add-company').click();
|
||||
await page.getByLabel('text-field-name').fill(supplierName);
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
|
||||
// Is prevented, due to uniqueness requirements
|
||||
await page
|
||||
.getByText('Company with this Company name and Email already exists')
|
||||
.waitFor();
|
||||
await page.getByRole('button', { name: 'Cancel' }).click();
|
||||
});
|
Reference in New Issue
Block a user