11classdef ContextualView < wt .test .BaseWidgetTest
22 % Implements a unit test for a widget or component
3-
3+
44 % Copyright 2025 The MathWorks, Inc.
5-
5+
66
77 %% Class Setup
88 methods (TestClassSetup )
9-
9+
1010 function createFigure(testCase )
1111 % Override the figure creation
12-
12+
1313 % Call superclass method
1414 testCase .createFigure @wt .test .BaseWidgetTest();
15-
15+
1616 % Set the figure size
1717 testCase .Figure .Position([3 4 ]) = [900 700 ];
18-
18+
1919 % Modify the grid row height
2020 testCase.Grid.RowHeight = {' 1x' ,' 1x' ,' 1x' };
2121 testCase.Grid.ColumnWidth = {' 1x' ,' 1x' ,' 1x' };
22-
22+
2323 end % function
24-
24+
2525 end % methods
26-
26+
2727
2828 %% Test Method Setup
2929 methods (TestMethodSetup )
30-
30+
3131 function setup(testCase )
32-
32+
3333 fcn = @()wt .ContextualView(testCase .Grid );
3434 testCase.Widget = verifyWarningFree(testCase ,fcn );
35-
35+
3636 end % function
37-
37+
3838 end % methods
39-
40-
39+
40+
4141 %% Test methods
4242 methods (Test )
43-
43+
4444 function testLaunchViewWithModel(testCase )
4545 % This tests:
4646 % Launching the Animal view
@@ -103,52 +103,14 @@ function testLaunchViewWithModel(testCase)
103103 testCase .verifyEqual(actVal , expVal , diag )
104104
105105 end % function
106-
107-
108- function testChildrenHierarchy(testCase )
109- % Verify the children order of the widget
110- % - widget itself
111- % - MainGrid
112- % - ContentGrid (views go here)
113- % - LoadingImage (visible gets toggled to cover view)
114- %
115- % Verify the loading image is off after setup
116- % Verify the loading image file is on path
117-
118- % Verify MainGrid's parent the widget
119- diag = " MainGrid's parent should be the ContextualView widget" ;
120- actVal = testCase .Widget .Grid .Parent ;
121- expVal = testCase .Widget ;
122- testCase .verifyEqual(actVal , expVal , diag )
123106
124- % Verify MainGrid's children order
125- diag = " MainGrid's children should be the ContentGrid and LoadingImage in order" ;
126- actVal = testCase .Widget .Grid .Children ;
127- expVal = [
128- testCase .Widget .ContentGrid
129- testCase .Widget .LoadingImage
130- ];
131- testCase .verifyEqual(actVal , expVal , diag )
132-
133- % Verify loading image is off after setup
134- diag = " LoadingImage should not be visible after setup" ;
135- val = testCase .Widget .LoadingImage .Visible ;
136- testCase .verifyFalse(val , diag )
137-
138- % Verify loading image source file exists on path
139- diag = " LoadingImageSource file must exist on path" ;
140- val = exist(testCase .Widget .LoadingImageSource ," file" ) == 2 ;
141- testCase .verifyTrue(val , diag )
142-
143- end % function
144-
145107
146108 function testChangingViews(testCase )
147109 % This tests:
148110 % Launching the Animal view
149111 % Launching the Enclosure view
150112 % Launching the Animal view again
151-
113+
152114
153115 % Create a model to display
154116 model1 = zooexample .model .Animal ;
@@ -240,186 +202,7 @@ function testChangingViews(testCase)
240202 testCase .verifyEqual(actVal , expVal , diag )
241203
242204 end % function
243-
244-
245- function testBlockWhileLoadingDuringLaunch(testCase )
246- % Verify loading image shows when launching a pane
247-
248- % Create models to display
249- model1 = zooexample .model .Animal ;
250- model1.Species = " Lion" ;
251- model1.Name = " Simba" ;
252- model1.Sex = " male" ;
253- model1.BirthDate = " March 9, 1994" ;
254-
255-
256- % Prepare to launch the view (turning on the loading image)
257- viewClass = " zooexample.view.Animal" ;
258- fcn = @()testCase .Widget .prepareToLaunchView(viewClass );
259- testCase .verifyWarningFree(fcn );
260-
261-
262- % Verify loading image is on
263- diag = " LoadingImage should be visible after prepareToLaunchView" ;
264- actVal = testCase .Widget .LoadingImage .Visible ;
265- expVal = matlab .lang .OnOffSwitchState .on ;
266- testCase .verifyEqual(actVal , expVal , diag )
267-
268-
269- % Launch the view
270- viewClass = " zooexample.view.Animal" ;
271- fcn = @()testCase .Widget .launchView(viewClass , model1 );
272- view1 = testCase .verifyWarningFree(fcn );
273-
274- % Verify loading image is off after launch
275- diag = " LoadingImage should not be visible after launch" ;
276- actVal = testCase .Widget .LoadingImage .Visible ;
277- expVal = matlab .lang .OnOffSwitchState .off ;
278- testCase .verifyEqual(actVal , expVal , diag )
279-
280- % Verify the view's parent
281- diag = " View's parent must be the ContextualView's internal content grid" ;
282- actVal = view1 .Parent ;
283- expVal = testCase .Widget .ContentGrid ;
284- testCase .verifyEqual(actVal , expVal , diag )
285-
286- % Verify the active view
287- diag = " View must be the ContextualView's active view" ;
288- actVal = testCase .Widget .ActiveView ;
289- expVal = view1 ;
290- testCase .verifyEqual(actVal , expVal , diag )
291-
292- end % function
293-
294205
295- function testBlockWhileLoadingOff(testCase )
296- % This tests:
297- % Using prepareToLaunchView
298- % Toggling off the BlockWhileLoading option
299- % Customize the loading image source
300-
301- % Create models to display
302- model1 = zooexample .model .Animal ;
303- model1.Species = " Lion" ;
304- model1.Name = " Simba" ;
305- model1.Sex = " male" ;
306- model1.BirthDate = " March 9, 1994" ;
307-
308- model3 = zooexample .model .Enclosure ;
309- model3.Name = " Lions' Den" ;
310- model3.Location = [10 20 ];
311-
312-
313- % Toggling off the BlockWhileLoading option
314- testCase.Widget.BlockWhileLoading = false ;
315-
316- % Prepare to launch the view (loading image is OFF)
317- viewClass = " zooexample.view.Animal" ;
318- fcn = @()testCase .Widget .prepareToLaunchView(viewClass );
319- testCase .verifyWarningFree(fcn );
320-
321- % Verify loading image is off
322- diag = " LoadingImage should not be visible with BlockWhileLoading = false" ;
323- actVal = testCase .Widget .LoadingImage .Visible ;
324- expVal = matlab .lang .OnOffSwitchState .off ;
325- testCase .verifyEqual(actVal , expVal , diag )
326-
327- % Launch the view
328- viewClass = " zooexample.view.Animal" ;
329- fcn = @()testCase .Widget .launchView(viewClass , model1 );
330- testCase .verifyWarningFree(fcn );
331-
332- % Verify loading image is off after launch
333- diag = " LoadingImage should not be visible after launch" ;
334- actVal = testCase .Widget .LoadingImage .Visible ;
335- expVal = matlab .lang .OnOffSwitchState .off ;
336- testCase .verifyEqual(actVal , expVal , diag )
337-
338-
339- % Toggling on the BlockWhileLoading option
340- testCase.Widget.BlockWhileLoading = true ;
341-
342- % Prepare to launch a different view (turning on the loading image)
343- viewClass = " zooexample.view.Enclosure" ;
344- fcn = @()testCase .Widget .prepareToLaunchView(viewClass );
345- testCase .verifyWarningFree(fcn );
346-
347- % Verify loading image is on
348- diag = " LoadingImage should be visible after prepareToLaunchView" ;
349- actVal = testCase .Widget .LoadingImage .Visible ;
350- expVal = matlab .lang .OnOffSwitchState .on ;
351- testCase .verifyEqual(actVal , expVal , diag )
352-
353- % Launch the view
354- viewClass = " zooexample.view.Enclosure" ;
355- fcn = @()testCase .Widget .launchView(viewClass , model3 );
356- testCase .verifyWarningFree(fcn );
357-
358- end % function
359-
360-
361- function testBlockWhileLoadingSwitching(testCase )
362- % This tests:
363- % Switching between views and models
364- % Launching a new view or switching them shows the loading
365- % image
366- % Changing model on the same view does not show the loading
367- % image
368-
369- % Create models to display
370- model1 = zooexample .model .Animal ;
371- model1.Species = " Lion" ;
372- model1.Name = " Simba" ;
373- model1.Sex = " male" ;
374- model1.BirthDate = " March 9, 1994" ;
375-
376- model3 = zooexample .model .Enclosure ;
377- model3.Name = " Lions' Den" ;
378- model3.Location = [10 20 ];
379-
380-
381- % Launch the first view
382- viewClass = " zooexample.view.Animal" ;
383- fcn = @()testCase .Widget .launchView(viewClass , model1 );
384- testCase .verifyWarningFree(fcn );
385-
386-
387- % Prepare to launch same view (no loading image)
388- viewClass = " zooexample.view.Animal" ;
389- fcn = @()testCase .Widget .prepareToLaunchView(viewClass );
390- testCase .verifyWarningFree(fcn );
391-
392- % Verify loading image is off
393- diag = " LoadingImage should not be visible when preparing to load same active view" ;
394- actVal = testCase .Widget .LoadingImage .Visible ;
395- expVal = matlab .lang .OnOffSwitchState .off ;
396- testCase .verifyEqual(actVal , expVal , diag )
397-
398-
399- % Prepare to launch different view (expect to have loading image)
400- viewClass = " zooexample.view.Enclosure" ;
401- fcn = @()testCase .Widget .prepareToLaunchView(viewClass );
402- testCase .verifyWarningFree(fcn );
403-
404- % Verify loading image is on
405- diag = " LoadingImage should be visible after prepareToLaunchView with launching new pane" ;
406- actVal = testCase .Widget .LoadingImage .Visible ;
407- expVal = matlab .lang .OnOffSwitchState .on ;
408- testCase .verifyEqual(actVal , expVal , diag )
409-
410- % Launch the view
411- viewClass = " zooexample.view.Enclosure" ;
412- fcn = @()testCase .Widget .launchView(viewClass , model3 );
413- testCase .verifyWarningFree(fcn );
414-
415- % Verify loading image is off after launch
416- diag = " LoadingImage should not be visible after launch" ;
417- actVal = testCase .Widget .LoadingImage .Visible ;
418- expVal = matlab .lang .OnOffSwitchState .off ;
419- testCase .verifyEqual(actVal , expVal , diag )
420-
421- end % function
422-
423206
424207 function testClearView(testCase )
425208 % This tests debugging methods:
@@ -429,7 +212,7 @@ function testClearView(testCase)
429212 diag = " Expected launchMultipleViews helper function to put component in desired state." ;
430213 fcn = @()testCase .launchMultipleViews();
431214 testCase .assumeWarningFree(fcn , diag )
432-
215+
433216 % Clear the view
434217 diag = " Expected clearView to run without warnings." ;
435218 fcn = @()testCase .Widget .clearView();
@@ -451,7 +234,7 @@ function testClearView(testCase)
451234 testCase .verifyNotEmpty(actVal , diag )
452235
453236 end % function
454-
237+
455238
456239 function testRelaunchActiveView(testCase )
457240 % This tests debugging methods:
@@ -465,7 +248,7 @@ function testRelaunchActiveView(testCase)
465248 % Get the active view and model
466249 view3 = testCase .Widget .ActiveView ;
467250 model3 = view3 .Model ;
468-
251+
469252 % Relaunch the view
470253 diag = " Expected relaunchActiveView to run without warnings." ;
471254 fcn = @()testCase .Widget .relaunchActiveView();
@@ -491,7 +274,7 @@ function testRelaunchActiveView(testCase)
491274 actVal = view3A .Model ;
492275 expVal = model3 ;
493276 testCase .verifyEqual(actVal , expVal , diag )
494-
277+
495278 % Verify the active view is listed in loaded views
496279 diag = " View must be listed in the ContextualView's loaded views" ;
497280 val = any(view3A == testCase .Widget .LoadedViews );
@@ -503,7 +286,7 @@ function testRelaunchActiveView(testCase)
503286 testCase .verifyFalse(val , diag )
504287
505288 end % function
506-
289+
507290
508291 function testReset(testCase )
509292 % This tests debugging methods:
@@ -513,7 +296,7 @@ function testReset(testCase)
513296 diag = " Expected launchMultipleViews helper function to put component in desired state." ;
514297 fcn = @()testCase .launchMultipleViews();
515298 testCase .assumeWarningFree(fcn , diag )
516-
299+
517300 % Reset the view
518301 diag = " Expected reset to run without warnings." ;
519302 fcn = @()testCase .Widget .reset();
@@ -535,13 +318,13 @@ function testReset(testCase)
535318 testCase .verifyEmpty(actVal , diag )
536319
537320 end % function
538-
321+
539322 end % methods (Test)
540323
541324
542325 %% Helper methods
543326 methods (Access = protected )
544-
327+
545328 function launchMultipleViews(testCase )
546329 % Launches multiple views into the component to have it in a
547330 % used state
@@ -571,5 +354,5 @@ function launchMultipleViews(testCase)
571354 end % function
572355
573356 end % methods
574-
357+
575358end % classdef
0 commit comments