Skip to content

Commit 21fab9c

Browse files
committed
task: replace error with uialert for CPT view
1 parent 646402c commit 21fab9c

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

app/mission/imap/+mag/+app/+imap/+control/CPT.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ function instantiate(this, parent)
9393

9494
methods (Access = private)
9595

96-
function validatePattern(~, changingData)
96+
function validatePattern(~, changedData)
9797

98-
value = changingData.Value;
98+
value = changedData.Value;
9999
pattern = asManyOfPattern(digitsPattern() + optionalPattern(characterListPattern(",") + whitespacePattern()));
100100

101101
if ~matches(value, pattern)
102-
error("mag:app:InvalidPattern", "Value must match the pattern ""1, 2, 3"".");
102+
103+
[~, figure] = gcbo();
104+
uialert(figure, "Value must match the pattern ""1, 2, 3"".", "Invalid Pattern");
103105
end
104106
end
105107
end

resources/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- (All) Add shortcut to open app from toolbar (quick access)
44
- (All) Fix errors when closing app during mission selection
5+
- (IMAP) Replace `error` with `uialert` for CPT view when mode or range patterns are incorrect
56

67
## Software
78

tests/tool/+mag/+test/ViewControllerTestCase.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
methods (Access = protected)
99

10-
function panel = createTestPanel(testCase)
10+
function panel = createTestPanel(testCase, options)
1111
% CREATETESTPANEL Create "uipanel" to add controls to.
1212

13-
f = uifigure();
13+
arguments
14+
testCase
15+
options.VisibleOverride (1, 1) matlab.lang.OnOffSwitchState = "off"
16+
end
17+
18+
f = uifigure(Visible = options.VisibleOverride);
1419
panel = uipanel(f, Position = [1, 1, f.InnerPosition(3:4)]);
1520

1621
testCase.addTeardown(@() close(f));

tests/unit/app/imap/tCPT.m

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
classdef tCPT < mag.test.ViewControllerTestCase & matlab.uitest.TestCase
2+
% TCPT Unit tests for "mag.app.imap.control.CPT" class.
3+
4+
properties (TestParameter)
5+
PatternField = {"PrimaryModePatternField", "SecondaryModePatternField", "RangePatternField"}
6+
end
7+
8+
methods (Test)
9+
10+
% Test that "instantiate" creates expected elements.
11+
function instantiate(testCase)
12+
13+
% Set up.
14+
panel = testCase.createTestPanel();
15+
cpt = mag.app.imap.control.CPT();
16+
17+
% Exercise.
18+
cpt.instantiate(panel);
19+
20+
% Verify.
21+
testCase.assertNotEmpty(cpt.StartFilterSpinner, "Start filter spinner should not be empty.");
22+
testCase.assertNotEmpty(cpt.PrimaryModePatternField, "Primary mode pattern field should not be empty.");
23+
testCase.assertNotEmpty(cpt.SecondaryModePatternField, "Secondary mode pattern field should not be empty.");
24+
testCase.assertNotEmpty(cpt.RangePatternField, "Range pattern field should not be empty.");
25+
26+
testCase.verifyEqual(cpt.StartFilterSpinner.Layout, matlab.ui.layout.GridLayoutOptions(Row = 1, Column = [2, 3]), ...
27+
"Start filter spinner layout should match expectation.");
28+
29+
testCase.verifyEqual(cpt.PrimaryModePatternField.Value, '2, 64, 2, 4, 64, 4, 4, 128', "Primary mode pattern field value should match expectation.");
30+
testCase.verifyEqual(cpt.PrimaryModePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 2, Column = [2, 3]), ...
31+
"Primary mode pattern field layout should match expectation.");
32+
33+
testCase.verifyEqual(cpt.SecondaryModePatternField.Value, '2, 8, 2, 1, 64, 1, 4, 128', "Secondary mode pattern field value should match expectation.");
34+
testCase.verifyEqual(cpt.SecondaryModePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 3, Column = [2, 3]), ...
35+
"Secondary mode pattern field layout should match expectation.");
36+
37+
testCase.verifyEqual(cpt.RangePatternField.Value, '3, 2, 1, 0', "Range pattern field value should match expectation.");
38+
testCase.verifyEqual(cpt.RangePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 4, Column = [2, 3]), ...
39+
"Range pattern field layout should match expectation.");
40+
end
41+
42+
% Test that "getVisualizeCommand" returns expected command.
43+
function getVisualizeCommand(testCase)
44+
45+
% Set up.
46+
panel = testCase.createTestPanel();
47+
48+
cpt = mag.app.imap.control.CPT();
49+
cpt.instantiate(panel);
50+
51+
results = mag.imap.Analysis();
52+
53+
% Exercise.
54+
command = cpt.getVisualizeCommand(results);
55+
56+
% Verify.
57+
testCase.verifyEqual(command.PositionalArguments, {results}, "Visualize command positional arguments should match expectation.");
58+
59+
for f = ["Filter", "PrimaryModePattern", "SecondaryModePattern", "RangePattern"]
60+
testCase.assertThat(command.NamedArguments, mag.test.constraint.IsField(f), compose("""%s"" should be a named argument.", f));
61+
end
62+
63+
testCase.verifyEqual(command.NamedArguments.Filter, minutes(1), """Filter"" should match expectation.");
64+
testCase.verifyEqual(command.NamedArguments.PrimaryModePattern, [2, 64, 2, 4, 64, 4, 4, 128], """PrimaryModePattern"" should match expectation.");
65+
testCase.verifyEqual(command.NamedArguments.SecondaryModePattern, [2, 8, 2, 1, 64, 1, 4, 128], """SecondaryModePattern"" should match expectation.");
66+
testCase.verifyEqual(command.NamedArguments.RangePattern, [3, 2, 1, 0], """RangePattern"" should match expectation.");
67+
end
68+
69+
% Test that error is thrown if patterns do not match expected
70+
% format.
71+
function pattern_validFormat(testCase, PatternField)
72+
73+
% Set up.
74+
panel = testCase.createTestPanel(VisibleOverride = "on");
75+
76+
cpt = mag.app.imap.control.CPT();
77+
cpt.instantiate(panel);
78+
79+
% Exercise and verify.
80+
testCase.type(cpt.(PatternField), "1, 2, 3");
81+
end
82+
83+
% Test that alert is shown if patterns do not match expected
84+
% format.
85+
function pattern_invalidFormat(testCase, PatternField)
86+
87+
% Set up.
88+
panel = testCase.createTestPanel(VisibleOverride = "on");
89+
90+
cpt = mag.app.imap.control.CPT();
91+
cpt.instantiate(panel);
92+
93+
% Exercise.
94+
testCase.type(cpt.(PatternField), "123 invalid");
95+
96+
% Verify.
97+
testCase.dismissDialog("uialert", panel.Parent);
98+
end
99+
end
100+
end

0 commit comments

Comments
 (0)