-
-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathSignUp.test.tsx
71 lines (64 loc) · 2.31 KB
/
SignUp.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import { ipcRenderer } from 'electron';
import SignUp from '../../app/components/SignUp';
import DashboardContextProvider from '../../app/context/DashboardContext';
import { HashRouter as Router } from 'react-router-dom';
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
describe('Create Admin Page', () => {
beforeEach(() => {
render(
<Router>
<DashboardContextProvider>
<SignUp />
</DashboardContextProvider>
</Router>
);
});
it('should render', () => {
expect(screen).toBeTruthy();
});
it('Should contain an h1, h2, form, two buttons, and three inputs', () => {
const element = screen.getByTestId('SignUp');
expect(element.querySelectorAll('h1').length).toBe(1);
expect(element.querySelectorAll('h2').length).toBe(1);
expect(element.querySelectorAll('form').length).toBe(1);
expect(element.querySelectorAll('button').length).toBe(2);
expect(element.querySelectorAll('input').length).toBe(4);
});
it('Sign up button should submit email, username, and password to addUser', () => {
const element = screen.getByTestId('SignUp');
const inputs = element.querySelectorAll('input');
inputs[0].value = 'me';
inputs[1].value = '[email protected]';
inputs[2].value = 'me123';
fireEvent.click(element);
expect(ipcRenderer.sendSync).toHaveBeenCalledTimes(1);
// expect(ipcRenderer.sendSync).toHaveBeenCalledWith('addUser', {
// username: 'me',
// email: '[email protected]',
// password: 'me123',
// });
});
});
// describe('handle submit function', () => {
// beforeEach(() => {
// render(
// <Router>
// <DashboardContextProvider>
// <SignUp />
// </DashboardContextProvider>
// </Router>
// );
// });
// it('should show error message when passwords don\'t match', () => {
// const element = screen.getByTestId('SignUp');
// const inputs = element.querySelectorAll('input');
// inputs[0].value = 'me';
// inputs[1].value = '[email protected]';
// inputs[2].value = 'me123';
// inputs[3].value = 'me1234';
// fireEvent.submit(element);
// expect(screen.getByText('Entered passwords do not match')).toBeInTheDocument();
// })
// })