Skip to content

Commit 0c13921

Browse files
committed
Created signIn RTL Tests
1 parent 6278e21 commit 0c13921

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

__tests__/BottomTabs.test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,4 @@ describe('invalid input test', () => {
105105
).toHaveLength(2);
106106
});
107107
});
108-
109-
//test for edge cases
110-
//trigger an event for each input
111-
//value being empty string
112-
//grab error message
113-
//check if it matches what is expected
114108
});

__tests__/signIn.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import SignIn from '../app/src/components/login/SignIn';
2+
import React from 'react';
3+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
4+
import { Provider } from 'react-redux';
5+
import store from '../app/src/redux/store';
6+
import { BrowserRouter } from 'react-router-dom';
7+
import '@testing-library/jest-dom';
8+
9+
function TestSignIn() {
10+
return (
11+
<Provider store={store}>
12+
<BrowserRouter>
13+
<SignIn />
14+
</BrowserRouter>
15+
</Provider>
16+
);
17+
}
18+
19+
describe('sign in page', () => {
20+
test('should render a login input', () => {
21+
render(<TestSignIn />);
22+
expect(screen.getByTestId('username-input')).toBeInTheDocument();
23+
});
24+
test('should render a password field', () => {
25+
render(<TestSignIn />);
26+
expect(screen.getByTestId('password-input')).toBeInTheDocument();
27+
});
28+
test('should render 4 login buttons and dark mode button', () => {
29+
render(<TestSignIn />);
30+
expect(screen.getAllByRole('button')).toHaveLength(5);
31+
});
32+
test('should invalidate empty username field', () => {
33+
render(<TestSignIn />);
34+
fireEvent.click(screen.getAllByRole('button')[1]);
35+
waitFor(() => {
36+
expect(screen.getByText('No Username Input')).toBeInTheDocument();
37+
});
38+
});
39+
test('should invalidate empty password field', () => {
40+
render(<TestSignIn />);
41+
console.log(screen.getAllByRole('textbox'));
42+
fireEvent.change(screen.getByRole('textbox'), {
43+
target: {
44+
value: 'username'
45+
}
46+
});
47+
fireEvent.click(screen.getAllByRole('button')[1]);
48+
waitFor(() => {
49+
expect(screen.getByText('No Password Input')).toBeInTheDocument();
50+
});
51+
});
52+
});

__tests__/userAuth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('User authentication tests', () => {
2929
});
3030
});
3131

32-
describe('POST', () => {
32+
xdescribe('POST', () => {
3333
it('responds with status 200 and json object on valid new user signup', () => {
3434
return request(app)
3535
.post('/signup')

app/src/components/login/SignIn.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
8080
const [username, setUsername] = useState('');
8181
const [password, setPassword] = useState('');
8282

83-
const isDarkMode = useSelector((store:RootState) => store.darkMode.isDarkMode);
83+
const isDarkMode = useSelector(
84+
(store: RootState) => store.darkMode.isDarkMode
85+
);
8486

8587
const [invalidUserMsg, setInvalidUserMsg] = useState('');
8688
const [invalidPassMsg, setInvalidPassMsg] = useState('');
@@ -250,6 +252,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
250252
onChange={handleChange}
251253
helperText={invalidUserMsg}
252254
error={invalidUser}
255+
data-testid="username-input"
253256
/>
254257
<TextField
255258
className={classes.root}
@@ -266,6 +269,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
266269
onChange={handleChange}
267270
helperText={invalidPassMsg}
268271
error={invalidPass}
272+
data-testid="password-input"
269273
/>
270274

271275
<Button

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"dist-linux": "electron-builder --linux",
7878
"dist-windows": "electron-builder --windows",
7979
"dist-all": "npm run prod-build && electron-builder --mac --linux --windows",
80-
"test": "NODE_ENV=test jest --verbose --detectOpenHandles --forceExit",
80+
"test": "NODE_ENV=test jest --verbose",
8181
"server": "cross-env NODE_ENV=development nodemon server/server.ts",
8282
"start": "node server/server.ts"
8383
},

0 commit comments

Comments
 (0)