Skip to content

Commit 4080489

Browse files
committed
Fixes to ListSelectorTwoPane to get callbacks working
1 parent 6928e82 commit 4080489

File tree

5 files changed

+706
-66
lines changed

5 files changed

+706
-66
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="ListAddSource.m" type="File" />

test/+wt/+test/ListSelectorTwoPane.m

Lines changed: 269 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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,290 @@ 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+
73119
end %function
74120

75121

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+
176+
end %function
177+
178+
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+
% Verify new order
257+
newIdx = [2 3 1 4 5];
258+
testCase.verifyEqual(w.Value, testCase.ItemNames(newIdx));
259+
testCase.verifyEqual(w.SelectedIndex, newIdx);
260+
261+
% Verify button enables
262+
testCase.verifyEquality(buttonGrid.ButtonEnable, [0 1 0 1]);
263+
264+
% Move items down
265+
testCase.press(button(4))
266+
267+
% Verify new order
268+
newIdx = 1:5;
269+
testCase.verifyEqual(w.Value, testCase.ItemNames(newIdx));
270+
testCase.verifyEqual(w.SelectedIndex, newIdx);
271+
272+
% Verify button enables
273+
testCase.verifyEquality(buttonGrid.ButtonEnable, [0 1 1 1]);
274+
275+
% Delete items
276+
testCase.press(button(2))
277+
278+
% Verify new order
279+
newIdx = [1 4 5];
280+
testCase.verifyEqual(w.Value, testCase.ItemNames(newIdx));
281+
testCase.verifyEqual(w.SelectedIndex, newIdx);
282+
283+
% Verify new highlight
284+
testCase.verifyEqual(w.HighlightedValue, testCase.ItemNames(1));
285+
286+
% Verify button enables
287+
testCase.verifyEquality(buttonGrid.ButtonEnable(2:4), [1 0 1]);
80288

81289
% Validate the left list items
82290
leftIdx = [2 3];
83-
leftList = testCase.Widget.AllItemsListBox;
291+
leftList = testCase.Widget.LeftList;
84292
testCase.verifyEqual(string(leftList.Items), testCase.ItemNames(leftIdx));
85293
testCase.verifyEqual(leftList.ItemsData, leftIdx);
86294

295+
% Verify callbacks fired
296+
testCase.verifyEqual(testCase.CallbackCount, 5);
297+
298+
end %function
299+
300+
301+
302+
function testUserButtons(testCase)
303+
304+
% Get the widget
305+
w = testCase.Widget;
306+
307+
% Add User buttons
308+
w.UserButtons.Icon = ["plot_24.png","play_24.png"];
309+
drawnow
310+
311+
% Press the buttons
312+
b = w.UserButtons.Button;
313+
testCase.verifyNumElements(b, 2);
314+
315+
%RAJ - not working
316+
%testCase.press(b(1))
317+
%testCase.press(b(2))
318+
319+
% Verify callbacks fired
320+
%testCase.verifyEqual(testCase.CallbackCount, 2);
321+
87322
end %function
88323

324+
325+
326+
function testStyleProperties(testCase)
327+
328+
% Set ButtonWidth
329+
testCase.verifySetProperty("ButtonWidth", 40);
330+
331+
% Set ButtonWidth
332+
testCase.verifySetProperty("FontSize", 20);
333+
334+
% Set Enable
335+
testCase.verifySetProperty("Enable", "off");
336+
337+
% Verify callback did not fire
338+
testCase.verifyEqual(testCase.CallbackCount, 0);
339+
340+
end %function
341+
342+
343+
89344
end %methods (Test)
90345

91346
end %classdef

0 commit comments

Comments
 (0)