1
+ import React , { useContext } from 'react' ;
2
+ import { createMount , createShallow } from '@material-ui/core/test-utils' ;
3
+
4
+ import DashboardContextProvider , { DashboardContext } from '../../../app/context/DashboardContext' ;
5
+ import Settings from '../../../app/components/Settings' ;
6
+ const { ipcRenderer } = require ( 'electron' ) ;
7
+ jest . mock ( 'electron' , ( ) => ( { ipcRenderer : { sendSync : jest . fn ( ) } } ) ) ;
8
+
9
+ describe ( '<Settings />' , ( ) => {
10
+ let wrapper : any ;
11
+ let mount : any ;
12
+ let shallow : any ;
13
+
14
+ beforeEach ( ( ) => {
15
+ mount = createMount ( ) ;
16
+ shallow = createShallow ( ) ;
17
+ } ) ;
18
+
19
+ afterEach ( ( ) => {
20
+ mount . cleanUp ( ) ;
21
+ } ) ;
22
+
23
+ it ( "should render " , ( ) => {
24
+ const wrapper = mount (
25
+ < DashboardContextProvider >
26
+ < Settings />
27
+ </ DashboardContextProvider >
28
+ ) ;
29
+ expect ( wrapper . exists ) . toBeTruthy ;
30
+ } ) ;
31
+
32
+ it ( "should have a button with text value of Light" , ( ) => {
33
+ const wrapper = mount (
34
+ < DashboardContextProvider >
35
+ < Settings />
36
+ </ DashboardContextProvider >
37
+ ) ;
38
+ const button = wrapper . find ( '#lightMode' ) ;
39
+ // button.simulate('click');
40
+ expect ( button . text ( ) ) . toEqual ( 'Light' )
41
+ } ) ;
42
+
43
+ it ( "should emit the changeApp event when click light mode" , ( ) => {
44
+ const wrapper = mount (
45
+ < DashboardContextProvider >
46
+ < Settings />
47
+ </ DashboardContextProvider >
48
+ ) ;
49
+ const button = wrapper . find ( '#lightMode' ) ;
50
+ button . simulate ( 'click' ) ;
51
+ expect ( ipcRenderer . sendSync ) . toHaveBeenCalledWith ( 'changeMode' , 'light mode' ) ;
52
+ } ) ;
53
+
54
+ it ( "should emit the changeApp event when click dark mode" , ( ) => {
55
+ const wrapper = mount (
56
+ < DashboardContextProvider >
57
+ < Settings />
58
+ </ DashboardContextProvider >
59
+ ) ;
60
+ const button = wrapper . find ( '#darkMode' ) ;
61
+ button . simulate ( 'click' ) ;
62
+ expect ( ipcRenderer . sendSync ) . toHaveBeenCalledWith ( 'changeMode' , 'dark mode' ) ;
63
+ } ) ;
64
+
65
+ it ( "should have a button with text value of Dark" , ( ) => {
66
+ const wrapper = mount (
67
+ < DashboardContextProvider >
68
+ < Settings />
69
+ </ DashboardContextProvider >
70
+ ) ;
71
+ const button = wrapper . find ( '#darkMode' ) ;
72
+ // button.simulate('click');
73
+ expect ( button . text ( ) ) . toEqual ( 'Dark' )
74
+ } ) ;
75
+
76
+
77
+ } ) ;
0 commit comments