Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD - Pipeline test #30

Merged
merged 13 commits into from
Dec 21, 2023
Merged
35 changes: 35 additions & 0 deletions .github/workflows/frontendWorkflowTests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run Unit Tests for frontend

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
jobs:
test-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node.js Environment
uses: actions/checkout@v3
with:
node-version: '18.16.x'
- name: Install dependencies
run: |
cd ./frontend
npm ci
- name: Run Frontend Unit Tests
run: |
cd ./frontend
npm run test
- name: Run Linter
run: |
cd ./frontend
npm run lint
- name: Build project
run: |
cd ./frontend
npm run build
17 changes: 5 additions & 12 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@hookform/resolvers": "^3.3.1",
"@react-icons/all-files": "^4.1.0",
"@reduxjs/toolkit": "^1.9.7",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.5",
Expand All @@ -25,7 +25,6 @@
"fetch": "^1.1.0",
"framer-motion": "^10.16.4",
"husky": "^8.0.3",
"jest-dom": "^4.0.0",
"jsdom": "^22.1.0",
"prettier-plugin-organize-attributes": "^1.0.0",
"react": "^18.2.0",
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/components/LoginForm/LoginForm.test.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions frontend/src/components/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { TSignInSchema, signInSchema } from '@components/LoginForm/LoginForm.typ

import styles from './LoginForm.module.scss';

// TODO: Write tests for this form

export function LoginForm() {
const {
register,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export function Navigation() {
} else {
toggleNav(true);
}
}, [showNav, location, isAuthenticated]);
}, [showNav, location, isAuthenticated, toggleNav]);
return <>{showNav && <NavigationSidebar />}</>;
}
13 changes: 5 additions & 8 deletions frontend/src/hooks/useToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { useCallback, useState } from 'react';
export const useToggle = (defaultValue: boolean) => {
const [value, setValue] = useState(defaultValue);

const toggleFlag = useCallback(
(userValue?: unknown) => {
setValue((currentValue) => {
return typeof userValue === 'boolean' ? userValue : !currentValue;
});
},
[value]
);
const toggleFlag = useCallback((userValue?: unknown) => {
setValue((currentValue) => {
return typeof userValue === 'boolean' ? userValue : !currentValue;
});
}, []);
return { value, toggleFlag };
};
2 changes: 1 addition & 1 deletion frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as matchers from '@testing-library/jest-dom/matchers';
import { expect } from 'vitest';
import * as matchers from '@testing-library/jest-dom/matchers';
import '@testing-library/jest-dom';

expect.extend(matchers);
7 changes: 4 additions & 3 deletions frontend/src/views/Login/Login.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { screen, fireEvent } from '@testing-library/react';
import { screen, fireEvent, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -54,7 +54,8 @@ describe('Test for Login panel', () => {
userEvent.type(password, CORRECT_USER.password);
fireEvent.click(submit);

// expect(await screen.findByText('Hasło jest wymagane')).toBeFalsy();
expect(await screen.findByRole('heading', { level: 1 })).toHaveTextContent(`Witaj ${CORRECT_USER.name}`);
await waitFor(() => {
expect(window.location.pathname).toBe('/');
});
});
});
Loading