Skip to content

Commit dbfb74e

Browse files
Justinlkirkastholdenwilliamowen65jessllee
committed
Finished testings suites on several components
Co-authored-by: Alexander Holden <[email protected]> Co-authored-by: William Owen <[email protected]> Co-authored-by: Jessica Lee <[email protected]>
1 parent 07d447e commit dbfb74e

13 files changed

+346
-31
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import About from '../../app/components/About';
4+
import DashboardContextProvider from '../../app/context/DashboardContext';
5+
6+
describe('About Page', () => {
7+
let element;
8+
beforeAll(() => {
9+
render(
10+
<DashboardContextProvider>
11+
<About />
12+
</DashboardContextProvider>
13+
);
14+
element = screen.getByTestId('aboutPage');
15+
});
16+
17+
it('Should have three p tags', () => {
18+
expect(element.querySelectorAll('p').length).toBe(3);
19+
});
20+
21+
it('Should have three h3 tags', () => {
22+
expect(element.querySelectorAll('h3').length).toBe(3);
23+
});
24+
25+
it('Should have one div', () => {
26+
expect(element.querySelectorAll('div').length).toBe(1);
27+
});
28+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// import React, { useContext } from 'react';
2+
import React from 'react';
3+
import { render, fireEvent, screen, cleanup } from '@testing-library/react';
4+
import { ipcRenderer, ipcMain } from 'electron';
5+
import DashboardContextProvider, { DashboardContext } from '../../app/context/DashboardContext';
6+
import Applications from '../../app/components/Applications';
7+
8+
jest.mock('electron', () => ({
9+
ipcRenderer: { sendSync: () => [] },
10+
ipcMain: { on: jest.fn() },
11+
}));
12+
13+
describe('Application', () => {
14+
// beforeEach(() => {
15+
// let comp = render(<Applications />);
16+
// });
17+
18+
it('should render', () => {
19+
const component = render(
20+
<DashboardContextProvider>
21+
<Applications />
22+
</DashboardContextProvider>
23+
);
24+
console.log(component);
25+
expect(component).toBeTruthy();
26+
});
27+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from 'react';
2+
import { renderHook } from '@testing-library/react-hooks';
3+
import { render, fireEvent, screen, cleanup } from '@testing-library/react';
4+
5+
import AwaitingApproval from '../../app/components/AwaitingApproval';
6+
7+
import '@testing-library/jest-dom';
8+
9+
describe('Awaiting Approval Page', () => {
10+
const { result } = renderHook(() => AwaitingApproval());
11+
12+
it('blah', () => {
13+
expect(result.current).toBe('function');
14+
});
15+
16+
it('Should have awaiting approval message', () => {
17+
// screen.logTestingPlaygroundURL();
18+
const element = result.current;
19+
expect(element).toMatchInlineSnapshot(`
20+
<p
21+
class="welcomeMessage"
22+
data-testid="awaitingApprovalMessage"
23+
>
24+
Your account is awaiting approval. Please contact your administrator if you have any questions.
25+
</p>
26+
`);
27+
});
28+
});
29+
// describe('Awaiting Approval Page', () => {
30+
// beforeEach(() => {
31+
// render(<AwaitingApproval />);
32+
// });
33+
34+
// xit('Should have awaiting approval message', () => {
35+
// const element = screen.getByTestId('awaitingApprovalMessage');
36+
// expect(element).toMatchInlineSnapshot(`
37+
// <p
38+
// class="welcomeMessage"
39+
// data-testid="awaitingApprovalMessage"
40+
// >
41+
// Your account is awaiting approval. Please contact your administrator if you have any questions.
42+
// </p>
43+
// `);
44+
// });
45+
46+
// xit('Should have return button', () => {
47+
// const returnBtn = screen.getByRole('button');
48+
// expect(returnBtn).toHaveTextContent('Return');
49+
// });
50+
51+
// it('Should perform re-route on button click', () => {
52+
// const returnBtn = screen.getByRole('button');
53+
// fireEvent.click(returnBtn);
54+
// screen.logTestingPlaygroundURL();
55+
// // expect(mockCall).toHaveBeenCalledTimes(1);
56+
// });
57+
// });
58+
59+
60+
/* render(<AwaitingApproval onClick={mockCall() />})
61+
62+
63+
64+
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import Contact from '../../app/components/Contact';
4+
import DashboardContextProvider from '../../app/context/DashboardContext';
5+
6+
describe('Contact Page', () => {
7+
let element;
8+
beforeAll(() => {
9+
render(
10+
<DashboardContextProvider>
11+
<Contact />
12+
</DashboardContextProvider>
13+
);
14+
element = screen.getByTestId('contactPage');
15+
});
16+
17+
it('Should have two p tags', () => {
18+
expect(element.querySelectorAll('p').length).toBe(2);
19+
});
20+
21+
it('Should have a form', () => {
22+
expect(element.querySelectorAll('form').length).toBe(1);
23+
});
24+
25+
it('Should have six labels', () => {
26+
expect(element.querySelectorAll('label').length).toBe(6);
27+
});
28+
29+
it('Should have one h1 tags', () => {
30+
expect(element.querySelectorAll('h1').length).toBe(1);
31+
});
32+
33+
it('Should have three divs', () => {
34+
expect(element.querySelectorAll('div').length).toBe(3);
35+
});
36+
37+
it('Should have have two inputs', () => {
38+
expect(element.querySelectorAll('input').length).toBe(6);
39+
});
40+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import CreateAdmin from '../../app/components/CreateAdmin';
4+
import DashboardContextProvider from '../../app/context/DashboardContext';
5+
6+
describe('Create Admin Page', () => {
7+
let element;
8+
beforeAll(() => {
9+
render(
10+
<DashboardContextProvider>
11+
<CreateAdmin />
12+
</DashboardContextProvider>
13+
);
14+
element = screen.getByTestId('createAdmin');
15+
});
16+
});

__tests__2022/components/FirstLaunch.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { ipcRenderer } = require('electron');
66

77
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
88

9-
describe('FirstLaunch Page', () => {
9+
xdescribe('FirstLaunch Page', () => {
1010
const TestComponent = ({ onClick }) => {
1111
const { updateLandingPage } = useContext(DashboardContext);
1212
return (
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { render, fireEvent, screen } from '@testing-library/react';
3+
import AwaitingApproval from '../../app/components/AwaitingApproval';
4+
import '@testing-library/jest-dom';
5+
6+
jest.mock('react-router', () => ({
7+
// ...jest.requireActual('react-router-dom') as typeof ReactRouterDom,
8+
useHistory: () => ({ push: jest.fn() }), // ({ push: jest.fn() })
9+
}));
10+
11+
describe('Awaiting Approval Page', () => {
12+
beforeEach(() => {
13+
render(<AwaitingApproval />);
14+
});
15+
16+
it('Should have awaiting approval message', () => {
17+
const element = screen.getByTestId('awaitingApprovalMessage');
18+
expect(element).toMatchInlineSnapshot(`
19+
<p
20+
class="welcomeMessage"
21+
data-testid="awaitingApprovalMessage"
22+
>
23+
Your account is awaiting approval. Please contact your administrator if you have any questions.
24+
</p>
25+
`);
26+
});
27+
28+
it('Should have return button', () => {
29+
const returnBtn = screen.getByRole('button');
30+
expect(returnBtn).toHaveTextContent('Return');
31+
});
32+
33+
it('Should perform re-route on button click', () => {
34+
const returnBtn = screen.getByRole('button');
35+
expect(fireEvent.click(returnBtn)).toBeTruthy();
36+
expect(typeof returnBtn.onclick).toBe('function');
37+
});
38+
});

app/components/About.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const About: React.FC = React.memo(() => {
1212

1313
return (
1414
<div className="about">
15-
<div className="blurb">
15+
<div className="blurb" data-testid="aboutPage">
1616
<h3 style={currentMode} className="mainTitle">
1717
About
1818
</h3>

app/components/AwaitingApproval.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import React from 'react';
22
import { useHistory } from 'react-router-dom';
33

4-
const AwaitingApproval = React.memo(() => {
4+
function AwaitingApproval() {
55
const history = useHistory();
6+
const reroute = () => history.push('/');
67
return (
78
<div className="home">
8-
<p className="welcomeMessage">
9+
<p className="welcomeMessage" data-testid="awaitingApprovalMessage">
910
Your account is awaiting approval. Please contact your administrator if you have any
1011
questions.
1112
</p>
1213
<br />
13-
<button className="link" onClick={() => history.push('/')}>
14+
<button className="link" onClick={reroute}>
1415
Return
1516
</button>
1617
</div>
1718
);
18-
});
19+
}
1920

2021
export default AwaitingApproval;

app/components/Contact.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Contact = React.memo(() => {
1212

1313
return (
1414
<div className="contact">
15-
<div className="contact-border">
15+
<div className="contact-border" data-testid="contactPage">
1616
<div className="contact-container">
1717
<div className="contact-blurb">
1818
<h1 style={currentMode}>Contact Us</h1>

0 commit comments

Comments
 (0)