14
14
limitations under the License.
15
15
*/
16
16
17
- const mockBrowserWindowInstance = ( ) => {
17
+ const mockWebContentsViewInstance = ( ) => {
18
18
const instance = {
19
19
listeners : { } ,
20
- addBrowserView : jest . fn ( ) ,
21
- destroy : jest . fn ( ) ,
22
- getContentBounds : jest . fn ( ( ) => ( { } ) ) ,
23
- isFullScreen : jest . fn ( ) ,
24
- loadURL : jest . fn ( ) ,
25
- minimize : jest . fn ( ) ,
26
20
on : jest . fn ( ( eventName , func ) => {
27
21
instance . listeners [ eventName ] = func ;
28
22
} ) ,
29
- removeBrowserView : jest . fn ( ) ,
30
- removeMenu : jest . fn ( ) ,
31
- setAutoResize : jest . fn ( ) ,
32
23
setBounds : jest . fn ( ) ,
33
- setBrowserView : jest . fn ( ) ,
34
- setFullScreen : jest . fn ( ) ,
35
- show : jest . fn ( ) ,
36
- showInactive : jest . fn ( ) ,
37
24
webContents : {
38
25
loadedUrl : '' ,
39
- browserWindowInstance : ( ) => instance ,
40
26
copy : jest . fn ( ) ,
41
27
copyImageAt : jest . fn ( ) ,
42
28
cut : jest . fn ( ) ,
@@ -61,9 +47,36 @@ const mockBrowserWindowInstance = () => {
61
47
return instance ;
62
48
} ;
63
49
50
+ const mockBaseWindowInstance = ( ) => {
51
+ const instance = {
52
+ listeners : { } ,
53
+ destroy : jest . fn ( ) ,
54
+ getContentBounds : jest . fn ( ( ) => ( { } ) ) ,
55
+ isFullScreen : jest . fn ( ) ,
56
+ loadURL : jest . fn ( ) ,
57
+ minimize : jest . fn ( ) ,
58
+ on : jest . fn ( ( eventName , func ) => {
59
+ instance . listeners [ eventName ] = func ;
60
+ } ) ,
61
+ removeMenu : jest . fn ( ) ,
62
+ setBounds : jest . fn ( ) ,
63
+ setFullScreen : jest . fn ( ) ,
64
+ show : jest . fn ( ) ,
65
+ showInactive : jest . fn ( ) ,
66
+ contentView : {
67
+ addChildView : jest . fn ( view => instance . contentView . children . push ( view ) ) ,
68
+ removeChildView : jest . fn ( view => {
69
+ instance . contentView . children = instance . contentView . children . filter ( child => child !== view ) ;
70
+ } ) ,
71
+ children : [ ]
72
+ }
73
+ } ;
74
+ return instance ;
75
+ } ;
76
+
64
77
const mockElectronInstance = ( { ...overriddenProps } = { } ) => {
65
- const browserViewInstance = mockBrowserWindowInstance ( ) ;
66
- const browserWindowInstance = mockBrowserWindowInstance ( ) ;
78
+ const webContentsViewInstance = mockWebContentsViewInstance ( ) ;
79
+ const baseWindowInstance = mockBaseWindowInstance ( ) ;
67
80
const sessionInstance = {
68
81
clearCache : jest . fn ( ) ,
69
82
clearCodeCaches : jest . fn ( ) ,
@@ -76,10 +89,10 @@ const mockElectronInstance = ({...overriddenProps} = {}) => {
76
89
on : jest . fn ( )
77
90
} ;
78
91
const instance = {
79
- BrowserView : jest . fn ( ( ) => browserViewInstance ) ,
80
- browserViewInstance ,
81
- BrowserWindow : jest . fn ( ( ) => browserWindowInstance ) ,
82
- browserWindowInstance ,
92
+ WebContentsView : jest . fn ( ( ) => webContentsViewInstance ) ,
93
+ webContentsViewInstance ,
94
+ BaseWindow : jest . fn ( ( ) => baseWindowInstance ) ,
95
+ baseWindowInstance ,
83
96
Menu : jest . fn ( ) ,
84
97
MenuItem : jest . fn ( ) ,
85
98
Notification : jest . fn ( ) ,
@@ -139,8 +152,7 @@ const mockElectronInstance = ({...overriddenProps} = {}) => {
139
152
} ,
140
153
...overriddenProps
141
154
} ;
142
- instance . BrowserWindow . fromWebContents = jest . fn ( webContents => webContents . browserWindowInstance ( ) ) ;
143
155
return instance ;
144
156
} ;
145
157
146
- module . exports = { mockBrowserWindowInstance , mockElectronInstance} ;
158
+ module . exports = { mockBaseWindowInstance , mockWebContentsViewInstance , mockElectronInstance} ;
0 commit comments