1- classdef ListSelectorTwoPane < wt .test .ListSelector
1+ classdef ListSelectorTwoPane < wt .test .BaseWidgetTest
22 % Implements a unit test for a widget or component
33
4- % This test for ListSelectorTwoPane reuses those of ListSelector
5- % with a few additions and modifications
6-
74 % Copyright 2020-2021 The MathWorks, Inc.
85
6+ %% Properties
7+ properties
8+ ItemNames = " TestItem" + string(1 : 5 );
9+ ItemData = " TestData" + string(1 : 5 );
10+ end
11+
912
1013 %% Class Setup
1114 methods (TestClassSetup )
@@ -37,6 +40,14 @@ function setup(testCase)
3740 % Set the initial items
3841 testCase .verifySetProperty(" Items" , testCase .ItemNames );
3942
43+ % Set callback
44+ testCase.Widget.ButtonPushedFcn = @(s ,e )onCallbackTriggered(testCase ,e );
45+ testCase.Widget.ValueChangedFcn = @(s ,e )onCallbackTriggered(testCase ,e );
46+ testCase.Widget.HighlightedValueChangedFcn = @(s ,e )onCallbackTriggered(testCase ,e );
47+
48+ % Ensure it renders
49+ drawnow
50+
4051 end % function
4152
4253 end % methods
@@ -46,46 +57,299 @@ function setup(testCase)
4657 methods (Test )
4758
4859 function testProgrammaticItemsValueSelection(testCase )
49-
50- % Run the superclass test
51- testCase .testProgrammaticItemsValueSelection @wt .test .ListSelector();
60+
61+ % Get the RightList
62+ listControl = testCase .Widget .RightList ;
63+
64+ % List should still be empty
65+ testCase .verifyEmpty( listControl .Items );
66+
67+ % Set the value
68+ newSelIdx = [2 5 ];
69+ newValue = testCase .ItemNames(newSelIdx );
70+ testCase .verifySetProperty(" Value" , newValue );
71+
72+ % List and selection should now match value
73+ testCase .verifyEqual(string(listControl .Items ), newValue );
74+ testCase .verifyEqual(listControl .ItemsData , newSelIdx );
75+ testCase .verifyEqual(testCase .Widget .SelectedIndex , newSelIdx );
5276
5377 % Validate the left list items
5478 leftIdx = [1 3 4 ];
55- leftList = testCase .Widget .AllItemsListBox ;
79+ leftList = testCase .Widget .LeftList ;
5680 testCase .verifyEqual(string(leftList .Items ), testCase .ItemNames(leftIdx ));
5781 testCase .verifyEqual(leftList .ItemsData , leftIdx );
5882
83+ % Verify callback did not fire
84+ testCase .verifyEqual(testCase .CallbackCount , 0 );
85+
5986 end % function
6087
6188
6289 function testProgrammaticItemsDataValueSelection(testCase )
6390
64- % Run the superclass test
65- testCase .testProgrammaticItemsDataValueSelection @wt .test .ListSelector();
91+ % Get the RightList
92+ listControl = testCase .Widget .RightList ;
93+
94+ % Set the items data
95+ testCase .verifySetProperty(" ItemsData" , testCase .ItemData );
96+
97+ % List should still be empty
98+ testCase .verifyEmpty( listControl .Items );
99+
100+ % Set the value
101+ newSelIdx = [2 5 ];
102+ newValue = testCase .ItemData(newSelIdx );
103+ testCase .verifySetProperty(" Value" , newValue );
104+
105+ % List and selection should now match value
106+ testCase .verifyEqual(string(listControl .Items ), testCase .ItemNames(newSelIdx ));
107+ testCase .verifyEqual(listControl .ItemsData , newSelIdx );
108+ testCase .verifyEqual(testCase .Widget .SelectedIndex , newSelIdx );
66109
67110 % Validate the left list items
68111 leftIdx = [1 3 4 ];
69- leftList = testCase .Widget .AllItemsListBox ;
112+ leftList = testCase .Widget .LeftList ;
70113 testCase .verifyEqual(string(leftList .Items ), testCase .ItemNames(leftIdx ));
71114 testCase .verifyEqual(leftList .ItemsData , leftIdx );
72115
116+ % Verify callback did not fire
117+ testCase .verifyEqual(testCase .CallbackCount , 0 );
118+
119+ end % function
120+
121+
122+ function testHighlightedValue(testCase )
123+
124+ % Get the RightList
125+ listControl = testCase .Widget .RightList ;
126+
127+ % Add items to the list
128+ newSelIdx = [1 2 4 ];
129+ newValue = testCase .ItemNames(newSelIdx );
130+ testCase .verifySetProperty(" Value" , newValue );
131+ testCase .verifyEqual(testCase .Widget .SelectedIndex , newSelIdx );
132+
133+ % Highlight a value in the list
134+ newHiliteIdx = [1 4 ];
135+ newHilite = testCase .ItemNames(newHiliteIdx );
136+ testCase .verifySetProperty(" HighlightedValue" , newHilite );
137+
138+ % List selection highlight should match
139+ testCase .verifyEqual(listControl .Value , newHiliteIdx );
140+
141+ % Verify callback did not fire
142+ testCase .verifyEqual(testCase .CallbackCount , 0 );
143+
144+ end % function
145+
146+
147+
148+ function testInteractiveSelection(testCase )
149+
150+ % Get the RightList
151+ listControl = testCase .Widget .RightList ;
152+
153+ % Add items to the list
154+ newSelIdx = [1 2 4 ];
155+ newValue = testCase .ItemNames(newSelIdx );
156+ testCase .verifySetProperty(" Value" , newValue );
157+ testCase .verifyEqual(testCase .Widget .SelectedIndex , newSelIdx );
158+
159+ % Select first item with mouse
160+ testCase .choose(listControl , 1 )
161+
162+ % List selection highlight should match
163+ testCase .verifyEqual(testCase .Widget .HighlightedValue , newValue(1 ));
164+ testCase .verifyEqual(listControl .Value , newSelIdx(1 ));
165+
166+ % Select first item with mouse
167+ testCase .choose(listControl , [1 3 ])
168+
169+ % List selection highlight should match
170+ testCase .verifyEqual(testCase .Widget .HighlightedValue , newValue([1 3 ]));
171+ testCase .verifyEqual(listControl .Value , newSelIdx([1 3 ]));
172+
173+ % Verify callbacks fired
174+ testCase .verifyEqual(testCase .CallbackCount , 2 );
175+
73176 end % function
74177
75178
179+
180+ function testButtonEnables(testCase )
181+
182+ % Get the RightList and button grid
183+ listControl = testCase .Widget .RightList ;
184+ buttonGrid = testCase .Widget .ListButtons ;
185+
186+ % Check button enables
187+ actValue = logical(buttonGrid .ButtonEnable );
188+ expValue = [true false false false ];
189+ testCase .verifyEqual(actValue , expValue );
190+
191+ % Now, add all items to the selected list
192+ testCase .verifySetProperty(" Value" , testCase .ItemNames );
193+
194+ % Check button enables
195+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 0 0 0 ]);
196+
197+ % Select first item with mouse
198+ testCase .choose(listControl , 1 )
199+
200+ % List selection highlight should match
201+ testCase .verifyEqual(testCase .Widget .HighlightedValue , testCase .ItemNames(1 ));
202+ testCase .verifyEqual(listControl .Value , 1 );
203+
204+ % Check button enables
205+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 0 1 ]);
206+
207+ % Select last item with mouse
208+ lastIdx = numel(testCase .ItemNames );
209+ testCase .choose(listControl , lastIdx )
210+
211+ % List selection highlight should match
212+ testCase .verifyEqual(testCase .Widget .HighlightedValue , testCase .ItemNames(lastIdx ));
213+ testCase .verifyEqual(listControl .Value , lastIdx );
214+
215+ % Check button enables
216+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 1 0 ]);
217+
218+ % Select multiple items with mouse
219+ selIdx = [2 3 ];
220+ testCase .choose(listControl , selIdx )
221+
222+ % List selection highlight should match
223+ testCase .verifyEqual(testCase .Widget .HighlightedValue , testCase .ItemNames(selIdx ));
224+ testCase .verifyEqual(listControl .Value , selIdx );
225+
226+ % Check button enables
227+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 1 1 ]);
228+
229+ % Verify callbacks fired
230+ testCase .verifyEqual(testCase .CallbackCount , 4 );
231+
232+ end % function
233+
234+
76235 function testButtonFunctions(testCase )
77236
78- % Run the superclass test
79- testCase .testButtonFunctions @wt .test .ListSelector();
237+ % Get the RightList and button grid
238+ w = testCase .Widget ;
239+ listControl = testCase .Widget .RightList ;
240+ buttonGrid = testCase .Widget .ListButtons ;
241+ button = buttonGrid .Button ;
242+
243+ % Add a list of items and put all on list
244+ testCase .verifySetProperty(" Value" , testCase .ItemNames );
245+
246+ % Select multiple items with mouse
247+ selIdx = [2 3 ];
248+ testCase .choose(listControl , selIdx )
249+
250+ % Check button enables
251+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 1 1 ]);
252+
253+ % Move items up
254+ testCase .press(button(3 ))
255+
256+ % Give a moment for update to run
257+ drawnow
258+
259+ % Verify new order
260+ newIdx = [2 3 1 4 5 ];
261+ testCase .verifyEqual(w .Value , testCase .ItemNames(newIdx ));
262+ testCase .verifyEqual(w .SelectedIndex , newIdx );
263+
264+ % Verify button enables
265+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 0 1 ]);
266+
267+ % Move items down
268+ testCase .press(button(4 ))
269+
270+ % Give a moment for update to run
271+ drawnow
272+
273+ % Verify new order
274+ newIdx = 1 : 5 ;
275+ testCase .verifyEqual(w .Value , testCase .ItemNames(newIdx ));
276+ testCase .verifyEqual(w .SelectedIndex , newIdx );
277+
278+ % Verify button enables
279+ testCase .verifyEquality(buttonGrid .ButtonEnable , [0 1 1 1 ]);
280+
281+ % Delete items
282+ testCase .press(button(2 ))
283+
284+ % Give a moment for update to run
285+ drawnow
286+
287+ % Verify new order
288+ newIdx = [1 4 5 ];
289+ testCase .verifyEqual(w .Value , testCase .ItemNames(newIdx ));
290+ testCase .verifyEqual(w .SelectedIndex , newIdx );
291+
292+ % Verify new highlight
293+ testCase .verifyEqual(w .HighlightedValue , testCase .ItemNames(1 ));
294+
295+ % Verify button enables
296+ testCase .verifyEquality(buttonGrid .ButtonEnable(2 : 4 ), [1 0 1 ]);
80297
81298 % Validate the left list items
82299 leftIdx = [2 3 ];
83- leftList = testCase .Widget .AllItemsListBox ;
300+ leftList = testCase .Widget .LeftList ;
84301 testCase .verifyEqual(string(leftList .Items ), testCase .ItemNames(leftIdx ));
85302 testCase .verifyEqual(leftList .ItemsData , leftIdx );
86303
304+ % Verify callbacks fired
305+ testCase .verifyEqual(testCase .CallbackCount , 5 );
306+
307+ end % function
308+
309+
310+
311+ function testUserButtons(testCase )
312+
313+ % Get the widget
314+ w = testCase .Widget ;
315+
316+ % Add User buttons
317+ w.UserButtons.Icon = [" plot_24.png" ," play_24.png" ];
318+ drawnow
319+
320+ % Press the buttons
321+ b = w .UserButtons .Button ;
322+ testCase .verifyNumElements(b , 2 );
323+
324+ % RAJ - not working
325+ % testCase.press(b(1))
326+ % testCase.press(b(2))
327+
328+ % Verify callbacks fired
329+ % testCase.verifyEqual(testCase.CallbackCount, 2);
330+
331+ end % function
332+
333+
334+
335+ function testStyleProperties(testCase )
336+
337+ % Set ButtonWidth
338+ testCase .verifySetProperty(" ButtonWidth" , 40 );
339+
340+ % Set ButtonWidth
341+ testCase .verifySetProperty(" FontSize" , 20 );
342+
343+ % Set Enable
344+ testCase .verifySetProperty(" Enable" , " off" );
345+
346+ % Verify callback did not fire
347+ testCase .verifyEqual(testCase .CallbackCount , 0 );
348+
87349 end % function
88350
351+
352+
89353 end % methods (Test)
90354
91355end % classdef
0 commit comments