Skip to content

Commit a9ba020

Browse files
author
Antonio Contreras LEMONCODE
committed
Create employee list mappers spec
1 parent 9c383fa commit a9ba020

2 files changed

Lines changed: 112 additions & 1 deletion

File tree

src/pods/employee-list/employee-list.container.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { trackPromise } from 'react-promise-tracker';
77
import { mapEmployeeListFromApiToVm } from './employee-list.mappers';
88
import { useHistory } from 'react-router-dom';
99
import { routes } from 'core/router';
10+
const editEmployeeId = '0';
1011

1112
export const EmployeeListContainer: React.FunctionComponent = () => {
1213
const [employees, setEmployees] = React.useState<Employee[]>([]);
@@ -25,7 +26,7 @@ export const EmployeeListContainer: React.FunctionComponent = () => {
2526
};
2627

2728
const handleCreate = () => {
28-
history.push(routes.editEmployee('0'));
29+
history.push(routes.editEmployee(editEmployeeId));
2930
};
3031

3132
const handleEdit = (id: string) => {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as apiModel from './api/employee-list.api-model';
2+
import * as viewModel from './employee-list.vm';
3+
import { mapEmployeeListFromApiToVm } from './employee-list.mappers';
4+
5+
describe('./pods/employee-list', () => {
6+
it('should return empty array when feeding undefined employee list', () => {
7+
// Arrange
8+
const employeeList = undefined;
9+
10+
// Act
11+
const result = mapEmployeeListFromApiToVm(employeeList);
12+
13+
// Assert
14+
expect(result).toEqual([]);
15+
});
16+
17+
it('should return empty array when feeding null employee list', () => {
18+
// Arrange
19+
const employeeList = null;
20+
21+
// Act
22+
const result = mapEmployeeListFromApiToVm(employeeList);
23+
24+
// Assert
25+
expect(result).toEqual([]);
26+
});
27+
28+
it('should return empty array when feeding empty array employee list', () => {
29+
// Arrange
30+
const employeeList = [];
31+
32+
// Act
33+
const result = mapEmployeeListFromApiToVm(employeeList);
34+
35+
// Assert
36+
expect(result).toEqual([]);
37+
});
38+
39+
it('should return one item with values when passing one item with values', () => {
40+
// Arrange
41+
const employeeList: apiModel.Employee[] = [
42+
{
43+
id: 'test id',
44+
active: true,
45+
name: 'test name',
46+
email: 'test@email.com',
47+
lastDateIncurred: '02/02/2020',
48+
},
49+
];
50+
51+
const expectedResult: viewModel.Employee[] = [
52+
{
53+
id: 'test id',
54+
active: true,
55+
name: 'test name',
56+
email: 'test@email.com',
57+
lastDateIncurred: '02/02/2020',
58+
},
59+
];
60+
61+
// Act
62+
const result = mapEmployeeListFromApiToVm(employeeList);
63+
64+
// Assert
65+
expect(result).toEqual(expectedResult);
66+
});
67+
68+
it('should return two item with values when passing two item with values', () => {
69+
// Arrange
70+
const employeeList: apiModel.Employee[] = [
71+
{
72+
id: 'test id 1',
73+
active: true,
74+
name: 'test name 1',
75+
email: 'test@email.com',
76+
lastDateIncurred: '02/02/2020',
77+
},
78+
{
79+
id: 'test id 2',
80+
active: true,
81+
name: 'test name 2',
82+
email: 'test@email.com',
83+
lastDateIncurred: '02/02/2020',
84+
},
85+
];
86+
87+
const expectedResult: viewModel.Employee[] = [
88+
{
89+
id: 'test id 1',
90+
active: true,
91+
name: 'test name 1',
92+
email: 'test@email.com',
93+
lastDateIncurred: '02/02/2020',
94+
},
95+
{
96+
id: 'test id 2',
97+
active: true,
98+
name: 'test name 2',
99+
email: 'test@email.com',
100+
lastDateIncurred: '02/02/2020',
101+
},
102+
];
103+
104+
// Act
105+
const result = mapEmployeeListFromApiToVm(employeeList);
106+
107+
// Assert
108+
expect(result).toEqual(expectedResult);
109+
});
110+
});

0 commit comments

Comments
 (0)