From ebf03dcd0e9603d5e46beea4293ae56b6da4dd9a Mon Sep 17 00:00:00 2001 From: "Leon.kov" Date: Sat, 4 Nov 2023 18:30:37 +0300 Subject: [PATCH] feat: change sidebar tests --- .github/workflows/main.yml | 13 +++++++++++ config/build/buildLoaders.ts | 2 +- extractedTranslations/en/translation.json | 1 + .../tests/componentRender/componentRender.tsx | 22 +++++++++++++++++++ .../Sidebar/ui/Sidebar/Sidebar.test.tsx | 8 +++---- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/shared/lib/tests/componentRender/componentRender.tsx diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5f3841..b027519 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,19 +17,32 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + - name: install modules run: npm install + - name: build production project + if: always() run: npm run build:prod + - name: linting typescript + if: always() run: npm run lint:ts + - name: linting css + if: always() run: npm run lint:scss + - name: unit testing + if: always() run: npm run test:unit + - name: build storybook + if: always() run: npm run storybook:build + - name: screenshot testing + if: always() run: npm run test:ui:ci diff --git a/config/build/buildLoaders.ts b/config/build/buildLoaders.ts index 8c6ef79..4b920b6 100644 --- a/config/build/buildLoaders.ts +++ b/config/build/buildLoaders.ts @@ -49,7 +49,7 @@ export function buildLoaders({ isDev }: BuildOptions): webpack.RuleSetRule[] { return [ fileLoader, svgLoader, - babelLoader, + // babelLoader, typescriptLoader, cssLoader, ]; diff --git a/extractedTranslations/en/translation.json b/extractedTranslations/en/translation.json index 097ae16..ab8ef30 100644 --- a/extractedTranslations/en/translation.json +++ b/extractedTranslations/en/translation.json @@ -1,4 +1,5 @@ { + "throw error": "throw error", "Главная": "", "Главная страница": "", "О сайте": "", diff --git a/src/shared/lib/tests/componentRender/componentRender.tsx b/src/shared/lib/tests/componentRender/componentRender.tsx new file mode 100644 index 0000000..94f2c70 --- /dev/null +++ b/src/shared/lib/tests/componentRender/componentRender.tsx @@ -0,0 +1,22 @@ +import { ReactNode } from 'react'; +import { render } from '@testing-library/react'; +import i18nForTests from 'shared/config/i18n/i18nForTests'; +import { I18nextProvider } from 'react-i18next'; +import { MemoryRouter } from 'react-router-dom'; + +export interface componentRenderOptions { + route?: string; +} + +export function componentRender(component: ReactNode, options: componentRenderOptions = {}) { + const { + route = '/', + } = options; + return render( + + + {component} + + , + ); +} diff --git a/src/widgets/Sidebar/ui/Sidebar/Sidebar.test.tsx b/src/widgets/Sidebar/ui/Sidebar/Sidebar.test.tsx index 7349b32..c9bad5b 100644 --- a/src/widgets/Sidebar/ui/Sidebar/Sidebar.test.tsx +++ b/src/widgets/Sidebar/ui/Sidebar/Sidebar.test.tsx @@ -1,17 +1,15 @@ import { fireEvent, screen } from '@testing-library/react'; import { Sidebar } from 'widgets/Sidebar/ui/Sidebar/Sidebar'; -import { - renderWithTranslation, -} from 'shared/lib/tests/renderWithTranslation/renderWithTranslation'; +import { componentRender } from 'shared/lib/tests/componentRender/componentRender'; describe('Sidebar', () => { test('with only first param', () => { - renderWithTranslation(); + componentRender(); expect(screen.getByTestId('sidebar')).toBeInTheDocument(); }); test('test toggle', () => { - renderWithTranslation(); + componentRender(); const toggleBtn = screen.getByTestId('sidebar-toggle'); expect(screen.getByTestId('sidebar')).toBeInTheDocument(); fireEvent.click(toggleBtn);