Skip to content

Commit

Permalink
feat: change sidebar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Nov 4, 2023
1 parent 9cd21d1 commit ebf03dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion config/build/buildLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function buildLoaders({ isDev }: BuildOptions): webpack.RuleSetRule[] {
return [
fileLoader,
svgLoader,
babelLoader,
// babelLoader,
typescriptLoader,
cssLoader,
];
Expand Down
1 change: 1 addition & 0 deletions extractedTranslations/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"throw error": "throw error",
"Главная": "",
"Главная страница": "",
"О сайте": "",
Expand Down
22 changes: 22 additions & 0 deletions src/shared/lib/tests/componentRender/componentRender.tsx
Original file line number Diff line number Diff line change
@@ -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(
<MemoryRouter initialEntries={[route]}>
<I18nextProvider i18n={i18nForTests}>
{component}
</I18nextProvider>
</MemoryRouter>,
);
}
8 changes: 3 additions & 5 deletions src/widgets/Sidebar/ui/Sidebar/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<Sidebar />);
componentRender(<Sidebar />);
expect(screen.getByTestId('sidebar')).toBeInTheDocument();
});

test('test toggle', () => {
renderWithTranslation(<Sidebar />);
componentRender(<Sidebar />);
const toggleBtn = screen.getByTestId('sidebar-toggle');
expect(screen.getByTestId('sidebar')).toBeInTheDocument();
fireEvent.click(toggleBtn);
Expand Down

0 comments on commit ebf03dc

Please sign in to comment.