@@ -53,6 +53,7 @@ describe('MiniViewHandler', () => {
53
53
unmaximize : jest . fn ( ) ,
54
54
setSize : jest . fn ( ) ,
55
55
setAlwaysOnTop : jest . fn ( ) ,
56
+ once : jest . fn ( ) ,
56
57
} ;
57
58
58
59
mockMainWebContents = {
@@ -73,12 +74,12 @@ describe('MiniViewHandler', () => {
73
74
} ) ;
74
75
75
76
describe ( 'activateMiniView' , ( ) => {
76
- it ( 'should set correct bounds when mainWinPosInMiniView exists' , ( ) => {
77
+ it ( 'should set correct bounds when mainWinPosInMiniView exists' , async ( ) => {
77
78
( config . getUserConfigFields as jest . Mock ) . mockReturnValue ( {
78
79
mainWinPosInMiniView : { x : 10 , y : 20 , width : 500 , height : 400 } ,
79
80
} ) ;
80
81
81
- miniViewHandler . activateMiniView ( ) ;
82
+ await miniViewHandler . activateMiniView ( ) ;
82
83
83
84
expect ( mockMainWindow . setBounds ) . toHaveBeenCalledWith ( {
84
85
x : 10 ,
@@ -88,11 +89,11 @@ describe('MiniViewHandler', () => {
88
89
} ) ;
89
90
} ) ;
90
91
91
- it ( 'should set default width and preserve height when mainWinPosInMiniView does not exist or has width > DEFAULT_MINI_VIEW_WINDOW_WIDTH' , ( ) => {
92
+ it ( 'should set default width and preserve height when mainWinPosInMiniView does not exist or has width > DEFAULT_MINI_VIEW_WINDOW_WIDTH' , async ( ) => {
92
93
( config . getUserConfigFields as jest . Mock ) . mockReturnValue ( {
93
94
mainWinPosInMiniView : { x : 10 , y : 20 , width : 700 , height : 400 } ,
94
95
} ) ;
95
- miniViewHandler . activateMiniView ( ) ;
96
+ await miniViewHandler . activateMiniView ( ) ;
96
97
97
98
expect ( mockMainWindow . setSize ) . toHaveBeenCalledWith (
98
99
DEFAULT_MINI_VIEW_WINDOW_WIDTH ,
@@ -102,32 +103,46 @@ describe('MiniViewHandler', () => {
102
103
103
104
it ( 'should call setIsMiniViewTransition and notifyClient with true' , ( done ) => {
104
105
jest . useFakeTimers ( ) ;
105
- miniViewHandler . activateMiniView ( ) ;
106
-
106
+ miniViewHandler . activateMiniView ( ) . then ( ( ) => {
107
+ expect ( windowHandler . setIsMiniViewTransition ) . toHaveBeenLastCalledWith (
108
+ false ,
109
+ ) ;
110
+ expect ( mockMainWebContents . send ) . toHaveBeenCalledWith (
111
+ 'set-mini-view' ,
112
+ true ,
113
+ ) ;
114
+ done ( ) ;
115
+ } ) ;
107
116
expect ( windowHandler . setIsMiniViewTransition ) . toHaveBeenLastCalledWith (
108
117
true ,
109
118
) ;
110
-
111
119
jest . runAllTimers ( ) ;
112
- expect ( windowHandler . setIsMiniViewTransition ) . toHaveBeenLastCalledWith (
113
- false ,
114
- ) ;
115
- expect ( mockMainWebContents . send ) . toHaveBeenCalledWith (
116
- 'set-mini-view' ,
117
- true ,
118
- ) ;
119
- done ( ) ;
120
120
} ) ;
121
121
122
- it ( 'should set fullscreen to false if currently is in fullscreen' , ( ) => {
122
+ it ( 'should set fullscreen to false if currently is in fullscreen' , async ( ) => {
123
+ jest . useFakeTimers ( ) ;
123
124
( mockMainWindow . isFullScreen as jest . Mock ) . mockReturnValue ( true ) ;
124
- miniViewHandler . activateMiniView ( ) ;
125
+ ( mockMainWindow . once as jest . Mock ) . mockImplementation (
126
+ ( event , callback ) => {
127
+ if ( event === 'leave-full-screen' ) {
128
+ callback ( ) ;
129
+ jest . runAllTimers ( ) ;
130
+ }
131
+ } ,
132
+ ) ;
133
+ await miniViewHandler . activateMiniView ( ) ;
125
134
expect ( mockMainWindow . setFullScreen ) . toHaveBeenCalledWith ( false ) ;
135
+ expect ( mockMainWindow . once ) . toHaveBeenCalledWith (
136
+ 'leave-full-screen' ,
137
+ expect . any ( Function ) ,
138
+ ) ;
126
139
} ) ;
127
140
128
- it ( 'should call unmaximize if currently is maximized' , ( ) => {
141
+ it ( 'should call unmaximize if currently is maximized' , async ( ) => {
142
+ jest . useFakeTimers ( ) ;
129
143
( mockMainWindow . isMaximized as jest . Mock ) . mockReturnValue ( true ) ;
130
- miniViewHandler . activateMiniView ( ) ;
144
+ await miniViewHandler . activateMiniView ( ) ;
145
+ jest . runAllTimers ( ) ;
131
146
expect ( mockMainWindow . unmaximize ) . toHaveBeenCalled ( ) ;
132
147
expect ( mainEvents . publish ) . toHaveBeenCalledWith ( 'unmaximize' ) ;
133
148
} ) ;
0 commit comments