Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added deploy/images/SearchDropdownExampleOpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deploy/images/SearchDropdownExampleSearching.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deploy/widget_icons/SearchDropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="test"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="SearchDropDown.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="SearchDropDown.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="SearchDropDownExample.mlx" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="SearchDropdown.png" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="SearchDropdownExampleOpen.png" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="SearchDropdownExampleSearching.png" type="File"/>
27 changes: 24 additions & 3 deletions test/+wt/+test/BaseTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,34 @@ function verifyPropertyValue(testCase, component, property, expValue)
expValue
end

import matlab.unittest.constraints.Eventually
import matlab.unittest.constraints.IsEqualTo
import matlab.unittest.constraints.*

% Verify values
if isStringScalar(expValue)

constraint = IsEqualTo(expValue,...
"Using", StringComparator);

elseif islogical(expValue)

constraint = IsEqualTo(expValue,...
"Using", LogicalComparator);

elseif isnumeric(expValue)

constraint = IsEqualTo(expValue,...
"Using", NumericComparator);

else

constraint = IsEqualTo(expValue);

end

% Perform the verification
testCase.verifyThat(...
@()get(component, property),...
Eventually(IsEqualTo(expValue), "WithTimeoutOf", 5));
Eventually(constraint, "WithTimeoutOf", 5));

end %function

Expand Down
14 changes: 11 additions & 3 deletions test/+wt/+test/BaseWidgetTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ function verifySetProperty(testCase,propName,newValue,expValue)
% Verify new property value
actualValue = testCase.Widget.(propName);
testCase.verifyEquality(actualValue, expValue);

% Tried to use this one, but the above works better because
% strings can equate to enumeration strings, etc.
% testCase.verifyPropertyValue(testCase.Widget, propName, expValue);

end %function

Expand All @@ -134,7 +138,7 @@ function verifySetPropertyError(testCase,propName,newValue,errorId)
end %function


function verifyTypeAction(testCase,control,newValue,propName,expValue)
function verifyTypeAction(testCase,component,newValue,propName,expValue)

% If no expected new value after set was given, assume it
% matches the newValue provided as usual
Expand All @@ -143,12 +147,16 @@ function verifyTypeAction(testCase,control,newValue,propName,expValue)
end

% Type the new value into the control
testCase.type(control, newValue);
testCase.type(component, newValue);

% Verify new property value
actualValue = testCase.Widget.(propName);
testCase.verifyEquality(actualValue, expValue);


% Tried to use this one, but the above works better because
% strings can equate to enumeration strings, etc.
% testCase.verifyPropertyValue(component, propName, expValue);

end %function


Expand Down
129 changes: 129 additions & 0 deletions test/+wt/+test/SearchDropDown.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
classdef SearchDropDown < wt.test.BaseWidgetTest
% Implements a unit test for a widget or component

% Copyright 2025 The MathWorks Inc.

%% Properties
properties
ItemNames = [
"Voltage A"
"Voltage B"
"Current A"
"Current B"
"Power A"
"Power B"
];
ItemData = [
11
12
21
22
31
32
];
end


%% Class Setup
methods (TestClassSetup)

function createFigure(testCase)

% Start with superclass
[email protected]();

% Adjust grid size
testCase.Figure.Position(3:4) = [1200 700];
testCase.Grid.RowHeight = repmat({'fit'},1,4);
testCase.Grid.ColumnWidth = repmat({'1x'},1,6);

end %function

end %methods


%% Test Method Setup
methods (TestMethodSetup)

function setup(testCase)

fcn = @()wt.SearchDropDown(testCase.Grid);
testCase.Widget = verifyWarningFree(testCase,fcn);
drawnow

% Set the initial items
testCase.verifySetProperty("Items", testCase.ItemNames);

% Verify empty default
expValue = "";
testCase.verifyPropertyValue(testCase.Widget, "Value", expValue)
testCase.verifyPropertyValue(testCase.Widget.EditField, "Value", char(expValue))

% Set callback
testCase.Widget.ValueChangedFcn = @(s,e)onCallbackTriggered(testCase,e);

end %function

end %methods


%% Unit Test
methods (Test)

function testValueProperty(testCase)

% Get the component
comp = testCase.Widget;

% Set a value from the list
expValue = testCase.ItemNames(3);
testCase.Widget.Value = expValue;
testCase.verifyPropertyValue(comp, "Value", expValue)
testCase.verifyPropertyValue(comp.EditField, "Value", char(expValue))

% Clear the value
expValue = "";
testCase.Widget.Value = expValue;
testCase.verifyPropertyValue(comp, "Value", expValue)
testCase.verifyPropertyValue(comp.EditField, "Value", char(expValue))

% Verify number of callbacks so far
testCase.verifyCallbackCount(0)

end %function



function testInteractivePartialSearch(testCase)

% Get the component
comp = testCase.Widget;

% Simulate typing to filter the dropdown items
testCase.type(comp.EditField, "urren")
testCase.verifyPropertyValue(comp.ListBox, "Items", cellstr(testCase.ItemNames(3:4)'));

% Verify number of callbacks so far
testCase.verifyCallbackCount(1)

% Ensure the listbox is showing
% It might not be due to the nature of the type command
comp.SearchPanel.Visible = true;

% Simulate selecting the second item from the filtered list
testCase.choose(comp.ListBox, 2);

testCase.verifyPropertyValue(comp, "Value", testCase.ItemNames(4));
testCase.verifyPropertyValue(comp.EditField, "Value", char(testCase.ItemNames(4)));

% Verify number of callbacks so far
testCase.verifyCallbackCount(2)

% Verify the list is no longer visible
testCase.verifyNotVisible(comp.SearchPanel)

end %function

end %methods (Test)

end %classdef
Loading
Loading