1
- from typing import Any , Callable , List , Optional , Tuple
1
+ from typing import Any , Callable , List , Optional , Tuple , Union
2
2
3
3
import pytest
4
4
from pytest_mock import MockerFixture
@@ -82,15 +82,15 @@ def test_set_footer_text_default(self, view: View, mocker: MockerFixture) -> Non
82
82
83
83
view .set_footer_text ()
84
84
85
- view ._w .footer .set_text .assert_called_once_with (["some help text" ])
85
+ view .frame .footer .set_text .assert_called_once_with (["some help text" ])
86
86
view .controller .update_screen .assert_called_once_with ()
87
87
88
88
def test_set_footer_text_specific_text (
89
89
self , view : View , text : str = "blah"
90
90
) -> None :
91
91
view .set_footer_text ([text ])
92
92
93
- view ._w .footer .set_text .assert_called_once_with ([text ])
93
+ view .frame .footer .set_text .assert_called_once_with ([text ])
94
94
view .controller .update_screen .assert_called_once_with ()
95
95
96
96
def test_set_footer_text_with_duration (
@@ -105,7 +105,7 @@ def test_set_footer_text_with_duration(
105
105
106
106
view .set_footer_text ([custom_text ], duration = duration )
107
107
108
- view ._w .footer .set_text .assert_has_calls (
108
+ view .frame .footer .set_text .assert_has_calls (
109
109
[mocker .call ([custom_text ]), mocker .call (["some help text" ])]
110
110
)
111
111
mock_sleep .assert_called_once_with (duration )
@@ -179,6 +179,7 @@ def just_set_message_view(self: Any) -> None:
179
179
title_divider = mocker .patch (MODULE + ".urwid.Divider" )
180
180
text = mocker .patch (MODULE + ".urwid.Text" )
181
181
footer_view = mocker .patch (VIEW + ".footer_view" )
182
+ show_left_panel = mocker .patch (VIEW + ".show_left_panel" )
182
183
183
184
full_name = "Bob James"
184
185
@@ -202,7 +203,7 @@ def just_set_message_view(self: Any) -> None:
202
203
expected_column_calls = [
203
204
mocker .call (
204
205
[
205
- (LEFT_WIDTH , view .left_panel ),
206
+ (TAB_WIDTH , view .left_tab ),
206
207
("weight" , 10 , mocker .ANY ), # ANY is a center
207
208
(TAB_WIDTH , view .right_tab ),
208
209
],
@@ -225,58 +226,107 @@ def just_set_message_view(self: Any) -> None:
225
226
frame .assert_called_once_with (
226
227
view .body , col (), focus_part = "body" , footer = footer_view ()
227
228
)
229
+ assert view .frame == frame ()
230
+ show_left_panel .assert_called_once_with (visible = True )
228
231
229
232
@pytest .mark .parametrize ("autohide" , [True , False ])
230
- @pytest .mark .parametrize ("visible, width" , [(True , LEFT_WIDTH ), (False , TAB_WIDTH )])
233
+ @pytest .mark .parametrize ("visible" , [True , False ])
234
+ @pytest .mark .parametrize (
235
+ "expected_overlay_options" ,
236
+ [
237
+ (
238
+ "left" ,
239
+ None ,
240
+ "given" ,
241
+ LEFT_WIDTH + 1 ,
242
+ None ,
243
+ 0 ,
244
+ 0 ,
245
+ "top" ,
246
+ None ,
247
+ "relative" ,
248
+ 100 ,
249
+ None ,
250
+ 0 ,
251
+ 0 ,
252
+ )
253
+ ],
254
+ )
231
255
def test_show_left_panel (
232
256
self ,
233
257
mocker : MockerFixture ,
234
258
view : View ,
235
259
visible : bool ,
236
- width : int ,
237
260
autohide : bool ,
261
+ expected_overlay_options : Tuple [Union [str , int , None ]],
238
262
) -> None :
239
- view .body = mocker .Mock ()
240
- view .body .contents = [view .left_panel , mocker .Mock (), mocker .Mock ()]
263
+ view .frame .body = view .body
241
264
view .controller .autohide = autohide
242
265
243
266
view .show_left_panel (visible = visible )
244
267
245
268
if autohide :
246
269
if visible :
247
- assert view .body .contents [0 ][0 ] == view .left_panel
270
+ assert view .frame .body .top_w .contents [0 ][0 ] == view .left_panel
271
+ assert view .frame .body .bottom_w == view .body
272
+ assert view .frame .body .contents [1 ][1 ] == expected_overlay_options
248
273
else :
249
- assert view .body .contents [0 ][0 ] == view .left_tab
250
- view .body .options . assert_called_once_with ( "given" , width )
274
+ assert view .frame . body .contents [0 ][0 ] == view .left_tab
275
+ assert view .body .focus_position == 1
251
276
else :
252
- view .body .options .assert_not_called ()
277
+ # No change
278
+ assert view .frame .body .contents [0 ][0 ] == view .left_tab
253
279
254
280
@pytest .mark .parametrize ("autohide" , [True , False ])
255
281
@pytest .mark .parametrize (
256
282
"visible, width" , [(True , RIGHT_WIDTH ), (False , TAB_WIDTH )]
257
283
)
284
+ @pytest .mark .parametrize (
285
+ "expected_overlay_options" ,
286
+ [
287
+ (
288
+ "right" ,
289
+ None ,
290
+ "given" ,
291
+ RIGHT_WIDTH + 1 ,
292
+ None ,
293
+ 0 ,
294
+ 0 ,
295
+ "top" ,
296
+ None ,
297
+ "relative" ,
298
+ 100 ,
299
+ None ,
300
+ 0 ,
301
+ 0 ,
302
+ )
303
+ ],
304
+ )
258
305
def test_show_right_panel (
259
306
self ,
260
307
mocker : MockerFixture ,
261
308
view : View ,
262
309
visible : bool ,
263
310
width : int ,
264
311
autohide : bool ,
312
+ expected_overlay_options : Tuple [Union [str , int , None ]],
265
313
) -> None :
266
- view .body = mocker .Mock ()
267
- view .body .contents = [mocker .Mock (), mocker .Mock (), view .right_panel ]
314
+ view .frame .body = view .body
268
315
view .controller .autohide = autohide
269
316
270
317
view .show_right_panel (visible = visible )
271
318
272
319
if autohide :
273
320
if visible :
274
- assert view .body .contents [2 ][0 ] == view .right_panel
321
+ assert view .frame .body .top_w .contents [1 ][0 ] == view .right_panel
322
+ assert view .frame .body .bottom_w == view .body
323
+ assert view .frame .body .contents [1 ][1 ] == expected_overlay_options
275
324
else :
276
- assert view .body .contents [2 ][0 ] == view .right_tab
277
- view .body .options . assert_called_once_with ( "given" , width )
325
+ assert view .frame . body .contents [0 ][0 ] == view .right_tab
326
+ assert view .body .focus_position == 1
278
327
else :
279
- view .body .options .assert_not_called ()
328
+ # No change
329
+ assert view .frame .body .contents [0 ][0 ] == view .right_tab
280
330
281
331
def test_keypress_normal_mode_navigation (
282
332
self ,
@@ -356,7 +406,7 @@ def test_keypress_autohide_users(
356
406
view .right_panel = mocker .Mock ()
357
407
size = widget_size (view )
358
408
view .controller .is_in_editor_mode = lambda : False
359
- view .body .focus_position = None
409
+ view .body .focus_position = 1
360
410
361
411
view .keypress (size , key )
362
412
0 commit comments