Skip to content

Commit 84abd18

Browse files
Name tests <CommsContext />
1 parent 20b7d8d commit 84abd18

1 file changed

Lines changed: 54 additions & 56 deletions

File tree

__tests__/app/context/CommsContext.test.tsx

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,65 @@ import CommsContextProvider, { CommsContext } from '../../../app/context/CommsCo
77
// Setup electron mock
88
jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } }));
99

10-
describe('React unit tests', () => {
11-
describe('<CommsContext />', () => {
12-
let wrapper: any;
13-
let shallow: any;
10+
describe('<CommsContext />', () => {
11+
let wrapper: any;
12+
let shallow: any;
1413

15-
beforeEach(() => {
16-
const TestComponent = () => {
17-
const { commsData, setCommsData, fetchCommsData } = useContext(CommsContext);
18-
const [mockData, setMockData] = useState([
19-
{
20-
correlatingid: '7bdad8c0',
21-
endpoint: '/customers/createcustomer',
22-
microservice: 'customers',
23-
request: 'GET',
24-
responsemessage: 'OK',
25-
responsestatus: 200,
26-
time: '2020-06-27T05:30:43.567Z',
27-
id: 36,
28-
},
29-
]);
30-
return (
31-
<>
32-
<div id="commsData">{JSON.stringify(commsData)}</div>
33-
<div id="parsedData">{JSON.stringify(mockData)}</div>
34-
<button id="fetchCommsData" onClick={() => fetchCommsData('customers')}>
35-
Test fetchCommsData
36-
</button>
37-
<button id="setCommsData" onClick={() => setCommsData({ foo: 'bar' })}>
38-
Test setCommsData
39-
</button>
40-
</>
41-
);
42-
};
43-
wrapper = mount(
44-
<CommsContextProvider>
45-
<TestComponent />
46-
</CommsContextProvider>
14+
beforeEach(() => {
15+
const TestComponent = () => {
16+
const { commsData, setCommsData, fetchCommsData } = useContext(CommsContext);
17+
const [mockData, setMockData] = useState([
18+
{
19+
correlatingid: '7bdad8c0',
20+
endpoint: '/customers/createcustomer',
21+
microservice: 'customers',
22+
request: 'GET',
23+
responsemessage: 'OK',
24+
responsestatus: 200,
25+
time: '2020-06-27T05:30:43.567Z',
26+
id: 36,
27+
},
28+
]);
29+
return (
30+
<>
31+
<div id="commsData">{JSON.stringify(commsData)}</div>
32+
<div id="parsedData">{JSON.stringify(mockData)}</div>
33+
<button id="fetchCommsData" onClick={() => fetchCommsData('customers')}>
34+
Test fetchCommsData
35+
</button>
36+
<button id="setCommsData" onClick={() => setCommsData({ foo: 'bar' })}>
37+
Test setCommsData
38+
</button>
39+
</>
4740
);
48-
});
41+
};
42+
wrapper = mount(
43+
<CommsContextProvider>
44+
<TestComponent />
45+
</CommsContextProvider>
46+
);
47+
});
4948

50-
it('should render correctly', () => {
51-
expect(wrapper).toMatchSnapshot();
52-
});
49+
it('should render correctly', () => {
50+
expect(wrapper).toMatchSnapshot();
51+
});
5352

54-
it("should emit the 'commsRequest' event and listen on 'commsResponse' when invoking fetchCommsData", () => {
55-
const button = wrapper.find('#fetchCommsData');
56-
button.simulate('click');
57-
expect(ipcRenderer.send).toHaveBeenCalledWith('commsRequest', 'customers');
58-
expect(ipcRenderer.on).toHaveBeenCalledWith('commsResponse', expect.any(Function));
59-
});
53+
it("should emit the 'commsRequest' event and listen on 'commsResponse' when invoking fetchCommsData", () => {
54+
const button = wrapper.find('#fetchCommsData');
55+
button.simulate('click');
56+
expect(ipcRenderer.send).toHaveBeenCalledWith('commsRequest', 'customers');
57+
expect(ipcRenderer.on).toHaveBeenCalledWith('commsResponse', expect.any(Function));
58+
});
6059

61-
it('should update dockerData when setCommsData is invoked with new data', () => {
62-
const button = wrapper.find('#setCommsData');
63-
button.simulate('click');
64-
expect(wrapper.find('#commsData').text()).toEqual(JSON.stringify({ foo: 'bar' }));
65-
});
60+
it('should update dockerData when setCommsData is invoked with new data', () => {
61+
const button = wrapper.find('#setCommsData');
62+
button.simulate('click');
63+
expect(wrapper.find('#commsData').text()).toEqual(JSON.stringify({ foo: 'bar' }));
64+
});
6665

67-
it('should display status code information', () => {
68-
console.log(wrapper.debug());
69-
expect(wrapper.find('#parsedData').text()).toMatch('GET');
70-
expect(wrapper.find('#parsedData').text()).toMatch('OK');
71-
});
66+
it('should display status code information', () => {
67+
console.log(wrapper.debug());
68+
expect(wrapper.find('#parsedData').text()).toMatch('GET');
69+
expect(wrapper.find('#parsedData').text()).toMatch('OK');
7270
});
7371
});

0 commit comments

Comments
 (0)