|
1 | | -xdescribe('<CommsContext />', () => { |
2 | | - xit('should'); |
| 1 | +import React, { useContext, useState } from 'react'; |
| 2 | +import { mount, shallow } from 'enzyme'; |
| 3 | +const { ipcRenderer } = require('electron'); |
| 4 | + |
| 5 | +import CommsContextProvider, { CommsContext } from '../../../app/context/CommsContext'; |
| 6 | + |
| 7 | +// Setup electron mock |
| 8 | +jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } })); |
| 9 | + |
| 10 | +describe('React unit tests', () => { |
| 11 | + describe('<CommsContext />', () => { |
| 12 | + let wrapper: any; |
| 13 | + |
| 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="dockerData">{JSON.stringify(commsData)}</div> |
| 32 | + <div id="parsedData">{JSON.stringify(mockData)}</div> |
| 33 | + <button id="fetchDockerData" onClick={() => fetchCommsData('customers')}> |
| 34 | + Test fetchDockerData |
| 35 | + </button> |
| 36 | + <button id="setDockerData" onClick={() => setCommsData({ foo: 'bar' })}> |
| 37 | + Test setDockerData |
| 38 | + </button> |
| 39 | + </> |
| 40 | + ); |
| 41 | + }; |
| 42 | + wrapper = mount( |
| 43 | + <CommsContextProvider> |
| 44 | + <TestComponent /> |
| 45 | + </CommsContextProvider> |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should render correctly', () => { |
| 50 | + expect(wrapper).toMatchSnapshot(); |
| 51 | + }); |
| 52 | + }); |
3 | 53 | }); |
0 commit comments