-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathCreateAdmin.test.tsx
50 lines (42 loc) · 1.8 KB
/
CreateAdmin.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
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import { ipcRenderer } from 'electron';
import CreateAdmin from '../../app/components/CreateAdmin';
import DashboardContextProvider from '../../app/context/DashboardContext';
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
describe('Create Admin Page', () => {
beforeEach(() => {
console.error = jest.fn();
render(
<DashboardContextProvider>
<CreateAdmin />
</DashboardContextProvider>
);
});
it('Should render', () => {
expect(screen).toBeTruthy();
});
it('Should contain an h1, h2, form, button, and three inputs', () => {
const element = screen.getByTestId('CreateAdmin');
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(1);
expect(element.querySelectorAll('input').length).toBe(3);
});
it('Create Account button should submit email, username, and password to addUser', () => {
const username = screen.getByPlaceholderText('enter username');
const email = screen.getByPlaceholderText('[email protected]');
const password = screen.getByPlaceholderText('enter password');
const createAccountButton = screen.getByRole('button', { name: /create account/i });
fireEvent.change(email, { target: { value: '[email protected]' } });
fireEvent.change(username, { target: { value: 'me' } });
fireEvent.change(password, { target: { value: 'me123' } });
fireEvent.click(createAccountButton);
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('addUser', {
email: '[email protected]',
username: 'me',
password: 'me123',
});
});
});