@@ -10,6 +10,7 @@ jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } }
1010describe ( 'React unit tests' , ( ) => {
1111 describe ( '<CommsContext />' , ( ) => {
1212 let wrapper : any ;
13+ let shallow : any ;
1314
1415 beforeEach ( ( ) => {
1516 const TestComponent = ( ) => {
@@ -28,13 +29,13 @@ describe('React unit tests', () => {
2829 ] ) ;
2930 return (
3031 < >
31- < div id = "dockerData " > { JSON . stringify ( commsData ) } </ div >
32+ < div id = "commsData " > { JSON . stringify ( commsData ) } </ div >
3233 < div id = "parsedData" > { JSON . stringify ( mockData ) } </ div >
33- < button id = "fetchDockerData " onClick = { ( ) => fetchCommsData ( 'customers' ) } >
34- Test fetchDockerData
34+ < button id = "fetchCommsData " onClick = { ( ) => fetchCommsData ( 'customers' ) } >
35+ Test fetchCommsData
3536 </ button >
36- < button id = "setDockerData " onClick = { ( ) => setCommsData ( { foo : 'bar' } ) } >
37- Test setDockerData
37+ < button id = "setCommsData " onClick = { ( ) => setCommsData ( { foo : 'bar' } ) } >
38+ Test setCommsData
3839 </ button >
3940 </ >
4041 ) ;
@@ -49,5 +50,24 @@ describe('React unit tests', () => {
4950 it ( 'should render correctly' , ( ) => {
5051 expect ( wrapper ) . toMatchSnapshot ( ) ;
5152 } ) ;
53+
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+ } ) ;
60+
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+ } ) ;
66+
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+ } ) ;
5272 } ) ;
5373} ) ;
0 commit comments