From d2426c6c6298e7c6f3d39ad57c0e315906ebbc02 Mon Sep 17 00:00:00 2001 From: grinikita Date: Sat, 21 Nov 2026 11:42:16 +0300 Subject: [PATCH] error boundary + disable keycloak --- package-lock.json | 28 ++++++++++++++++------------ package.json | 1 + src/__tests__/index.test.ts | 5 +++++ src/__tests__/mocks/brojs-cli.ts | 4 ++-- src/components/heading/index.tsx | 1 + src/container/list/index.tsx | 10 ++++++++++ src/container/main/index.tsx | 3 ++- src/container/main/router.tsx | 11 +++++++++-- stubs/api/index.js | 2 +- stubs/api/list/index.js | 3 ++- 10 files changed, 49 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 136a092..700479b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "keycloak-js": "^26.0.7", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-error-boundary": "^6.1.6", "react-redux": "^9.2.0", "react-router-dom": "^6.28.0" }, @@ -27,7 +28,6 @@ "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.1.0", - "@types/jest": "^29.5.14", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "@types/webpack-env": "^1.18.5", @@ -3787,17 +3787,6 @@ "@types/istanbul-lib-report": "*" } }, - "node_modules/@types/jest": { - "version": "29.5.14", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", - "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "expect": "^29.0.0", - "pretty-format": "^29.0.0" - } - }, "node_modules/@types/jsdom": { "version": "20.0.1", "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz", @@ -12857,6 +12846,21 @@ "react": "^18.3.1" } }, + "node_modules/react-error-boundary": { + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-6.1.6.tgz", + "integrity": "sha512-CDXPnXDGyFIbkwaaJ6u+xgsRmJhSi6YdgUDW1vnyKHfXp1a9pfAlM+ZET2CDu80/A+8iRcmXN0NSY9BCCoWP5A==", + "license": "MIT", + "peerDependencies": { + "@types/react": "^18.0.0 || ^19.0.0", + "react": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/react-error-overlay": { "version": "6.0.11", "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz", diff --git a/package.json b/package.json index 3d59ecd..da23021 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "keycloak-js": "^26.0.7", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-error-boundary": "^6.1.6", "react-redux": "^9.2.0", "react-router-dom": "^6.28.0" }, diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 3a94083..d7ce043 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -3,8 +3,13 @@ import { describe, test, expect } from '@jest/globals'; describe('Тесты на функцию sum', () => { test('1 + 2 = 3', () => { + // Подготовка к тесту. Моки + + const result = sum(1, 2); expect(result).toBe(3); + + // Очистка моков, состояния }); }); diff --git a/src/__tests__/mocks/brojs-cli.ts b/src/__tests__/mocks/brojs-cli.ts index ff7078b..c563466 100644 --- a/src/__tests__/mocks/brojs-cli.ts +++ b/src/__tests__/mocks/brojs-cli.ts @@ -18,8 +18,8 @@ jest.mock('@brojs/cli', () => { return { ...originalBroJsCli, - getConfigValue: () => { + getConfigValue: jest.fn(() => { return 'mocked_value'; - } + }) }; }); diff --git a/src/components/heading/index.tsx b/src/components/heading/index.tsx index b4afbd0..2c87114 100644 --- a/src/components/heading/index.tsx +++ b/src/components/heading/index.tsx @@ -3,6 +3,7 @@ import { HeadingStyled } from './index.style'; import { HeadingProps, HeadingVariant } from './types'; const Heading = ({ children, variant = HeadingVariant.h1, className }: HeadingProps) => { + return ( {children} diff --git a/src/container/list/index.tsx b/src/container/list/index.tsx index f00d247..285eaa3 100644 --- a/src/container/list/index.tsx +++ b/src/container/list/index.tsx @@ -2,9 +2,19 @@ import React from 'react'; import Heading from '../../components/heading'; import { useGetListQuery } from '../../store/api'; +let render = 0; + const ListPage = (): React.ReactElement => { const { data, isLoading, error } = useGetListQuery(undefined); + if (!render) + throw new Promise((res) => + setTimeout(() => { + render++; + res(

Hello from promise

); + }, 4000) + ); + return ( <> List Page New diff --git a/src/container/main/index.tsx b/src/container/main/index.tsx index fd8729a..9b6fea3 100644 --- a/src/container/main/index.tsx +++ b/src/container/main/index.tsx @@ -8,7 +8,8 @@ import { useKeycloak } from './keycloak'; const store = setupStore(); const Main = (): React.ReactElement | string => { - const { isLoading } = useKeycloak(); + // const { isLoading } = useKeycloak(); + const { isLoading } = { isLoading: false }; if (isLoading) { return 'Loading...'; diff --git a/src/container/main/router.tsx b/src/container/main/router.tsx index 87dbc63..33d0819 100644 --- a/src/container/main/router.tsx +++ b/src/container/main/router.tsx @@ -1,9 +1,10 @@ -import React from 'react'; +import React, { Suspense } from 'react'; import { createBrowserRouter } from 'react-router-dom'; import ListPage from '../list'; import DetailPage from '../detail'; import { getNavigationValue } from '@brojs/cli'; import Layout from './components/layout'; +import { ErrorBoundary } from 'react-error-boundary'; export const router = createBrowserRouter([ { @@ -12,7 +13,13 @@ export const router = createBrowserRouter([ children: [ { path: getNavigationValue('kfu-24-teacher.main'), - element: + element: ( + List page Error

}> + List page Loading

}> + +
+
+ ) }, { path: getNavigationValue('kfu-24-teacher.detail'), diff --git a/stubs/api/index.js b/stubs/api/index.js index c37fddc..7472129 100644 --- a/stubs/api/index.js +++ b/stubs/api/index.js @@ -9,6 +9,6 @@ const delay = setTimeout(next, ms); }; -router.use(keycloak.middleware()); +// router.use(keycloak.middleware()); router.use(delay()); router.use('/list', listRouter); diff --git a/stubs/api/list/index.js b/stubs/api/list/index.js index 090b027..e5960a0 100644 --- a/stubs/api/list/index.js +++ b/stubs/api/list/index.js @@ -5,7 +5,8 @@ module.exports = router; const data = require('./data/list.json'); const keycloak = require('../keycloak'); -router.get('/', keycloak.protect(), (req, res) => { +// router.get('/', keycloak.protect(), (req, res) => { +router.get('/', (req, res) => { res.send(data); // res.status(500).send({ // message: 'Internal server error'