Skip to content

Commit 602945d

Browse files
authored
Merge pull request #114 from mathworks/85-list-selector-changing-items-or-itemsdata-sets-value-arbitrarily
85 list selector changing items or itemsdata sets value arbitrarily
2 parents b64e68c + f7c0d47 commit 602945d

File tree

2 files changed

+207
-119
lines changed

2 files changed

+207
-119
lines changed

test/+wt/+test/ListSelector.m

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef ListSelector < wt.test.BaseWidgetTest
22
% Implements a unit test for a widget or component
33

4-
% Copyright 2020-2025 The MathWorks Inc.
4+
% Copyright 2020-2025 The MathWorks Inc.
55

66
%% Properties
77
properties
@@ -19,10 +19,10 @@ function createFigure(testCase)
1919
testCase.createFigure@wt.test.BaseWidgetTest();
2020

2121
% Adjust grid size
22-
testCase.Figure.Position(3:4) = [500 700];
23-
testCase.Grid.RowHeight = repmat({175},1,3);
22+
testCase.Figure.Position(3:4) = [800 700];
23+
testCase.Grid.RowHeight = repmat({175},1,4);
2424
testCase.Grid.ColumnWidth = {'1x','1x','1x'};
25-
25+
2626
end %function
2727

2828
end %methods
@@ -47,7 +47,7 @@ function setup(testCase)
4747

4848
%% Unit Test
4949
methods (Test)
50-
50+
5151
function testProgrammaticItemsValueSelection(testCase)
5252

5353
% Get the listbox
@@ -67,7 +67,7 @@ function testProgrammaticItemsValueSelection(testCase)
6767
testCase.verifyEqual(testCase.Widget.SelectedIndex, newSelIdx);
6868

6969
end %function
70-
70+
7171

7272
function testProgrammaticItemsDataValueSelection(testCase)
7373

@@ -92,7 +92,7 @@ function testProgrammaticItemsDataValueSelection(testCase)
9292

9393
end %function
9494

95-
95+
9696

9797
function testHighlightedValue(testCase)
9898

@@ -116,7 +116,49 @@ function testHighlightedValue(testCase)
116116
end %function
117117

118118

119+
120+
function testHighlightedValueOnListRemoval(testCase)
121+
122+
% Get the listbox
123+
listControl = testCase.Widget.ListBox;
124+
125+
% Add items to the list
126+
newSelIdx = [1 2 4];
127+
newValue = testCase.ItemNames(newSelIdx);
128+
testCase.verifySetProperty("Value", newValue);
129+
testCase.verifyEqual(testCase.Widget.SelectedIndex, newSelIdx);
130+
131+
% Highlight a value in the list
132+
newHiliteIdx = [1 2 4];
133+
newHilite = testCase.ItemNames(newHiliteIdx);
134+
testCase.verifySetProperty("HighlightedValue", newHilite);
135+
136+
% Remove items from list
137+
testCase.Widget.Items(5) = [];
119138

139+
% List selection value should match
140+
expValue = testCase.ItemNames([1 2 4]);
141+
testCase.verifyEqual(string(listControl.Items), expValue);
142+
143+
% List selection highlight should match
144+
expHighlight = testCase.ItemNames([1 2 4]);
145+
testCase.verifyEqual(testCase.Widget.HighlightedValue, expHighlight);
146+
147+
% Remove items from list
148+
testCase.Widget.Items(2) = [];
149+
150+
% List selection value should match
151+
expValue = testCase.ItemNames([1 4]);
152+
testCase.verifyEqual(string(listControl.Items), expValue);
153+
154+
% List selection highlight should match
155+
expHighlight = testCase.ItemNames([1 4]);
156+
testCase.verifyEqual(testCase.Widget.HighlightedValue, expHighlight);
157+
158+
end %function
159+
160+
161+
120162
function testInteractiveSelection(testCase)
121163

122164
% Get the listbox
@@ -146,7 +188,7 @@ function testInteractiveSelection(testCase)
146188
end %function
147189

148190

149-
191+
150192
function testButtonEnables(testCase)
151193

152194
% Get the listbox and button grid
@@ -205,7 +247,7 @@ function testButtonEnables(testCase)
205247
end %function
206248

207249

208-
250+
209251
function testButtonFunctions(testCase)
210252

211253
% Get the listbox and button grid
@@ -265,22 +307,22 @@ function testButtonFunctions(testCase)
265307

266308
% Verify new highlight
267309
testCase.verifyEqual(w.HighlightedValue, testCase.ItemNames(1));
268-
310+
269311
% Verify button enables
270312
testCase.verifyEquality(buttonGrid.ButtonEnable(2:4), [1 0 1]);
271313

272314
end %function
273315

274316

275-
317+
276318
function testUserButtons(testCase)
277319

278320
% Get the widget
279321
w = testCase.Widget;
280322

281323
% Add User buttons
282324
w.UserButtons.Icon = ["plot_24.png","play_24.png"];
283-
drawnow
325+
drawnow
284326

285327
% Press the buttons
286328
b = w.UserButtons.Button;
@@ -291,7 +333,7 @@ function testUserButtons(testCase)
291333
end %function
292334

293335

294-
336+
295337
function testStyleProperties(testCase)
296338

297339
% Set ButtonWidth

0 commit comments

Comments
 (0)