Skip to content

Commit 8be60dc

Browse files
committed
Added some tests
1 parent f1d12cb commit 8be60dc

9 files changed

+173
-25
lines changed

src/domain/Jump.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Jump } from './Jump';
2+
3+
describe('Jump Interface', () => {
4+
it('should instantiate a Jump Object', () => {
5+
const jump: Jump = {
6+
message: 'message',
7+
jump_path: '/jump_path',
8+
last_path: '/last_path',
9+
jumps: ['jump1']
10+
};
11+
12+
expect(jump).toBeTruthy();
13+
});
14+
});

src/domain/JumpLog.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { JumpLog } from './JumpLog';
2+
3+
describe('Jump Log Interface', () => {
4+
it('should instantiate a Jump Log Object', () => {
5+
const jumpLog: JumpLog = {
6+
message: 'message',
7+
dateLog: '01/01/2021'
8+
};
9+
10+
expect(jumpLog).toBeTruthy();
11+
});
12+
});

src/domain/ResponseBack.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ResponseBack } from './ResponseBack';
2+
3+
describe('Response Back Interface', () => {
4+
it('should instantiate a Response Back Object', () => {
5+
const responseBack: ResponseBack = {
6+
message: 'message',
7+
code: 1234
8+
};
9+
10+
expect(responseBack).toBeTruthy();
11+
});
12+
});

src/domain/Task.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Task } from './Task';
2+
3+
describe('Task Interface', () => {
4+
it('should instantiate a Task Object', () => {
5+
const task: Task = {
6+
message: 'message',
7+
code: 1234
8+
};
9+
10+
expect(task).toBeTruthy();
11+
});
12+
});

src/infrastructure/postJump.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import axios from 'axios';
2+
import { Jump } from '../domain/Jump';
3+
import { sentJump } from './postJump';
4+
5+
jest.mock('axios');
6+
7+
describe('Infrastructure -> Test Sent Jump to Back', () => {
8+
it('should send a jump object to the backend', async () => {
9+
const url: string = 'https://acidonpe.com/jump';
10+
const data: Jump = {
11+
message: 'message',
12+
jump_path: '/jump_path',
13+
last_path: '/last_path',
14+
jumps: ['jump1']
15+
};
16+
17+
const response: any = {
18+
data: {
19+
message: 'messages',
20+
code: 1234
21+
}
22+
};
23+
24+
axios.post.mockImplementationOnce(() => Promise.resolve(response));
25+
const jumpResponse = await sentJump(url, data);
26+
27+
expect(jumpResponse).toBe(response.data);
28+
});
29+
});

src/ui/header/Header.spec.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { Header } from './Header';
3+
import { render } from '@testing-library/react';
4+
5+
describe('Test React Multi Component Header', () => {
6+
it('should have a logo component', () => {
7+
const { getByRole, getAllByRole } = render(<Header />);
8+
const logoDiv = getByRole('logo');
9+
const img = getByRole('img');
10+
const h1 = getAllByRole('heading');
11+
12+
const imgName = img.getAttribute('alt');
13+
14+
expect(logoDiv).toBeTruthy();
15+
expect(imgName).toBe('Jump Logo');
16+
expect(h1[0]).toHaveTextContent('Jump App v2.0');
17+
});
18+
});

src/ui/header/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Props {}
1010
export const Header: React.FunctionComponent<Props> = () => {
1111
return (
1212
<>
13-
<div className={cx('logo')}>
13+
<div role='logo' className={cx('logo')}>
1414
<a href='/'>
1515
<Logo size='xxl'></Logo>
1616
</a>

src/ui/home/Home.spec.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { Home } from './Home';
3+
import { screen } from '@testing-library/react';
4+
import { render } from '@testing-library/react';
5+
6+
describe('Test React Multi Component Home', () => {
7+
let container: any;
8+
9+
beforeEach(() => {
10+
container = document.createElement('div');
11+
document.body.appendChild(container);
12+
});
13+
14+
afterEach(() => {
15+
document.body.removeChild(container);
16+
container = null;
17+
});
18+
19+
it('should have a Home component', async () => {
20+
const { getByRole } = render(<Home />);
21+
22+
const titles = screen.getAllByRole('heading');
23+
const images = screen.getAllByRole('img');
24+
const roleJump = getByRole('jump');
25+
const roleJumpSel = getByRole('jumpselections');
26+
const roleJumpBox = getByRole('jumpbox');
27+
const roleJumpActs = getByRole('jumpaction');
28+
const roleJumpLogs = getByRole('jumplog');
29+
const buttons = screen.getAllByRole('button');
30+
31+
const imgNameSp = images[0].getAttribute('alt');
32+
const imgNameGo = images[1].getAttribute('alt');
33+
const imgNamePy = images[2].getAttribute('alt');
34+
const imgNameJump = images[images.length - 1].getAttribute('alt');
35+
36+
expect(titles[0]).toHaveTextContent('Add Jump:');
37+
expect(titles[1]).toHaveTextContent('Calls Retries:');
38+
expect(titles[2]).toHaveTextContent('Calls Interval:');
39+
expect(titles[3]).toHaveTextContent('Jumps');
40+
expect(imgNameSp).toBe('Springboot');
41+
expect(imgNameGo).toBe('Golang');
42+
expect(imgNamePy).toBe('Python');
43+
expect(imgNameJump).toBe('Jump!');
44+
expect(roleJump).toBeTruthy();
45+
expect(roleJumpSel).toBeTruthy();
46+
expect(roleJumpBox).toBeTruthy();
47+
expect(roleJumpActs).toBeTruthy();
48+
expect(roleJumpLogs).toBeTruthy();
49+
expect(buttons.length).toBe(4);
50+
});
51+
});

src/ui/home/Home.tsx

+24-24
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ export const Home: React.FunctionComponent<Props> = () => {
2222
id: '1',
2323
jump: appGolang,
2424
name: 'Golang',
25-
img: './golang.png',
25+
img: './golang.png'
2626
};
2727
const springboot = {
2828
id: '2',
2929
jump: appSpringboot,
3030
name: 'Springboot',
31-
img: './springboot.png',
31+
img: './springboot.png'
3232
};
3333
const python = {
3434
id: '3',
3535
jump: appPython,
3636
name: 'Python',
37-
img: './python.png',
37+
img: './python.png'
3838
};
3939

4040
const jumps = [golang, springboot, python];
4141
const jumpLogTest = {
4242
dateLog: '',
43-
message: '',
43+
message: ''
4444
};
4545

4646
const [data, setData] = useState(jumps);
@@ -63,7 +63,7 @@ export const Home: React.FunctionComponent<Props> = () => {
6363
message: 'hello',
6464
jump_path: '/jump',
6565
last_path: '/jump',
66-
jumps: data.map((i) => i.jump),
66+
jumps: data.map((i) => i.jump)
6767
};
6868

6969
const timeout = async (ms: number) => {
@@ -82,7 +82,7 @@ export const Home: React.FunctionComponent<Props> = () => {
8282
const prefix = 'Jump ' + index.toString() + ' -> ';
8383
const item: JumpLog = {
8484
dateLog: prefix + date.toString(),
85-
message: JSON.stringify(jump),
85+
message: JSON.stringify(jump)
8686
};
8787
setCallLogs({ ...item });
8888
}
@@ -133,8 +133,8 @@ export const Home: React.FunctionComponent<Props> = () => {
133133

134134
return (
135135
<>
136-
<div className={cx('jumps')}>
137-
<div className={cx('jumps-buttons')}>
136+
<div role='jump' className={cx('jumps')}>
137+
<div role='jumpselections' className={cx('jumps-buttons')}>
138138
<div>
139139
<h1>Add Jump:</h1>
140140
<div className={cx('jumps-buttons-images')}>
@@ -167,11 +167,11 @@ export const Home: React.FunctionComponent<Props> = () => {
167167
<div>
168168
<h1>Calls Retries:</h1>
169169
<input
170-
type="number"
171-
id="calls"
172-
name="calls"
170+
type='number'
171+
id='calls'
172+
name='calls'
173173
required={true}
174-
placeholder="80"
174+
placeholder='80'
175175
onChange={(event) => setCalls(parseInt(event.target.value))}
176176
value={calls}
177177
className={cx('jumps-buttons-calls')}
@@ -180,11 +180,11 @@ export const Home: React.FunctionComponent<Props> = () => {
180180
<div>
181181
<h1>Calls Interval:</h1>
182182
<input
183-
type="number"
184-
id="callsInterval"
185-
name="callsInterval"
183+
type='number'
184+
id='callsInterval'
185+
name='callsInterval'
186186
required={true}
187-
placeholder="80"
187+
placeholder='80'
188188
onChange={(event) =>
189189
setCallsInterval(parseInt(event.target.value))
190190
}
@@ -193,10 +193,10 @@ export const Home: React.FunctionComponent<Props> = () => {
193193
/>
194194
</div>
195195
</div>
196-
<div className={cx('jumps-box')}>
196+
<div role='jumpbox' className={cx('jumps-box')}>
197197
<h1>Jumps</h1>
198198
<DragDropContext onDragEnd={handleOnDragEnd}>
199-
<Droppable droppableId="jumps">
199+
<Droppable droppableId='jumps'>
200200
{(provided) => (
201201
<ul {...provided.droppableProps} ref={provided.innerRef}>
202202
{data.map(({ id, name, jump }, index) => {
@@ -215,8 +215,8 @@ export const Home: React.FunctionComponent<Props> = () => {
215215
</p>
216216
<img
217217
onClick={() => delJump(index)}
218-
src="./bin.png"
219-
alt="bin"
218+
src='./bin.png'
219+
alt='bin'
220220
className={cx('jumps-box-item-img')}
221221
/>
222222
</div>
@@ -231,18 +231,18 @@ export const Home: React.FunctionComponent<Props> = () => {
231231
</Droppable>
232232
</DragDropContext>
233233
</div>
234-
<div className={cx('jumps-actions')}>
234+
<div role='jumpaction' className={cx('jumps-actions')}>
235235
<button onClick={sendJumps} className={cx('jumps-actions-button')}>
236236
<img
237-
src="./rocket.png"
238-
alt="Jump!"
237+
src='./rocket.png'
238+
alt='Jump!'
239239
className={cx('jumps-actions-button-img')}
240240
/>
241241
<p>- JUMP -</p>
242242
</button>
243243
</div>
244244
</div>
245-
<div className={cx('logs')}>
245+
<div role='jumplog' className={cx('logs')}>
246246
<div className={cx('logs-items')}>
247247
<p>
248248
{callLogs.dateLog} {callLogs.message}

0 commit comments

Comments
 (0)