Skip to content

Commit 0caaa35

Browse files
authored
Merge pull request #14 from jerseysu/unit-test-onboard
test(__tests__): onboarding the unit test
2 parents 4f2f7f0 + ff69af4 commit 0caaa35

File tree

7 files changed

+75
-93
lines changed

7 files changed

+75
-93
lines changed

.github/workflows/playwright.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ jobs:
1818
run: npm ci
1919
- name: Lint
2020
run: npm run lint
21+
- name: Run Unit Test
22+
run: npm run test:ci
2123
- name: Install Playwright Browsers
2224
run: npx playwright install --with-deps
2325
- name: Run Playwright tests
24-
run: npx playwright test
26+
run: npm run test:e2e
2527
- uses: actions/upload-artifact@v4
2628
if: always()
2729
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ build/
1212
/playwright-report/
1313
/blob-report/
1414
/playwright/.cache/
15+
coverage/

package-lock.json

Lines changed: 20 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"@mui/icons-material": "^5.16.0",
1010
"@mui/material": "^5.16.0",
1111
"@testing-library/jest-dom": "^5.17.0",
12-
"@testing-library/react": "^13.4.0",
1312
"@testing-library/user-event": "^13.5.0",
1413
"@types/jest": "^27.5.2",
1514
"@types/node": "^20.14.10",
@@ -27,7 +26,8 @@
2726
"deploy": "gh-pages -d build",
2827
"start": "react-scripts start",
2928
"build": "react-scripts build",
30-
"test": "react-scripts test",
29+
"test": "react-scripts test --coverage",
30+
"test:ci": "CI=true react-scripts test --no-watchAll --coverage",
3131
"test:e2e": "npx playwright test",
3232
"lint": "npx eslint .",
3333
"eject": "react-scripts eject"
@@ -52,6 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"@playwright/test": "^1.45.1",
55+
"@testing-library/react": "^16.0.0",
5556
"gh-pages": "^6.1.1",
5657
"typescript-eslint": "^7.16.0"
5758
}

src/__tests__/login.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom'
4+
import Login from '../pages/Login';
5+
import { BrowserRouter } from 'react-router-dom'
6+
7+
it('renders login page', () => {
8+
render(<Login />, { wrapper: BrowserRouter });
9+
10+
const emailInputBox = screen.getByTestId('email');
11+
const passwordInputBox = screen.getByTestId('password');
12+
13+
expect(screen.getByText(/Register/i)).toBeInTheDocument();
14+
expect(emailInputBox).toBeInTheDocument();
15+
expect(passwordInputBox).toBeInTheDocument();
16+
});
17+

src/__tests__/loginSuccess.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom'
4+
import LoginSuccess from '../pages/LoginSuccess';
5+
import { BrowserRouter } from 'react-router-dom'
6+
7+
it('renders welcome message', () => {
8+
render(<LoginSuccess />, { wrapper: BrowserRouter });
9+
expect(screen.getByText(/LoginSuccess/i)).toBeInTheDocument();
10+
expect(screen.getByAltText(/Jersey/i)).toBeInTheDocument();
11+
expect(screen.getByRole('img')).toBeInTheDocument();
12+
});
13+

src/__tests__/register.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom'
4+
import Register from '../pages/Register';
5+
import { BrowserRouter } from 'react-router-dom'
6+
7+
it('renders register page', () => {
8+
render(<Register />, { wrapper: BrowserRouter });
9+
10+
const emailInputBox = screen.getByTestId('email');
11+
const passwordInputBox = screen.getByTestId('password');
12+
const userInputBox = screen.getByTestId('name');
13+
expect(screen.getByText(/Login/i)).toBeInTheDocument();
14+
expect(emailInputBox).toBeInTheDocument();
15+
expect(passwordInputBox).toBeInTheDocument();
16+
expect(userInputBox).toBeInTheDocument();
17+
});
18+

0 commit comments

Comments
 (0)