From 655c95837ca658062fc85cac1bda2f8c3c3c05a4 Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:28:38 +0200 Subject: [PATCH] apply suggestions from codereview --- src/frontend/src/components/plugins/PluginContext.tsx | 2 +- src/frontend/tests/login.ts | 6 ++++++ src/frontend/tests/pui_printing.spec.ts | 9 +++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/components/plugins/PluginContext.tsx b/src/frontend/src/components/plugins/PluginContext.tsx index ea57e65ef6..992d32a1a1 100644 --- a/src/frontend/src/components/plugins/PluginContext.tsx +++ b/src/frontend/src/components/plugins/PluginContext.tsx @@ -41,7 +41,7 @@ export type InvenTreeContext = { }; export const useInvenTreeContext = () => { - const host = useLocalState.getState().host; + const host = useLocalState((s) => s.host); const navigate = useNavigate(); const user = useUserState(); const { colorScheme } = useMantineColorScheme(); diff --git a/src/frontend/tests/login.ts b/src/frontend/tests/login.ts index 5529e24d8c..b438e90819 100644 --- a/src/frontend/tests/login.ts +++ b/src/frontend/tests/login.ts @@ -42,3 +42,9 @@ export const doLogout = async (page) => { await page.goto(`${baseUrl}/logout/`); await page.waitForURL('**/platform/login'); }; + +export const createBasicAuthHeader = (username: string, password: string) => { + return { + Authorization: `Basic ${btoa(`${username}:${password}`)}` + }; +}; diff --git a/src/frontend/tests/pui_printing.spec.ts b/src/frontend/tests/pui_printing.spec.ts index a5de690f8a..b73ee2abb1 100644 --- a/src/frontend/tests/pui_printing.spec.ts +++ b/src/frontend/tests/pui_printing.spec.ts @@ -1,6 +1,6 @@ import { expect, test } from './baseFixtures.js'; import { baseUrl, classicUrl } from './defaults.js'; -import { doQuickLogin } from './login.js'; +import { createBasicAuthHeader, doQuickLogin } from './login.js'; /* * Test for label printing. @@ -82,13 +82,14 @@ test('PUI - Report Printing', async ({ page }) => { }); test('PUI - Report Editing', async ({ page }) => { - await doQuickLogin(page, 'admin', 'inventree'); + const [username, password] = ['admin', 'inventree']; + await doQuickLogin(page, username, password); // activate the sample plugin for this test await page.request.patch(`${classicUrl}/api/plugins/sampleui/activate/`, { headers: { 'Content-Type': 'application/json', - Authorization: `Basic YWRtaW46aW52ZW50cmVl` + ...createBasicAuthHeader(username, password) }, data: { active: true } }); @@ -145,7 +146,7 @@ test('PUI - Report Editing', async ({ page }) => { await page.request.patch(`${classicUrl}/api/plugins/sampleui/activate/`, { headers: { 'Content-Type': 'application/json', - Authorization: `Basic YWRtaW46aW52ZW50cmVl` + ...createBasicAuthHeader(username, password) }, data: { active: false } });