From b5b0ff2666549c6fbbf07707475bfddb2197219f Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 25 Apr 2024 11:26:04 +0200 Subject: [PATCH] [PUI] Test for errors in console (#7114) * ensure no errors are thrown in the console * fix key issue * add missing keys * fix table order * fix wrong imports * add missing key * fix accessor ref * fix style * mark internal fetching errors and ignore them * do not raise internal errors * ignore barcode api calls * style fix * do not raise on chrome errors * refactor url * more exclusion * remove duplicate assertation --- .../src/components/details/DetailsBadge.tsx | 8 +------- src/frontend/src/components/nav/PageDetail.tsx | 5 +++-- src/frontend/src/pages/part/PartDetail.tsx | 18 ++++++++++++++++-- .../part/pricing/PricingOverviewPanel.tsx | 6 +++++- .../src/pages/sales/SalesOrderDetail.tsx | 1 + src/frontend/src/pages/stock/StockDetail.tsx | 4 ++++ src/frontend/src/states/ApiState.tsx | 4 ++-- src/frontend/src/states/SettingsState.tsx | 4 ++-- src/frontend/src/states/StatusState.tsx | 2 +- src/frontend/src/states/UserState.tsx | 4 ++-- .../src/tables/build/BuildOrderTable.tsx | 1 + .../src/tables/settings/ErrorTable.tsx | 6 +++++- src/frontend/tests/baseFixtures.ts | 18 ++++++++++++++++++ src/frontend/tests/modals.spec.ts | 5 ----- src/frontend/tests/pages/pui_part.spec.ts | 3 +-- 15 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/frontend/src/components/details/DetailsBadge.tsx b/src/frontend/src/components/details/DetailsBadge.tsx index d5228e9fd4..9aeeef67f7 100644 --- a/src/frontend/src/components/details/DetailsBadge.tsx +++ b/src/frontend/src/components/details/DetailsBadge.tsx @@ -5,7 +5,6 @@ export type DetailsBadgeProps = { label: string; size?: string; visible?: boolean; - key?: any; }; export default function DetailsBadge(props: DetailsBadgeProps) { @@ -14,12 +13,7 @@ export default function DetailsBadge(props: DetailsBadgeProps) { } return ( - + {props.label} ); diff --git a/src/frontend/src/components/nav/PageDetail.tsx b/src/frontend/src/components/nav/PageDetail.tsx index 6b640253f5..9450e733c1 100644 --- a/src/frontend/src/components/nav/PageDetail.tsx +++ b/src/frontend/src/components/nav/PageDetail.tsx @@ -1,7 +1,6 @@ import { Group, Paper, Space, Stack, Text } from '@mantine/core'; import { Fragment, ReactNode } from 'react'; -import DetailsBadge, { DetailsBadgeProps } from '../details/DetailsBadge'; import { ApiImage } from '../images/ApiImage'; import { StylishText } from '../items/StylishText'; import { Breadcrumb, BreadcrumbList } from './BreadcrumbList'; @@ -60,7 +59,9 @@ export function PageDetail({ {detail} - {badges} + {badges?.map((badge, idx) => ( + {badge} + ))} {actions && ( diff --git a/src/frontend/src/pages/part/PartDetail.tsx b/src/frontend/src/pages/part/PartDetail.tsx index 859048e5e5..50be4a95f8 100644 --- a/src/frontend/src/pages/part/PartDetail.tsx +++ b/src/frontend/src/pages/part/PartDetail.tsx @@ -448,7 +448,11 @@ export default function PartDetail() { - + + + + +
@@ -642,23 +646,32 @@ export default function PartDetail() { label={t`In Stock` + `: ${part.in_stock}`} color={part.in_stock >= part.minimum_stock ? 'green' : 'orange'} visible={part.in_stock > 0} + key="in_stock" />, , 0} + key="on_order" />, 0} + key="in_production" />, - + ]; }, [part, instanceQuery]); @@ -706,6 +719,7 @@ export default function PartDetail() { hidden: !part?.barcode_hash || !user.hasChangeRole(UserRoles.part) }) ]} + key="action_dropdown" />, )} - + diff --git a/src/frontend/src/pages/sales/SalesOrderDetail.tsx b/src/frontend/src/pages/sales/SalesOrderDetail.tsx index 4fea24044e..ca96e3f450 100644 --- a/src/frontend/src/pages/sales/SalesOrderDetail.tsx +++ b/src/frontend/src/pages/sales/SalesOrderDetail.tsx @@ -322,6 +322,7 @@ export default function SalesOrderDetail() { status={order.status} type={ModelType.salesorder} options={{ size: 'lg' }} + key={order.pk} /> ]; }, [order, instanceQuery]); diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index b74e2b555d..7fe1649f13 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -473,21 +473,25 @@ export default function StockDetail() { color="blue" label={t`Serial Number` + `: ${stockitem.serial}`} visible={!!stockitem.serial} + key="serial" />, , , ]; }, [stockitem, instanceQuery]); diff --git a/src/frontend/src/states/ApiState.tsx b/src/frontend/src/states/ApiState.tsx index 2b284efcf4..de6fa14838 100644 --- a/src/frontend/src/states/ApiState.tsx +++ b/src/frontend/src/states/ApiState.tsx @@ -26,7 +26,7 @@ export const useServerApiState = create()( set({ server: response.data }); }) .catch(() => { - console.error('Error fetching server info'); + console.error('ERR: Error fetching server info'); }); // Fetch login/SSO behaviour @@ -38,7 +38,7 @@ export const useServerApiState = create()( set({ auth_settings: response.data }); }) .catch(() => { - console.error('Error fetching SSO information'); + console.error('ERR: Error fetching SSO information'); }); }, status: undefined diff --git a/src/frontend/src/states/SettingsState.tsx b/src/frontend/src/states/SettingsState.tsx index 85fdba8ab3..b5d97592f2 100644 --- a/src/frontend/src/states/SettingsState.tsx +++ b/src/frontend/src/states/SettingsState.tsx @@ -42,7 +42,7 @@ export const useGlobalSettingsState = create( }); }) .catch((_error) => { - console.error('Error fetching global settings'); + console.error('ERR: Error fetching global settings'); }); }, getSetting: (key: string, default_value?: string) => { @@ -76,7 +76,7 @@ export const useUserSettingsState = create((set, get) => ({ }); }) .catch((_error) => { - console.error('Error fetching user settings'); + console.error('ERR: Error fetching user settings'); }); }, getSetting: (key: string, default_value?: string) => { diff --git a/src/frontend/src/states/StatusState.tsx b/src/frontend/src/states/StatusState.tsx index 57e845f33a..f0c27d3ccb 100644 --- a/src/frontend/src/states/StatusState.tsx +++ b/src/frontend/src/states/StatusState.tsx @@ -39,7 +39,7 @@ export const useGlobalStatusState = create()( set({ status: newStatusLookup }); }) .catch(() => { - console.error('Error fetching global status information'); + console.error('ERR: Error fetching global status information'); }); } }), diff --git a/src/frontend/src/states/UserState.tsx b/src/frontend/src/states/UserState.tsx index 35d8a82979..a203de13ae 100644 --- a/src/frontend/src/states/UserState.tsx +++ b/src/frontend/src/states/UserState.tsx @@ -57,7 +57,7 @@ export const useUserState = create((set, get) => ({ set({ user: user }); }) .catch((error) => { - console.error('Error fetching user data'); + console.error('ERR: Error fetching user data'); }); // Fetch role data @@ -75,7 +75,7 @@ export const useUserState = create((set, get) => ({ } }) .catch((_error) => { - console.error('Error fetching user roles'); + console.error('ERR: Error fetching user roles'); }); }, checkUserRole: (role: UserRoles, permission: UserPermissions) => { diff --git a/src/frontend/src/tables/build/BuildOrderTable.tsx b/src/frontend/src/tables/build/BuildOrderTable.tsx index cfc0a61346..405909cfca 100644 --- a/src/frontend/src/tables/build/BuildOrderTable.tsx +++ b/src/frontend/src/tables/build/BuildOrderTable.tsx @@ -153,6 +153,7 @@ export function BuildOrderTable({ hidden={!user.hasAddRole(UserRoles.build)} tooltip={t`Add Build Order`} onClick={() => newBuild.open()} + key="add-build-order" /> ]; }, [user]); diff --git a/src/frontend/src/tables/settings/ErrorTable.tsx b/src/frontend/src/tables/settings/ErrorTable.tsx index 0141807ec8..4fec4e3c34 100644 --- a/src/frontend/src/tables/settings/ErrorTable.tsx +++ b/src/frontend/src/tables/settings/ErrorTable.tsx @@ -68,7 +68,11 @@ export default function ErrorReportTable() { onClose={close} > {error.split('\n').map((line: string) => { - return {line}; + return ( + + {line} + + ); })} { + const messages = []; + page.on('console', (msg) => { + const url = msg.location().url; + if ( + msg.type() === 'error' && + !msg.text().startsWith('ERR: ') && + url != 'http://localhost:8000/api/barcode/' && + url != 'http://localhost:8000/api/news/?search=&offset=0&limit=25' && + url != 'https://docs.inventree.org/en/versions.json' && + !url.startsWith('chrome://') + ) + messages.push(msg); + }); + await use(page); + expect(messages).toEqual([]); } }); diff --git a/src/frontend/tests/modals.spec.ts b/src/frontend/tests/modals.spec.ts index 4d628eaf1f..a6cfc0c020 100644 --- a/src/frontend/tests/modals.spec.ts +++ b/src/frontend/tests/modals.spec.ts @@ -4,11 +4,6 @@ import { doQuickLogin } from './login.js'; test('PUI - Modals as admin', async ({ page }) => { await doQuickLogin(page, 'admin', 'inventree'); - // Fail on console error - await page.on('console', (msg) => { - if (msg.type() === 'error') test.fail(); - }); - // use server info await page.getByRole('button', { name: 'Open spotlight' }).click(); await page diff --git a/src/frontend/tests/pages/pui_part.spec.ts b/src/frontend/tests/pages/pui_part.spec.ts index 4d4aecf4b7..f0e21f108e 100644 --- a/src/frontend/tests/pages/pui_part.spec.ts +++ b/src/frontend/tests/pages/pui_part.spec.ts @@ -1,5 +1,4 @@ -import { test } from '@playwright/test'; - +import { test } from '../baseFixtures'; import { baseUrl } from '../defaults'; import { doQuickLogin } from '../login';