Skip to content

Commit

Permalink
[PUI] Form error fix (#8204)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SchrodingersGat authored Sep 28, 2024
1 parent e6470ff commit 390fec3
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 52 deletions.
3 changes: 3 additions & 0 deletions src/frontend/src/components/forms/ApiForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ export function ApiForm({
// Standard error handling for other fields
form.setError(path, { message: v.join(', ') });
}
} else if (typeof v === 'string') {
form.setError(path, { message: v });
} else {
processErrors(v, path);
}
Expand All @@ -529,6 +531,7 @@ export function ApiForm({

processErrors(error.response.data);
setNonFieldErrors(_nonFieldErrors);

break;
default:
// Unexpected state on form error
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/components/forms/fields/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default function TextField({
radius="sm"
onChange={(event) => onTextChange(event.currentTarget.value)}
onBlur={(event) => {
onChange(event.currentTarget.value);
if (event.currentTarget.value != value) {
onChange(event.currentTarget.value);
}
}}
onKeyDown={(event) => onKeyDown(event.code)}
rightSection={
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export function useStockFields({
part: {
value: part,
disabled: !create,
filters: {
active: create ? true : undefined
},
onValueChange: (value, record) => {
setPart(value);
// TODO: implement remaining functionality from old stock.py
Expand Down
31 changes: 29 additions & 2 deletions src/frontend/src/pages/stock/StockDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PageDetail } from '../../components/nav/PageDetail';
import { PanelType } from '../../components/nav/Panel';
import { PanelGroup } from '../../components/nav/PanelGroup';
import { StatusRenderer } from '../../components/render/StatusRenderer';
import { formatCurrency } from '../../defaults/formatters';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import { UserRoles } from '../../enums/Roles';
Expand Down Expand Up @@ -179,8 +180,6 @@ export default function StockDetail() {
label: t`Batch Code`,
hidden: !stockitem.batch
}
// TODO: allocated_to_sales_orders
// TODO: allocated_to_build_orders
];

// Bottom left: location information
Expand Down Expand Up @@ -264,6 +263,34 @@ export default function StockDetail() {
let br: DetailsField[] = [
// TODO: Expiry date
// TODO: Ownership
{
type: 'text',
name: 'purchase_price',
label: t`Unit Price`,
icon: 'currency',
hidden: !stockitem.purchase_price,
value_formatter: () => {
return formatCurrency(stockitem.purchase_price, {
currency: stockitem.purchase_price_currency
});
}
},
{
type: 'text',
name: 'stock_value',
label: t`Stock Value`,
icon: 'currency',
hidden:
!stockitem.purchase_price ||
stockitem.quantity == 1 ||
stockitem.quantity == 0,
value_formatter: () => {
return formatCurrency(stockitem.purchase_price, {
currency: stockitem.purchase_price_currency,
multiplier: stockitem.quantity
});
}
},
{
type: 'text',
name: 'packaging',
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/tests/modals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from './baseFixtures.js';
import { doQuickLogin } from './login.js';

test('PUI - Modals as admin', async ({ page }) => {
test('Modals as admin', async ({ page }) => {
await doQuickLogin(page, 'admin', 'inventree');

// use server info
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/tests/pages/pui_build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from '../baseFixtures.ts';
import { baseUrl } from '../defaults.ts';
import { doQuickLogin } from '../login.ts';

test('PUI - Pages - Build Order', async ({ page }) => {
test('Pages - Build Order', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/`);
Expand Down Expand Up @@ -82,7 +82,7 @@ test('PUI - Pages - Build Order', async ({ page }) => {
.waitFor();
});

test('PUI - Pages - Build Order - Build Outputs', async ({ page }) => {
test('Pages - Build Order - Build Outputs', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/`);
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/tests/pages/pui_index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { doQuickLogin } from '../login.js';

const newPartName = 'UITESTIN123';

test('PUI - Pages - Index - Playground', async ({ page }) => {
test('Pages - Index - Playground', async ({ page }) => {
await doQuickLogin(page);

await page.goto('./');
Expand Down Expand Up @@ -72,7 +72,7 @@ test('PUI - Pages - Index - Playground', async ({ page }) => {
await page.getByText('Attention needed').waitFor();
});

test('PUI - Pages - Index - Dashboard', async ({ page }) => {
test('Pages - Index - Dashboard', async ({ page }) => {
await doQuickLogin(page);

// Dashboard auto update
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/tests/pages/pui_orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from '../baseFixtures.ts';
import { baseUrl } from '../defaults.ts';
import { doQuickLogin } from '../login.ts';

test('PUI - Sales Orders', async ({ page }) => {
test('Sales Orders', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/home`);
Expand Down Expand Up @@ -41,7 +41,7 @@ test('PUI - Sales Orders', async ({ page }) => {
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});

test('PUI - Purchase Orders', async ({ page }) => {
test('Purchase Orders', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/home`);
Expand All @@ -61,7 +61,7 @@ test('PUI - Purchase Orders', async ({ page }) => {
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});

test('PUI - Purchase Orders - Barcodes', async ({ page }) => {
test('Purchase Orders - Barcodes', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/purchasing/purchase-order/13/detail`);
Expand Down
22 changes: 11 additions & 11 deletions src/frontend/tests/pages/pui_part.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from '../baseFixtures';
import { baseUrl } from '../defaults';
import { doQuickLogin } from '../login';

test('PUI - Pages - Part - Locking', async ({ page }) => {
test('Pages - Part - Locking', async ({ page }) => {
await doQuickLogin(page);

// Navigate to a known assembly which is *not* locked
Expand All @@ -23,7 +23,7 @@ test('PUI - Pages - Part - Locking', async ({ page }) => {
await page.getByText('Part parameters cannot be').waitFor();
});

test('PUI - Pages - Part - Pricing (Nothing, BOM)', async ({ page }) => {
test('Pages - Part - Pricing (Nothing, BOM)', async ({ page }) => {
await doQuickLogin(page);

// Part with no history
Expand Down Expand Up @@ -72,7 +72,7 @@ test('PUI - Pages - Part - Pricing (Nothing, BOM)', async ({ page }) => {
await page.waitForURL('**/part/98/**');
});

test('PUI - Pages - Part - Pricing (Supplier)', async ({ page }) => {
test('Pages - Part - Pricing (Supplier)', async ({ page }) => {
await doQuickLogin(page);

// Part
Expand All @@ -98,7 +98,7 @@ test('PUI - Pages - Part - Pricing (Supplier)', async ({ page }) => {
// await page.waitForURL('**/purchasing/supplier-part/697/');
});

test('PUI - Pages - Part - Pricing (Variant)', async ({ page }) => {
test('Pages - Part - Pricing (Variant)', async ({ page }) => {
await doQuickLogin(page);

// Part
Expand All @@ -124,7 +124,7 @@ test('PUI - Pages - Part - Pricing (Variant)', async ({ page }) => {
await page.waitForURL('**/part/109/**');
});

test('PUI - Pages - Part - Pricing (Internal)', async ({ page }) => {
test('Pages - Part - Pricing (Internal)', async ({ page }) => {
await doQuickLogin(page);

// Part
Expand All @@ -149,7 +149,7 @@ test('PUI - Pages - Part - Pricing (Internal)', async ({ page }) => {
await page.getByText('Part *M2x4 SHCSSocket head').click();
});

test('PUI - Pages - Part - Pricing (Purchase)', async ({ page }) => {
test('Pages - Part - Pricing (Purchase)', async ({ page }) => {
await doQuickLogin(page);

// Part
Expand All @@ -171,7 +171,7 @@ test('PUI - Pages - Part - Pricing (Purchase)', async ({ page }) => {
await page.getByText('2022-04-29').waitFor();
});

test('PUI - Pages - Part - Attachments', async ({ page }) => {
test('Pages - Part - Attachments', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/69/attachments`);
Expand All @@ -193,7 +193,7 @@ test('PUI - Pages - Part - Attachments', async ({ page }) => {
await page.getByRole('button', { name: 'Cancel' }).click();
});

test('PUI - Pages - Part - Parameters', async ({ page }) => {
test('Pages - Part - Parameters', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/69/parameters`);
Expand All @@ -220,7 +220,7 @@ test('PUI - Pages - Part - Parameters', async ({ page }) => {
await page.getByRole('button', { name: 'Cancel' }).click();
});

test('PUI - Pages - Part - Notes', async ({ page }) => {
test('Pages - Part - Notes', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/69/notes`);
Expand All @@ -241,7 +241,7 @@ test('PUI - Pages - Part - Notes', async ({ page }) => {
await page.getByLabel('Save Notes').waitFor();
});

test('PUI - Pages - Part - 404', async ({ page }) => {
test('Pages - Part - 404', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/99999/`);
Expand All @@ -251,7 +251,7 @@ test('PUI - Pages - Part - 404', async ({ page }) => {
await page.evaluate(() => console.clear());
});

test('PUI - Pages - Part - Revision', async ({ page }) => {
test('Pages - Part - Revision', async ({ page }) => {
await doQuickLogin(page);

await page.goto(`${baseUrl}/part/906/details`);
Expand Down
16 changes: 8 additions & 8 deletions src/frontend/tests/pages/pui_scan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function defaultScanTest(page, search_text) {
await page.getByRole('button', { name: 'Lookup part' }).click();
}

test('PUI - Pages - Index - Scan (Part)', async ({ page }) => {
test('Pages - Index - Scan (Part)', async ({ page }) => {
await defaultScanTest(page, '{"part": 1}');

// part: 1
Expand All @@ -33,7 +33,7 @@ test('PUI - Pages - Index - Scan (Part)', async ({ page }) => {
await page.getByRole('cell', { name: 'part' }).waitFor();
});

test('PUI - Pages - Index - Scan (Stockitem)', async ({ page }) => {
test('Pages - Index - Scan (Stockitem)', async ({ page }) => {
await defaultScanTest(page, '{"stockitem": 408}');

// stockitem: 408
Expand All @@ -42,7 +42,7 @@ test('PUI - Pages - Index - Scan (Stockitem)', async ({ page }) => {
await page.getByRole('cell', { name: 'Quantity: 100' }).waitFor();
});

test('PUI - Pages - Index - Scan (StockLocation)', async ({ page }) => {
test('Pages - Index - Scan (StockLocation)', async ({ page }) => {
await defaultScanTest(page, '{"stocklocation": 3}');

// stocklocation: 3
Expand All @@ -51,7 +51,7 @@ test('PUI - Pages - Index - Scan (StockLocation)', async ({ page }) => {
await page.getByRole('cell', { name: 'stocklocation' }).waitFor();
});

test('PUI - Pages - Index - Scan (SupplierPart)', async ({ page }) => {
test('Pages - Index - Scan (SupplierPart)', async ({ page }) => {
await defaultScanTest(page, '{"supplierpart": 204}');

// supplierpart: 204
Expand All @@ -60,7 +60,7 @@ test('PUI - Pages - Index - Scan (SupplierPart)', async ({ page }) => {
await page.getByRole('cell', { name: 'supplierpart' }).waitFor();
});

test('PUI - Pages - Index - Scan (PurchaseOrder)', async ({ page }) => {
test('Pages - Index - Scan (PurchaseOrder)', async ({ page }) => {
await defaultScanTest(page, '{"purchaseorder": 12}');

// purchaseorder: 12
Expand All @@ -69,7 +69,7 @@ test('PUI - Pages - Index - Scan (PurchaseOrder)', async ({ page }) => {
await page.getByRole('cell', { name: 'purchaseorder' }).waitFor();
});

test('PUI - Pages - Index - Scan (SalesOrder)', async ({ page }) => {
test('Pages - Index - Scan (SalesOrder)', async ({ page }) => {
await defaultScanTest(page, '{"salesorder": 6}');

// salesorder: 6
Expand All @@ -78,7 +78,7 @@ test('PUI - Pages - Index - Scan (SalesOrder)', async ({ page }) => {
await page.getByRole('cell', { name: 'salesorder' }).waitFor();
});

test('PUI - Pages - Index - Scan (Build)', async ({ page }) => {
test('Pages - Index - Scan (Build)', async ({ page }) => {
await defaultScanTest(page, '{"build": 8}');

// build: 8
Expand All @@ -87,7 +87,7 @@ test('PUI - Pages - Index - Scan (Build)', async ({ page }) => {
await page.getByRole('cell', { name: 'build', exact: true }).waitFor();
});

test('PUI - Pages - Index - Scan (General)', async ({ page }) => {
test('Pages - Index - Scan (General)', async ({ page }) => {
await defaultScanTest(page, '{"unknown": 312}');
await page.getByText('"unknown": 312').waitFor();

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/tests/pui_basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from './baseFixtures.js';
import { baseUrl, user } from './defaults.js';
import { doLogin, doQuickLogin } from './login.js';

test('PUI - Basic Login Test', async ({ page }) => {
test('Basic Login Test', async ({ page }) => {
await doLogin(page);

// Check that the username is provided
Expand Down Expand Up @@ -35,7 +35,7 @@ test('PUI - Basic Login Test', async ({ page }) => {
await page.getByLabel('username');
});

test('PUI - Quick Login Test', async ({ page }) => {
test('Quick Login Test', async ({ page }) => {
await doQuickLogin(page);

// Check that the username is provided
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/tests/pui_command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { systemKey, test } from './baseFixtures.js';
import { baseUrl } from './defaults.js';
import { doQuickLogin } from './login.js';

test('PUI - Quick Command', async ({ page }) => {
test('Quick Command', async ({ page }) => {
await doQuickLogin(page);

// Open Spotlight with Keyboard Shortcut
Expand Down Expand Up @@ -31,7 +31,7 @@ test('PUI - Quick Command', async ({ page }) => {
await page.waitForURL('**/platform/dashboard');
});

test('PUI - Quick Command - No Keys', async ({ page }) => {
test('Quick Command - No Keys', async ({ page }) => {
await doQuickLogin(page);

// Open Spotlight with Button
Expand Down
Loading

0 comments on commit 390fec3

Please sign in to comment.