Skip to content

Commit 698e7d4

Browse files
authored
Merge pull request #397 from smartdevicelink/bugfix/choice-set-timeouts
Fix setting choice set timeouts
2 parents 2084b65 + 114b364 commit 698e7d4

File tree

4 files changed

+237
-36
lines changed

4 files changed

+237
-36
lines changed

lib/js/src/manager/screen/choiceset/ChoiceSet.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class ChoiceSet {
3737
/**
3838
* Create a new instance of ChoiceSet
3939
* Initialize with a title, choices, and listener. It will use the default timeout and layout, all other properties (such as prompts) will be null.
40-
* WARNING: If you display multiple cells with the same title with the only uniquing property between cells being different `vrCommands` or a feature
41-
* that is not displayed on the head unit (e.g. if the head unit doesn't display `secondaryArtwork` and that's the only uniquing property between two cells)
40+
* WARNING: If you display multiple cells with the same title with the only uniquing property between cells being different `vrCommands` or a feature
41+
* that is not displayed on the head unit (e.g. if the head unit doesn't display `secondaryArtwork` and that's the only uniquing property between two cells)
4242
* then the cells may appear to be the same to the user in `Manual` mode. This only applies to RPC connections >= 7.1.0.
43-
* WARNING: On < 7.1.0 connections, the title cell will be automatically modified among cells that have the same title when they are preloaded, so they will
43+
* WARNING: On < 7.1.0 connections, the title cell will be automatically modified among cells that have the same title when they are preloaded, so they will
4444
* always appear differently on-screen when they are displayed. Unique text will be created by appending " (2)", " (3)", etc.
4545
* @class
4646
* @param {String} title - The choice set's title
@@ -54,7 +54,11 @@ class ChoiceSet {
5454
// defaults
5555
this._defaultLayout = ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST;
5656
this._layout = this._defaultLayout;
57-
this._timeout = 10;
57+
this._defaultTimeout = 10;
58+
this._TIMEOUT_DEFAULT = 0;
59+
this._TIMEOUT_MIN_CAP = 5;
60+
this._TIMEOUT_MAX_CAP = 100;
61+
this._timeout = this._TIMEOUT_DEFAULT;
5862

5963
this._initialPrompt = null;
6064
this._timeoutPrompt = null;
@@ -85,11 +89,6 @@ class ChoiceSet {
8589
console.warn(`ChoiceSet: Attempted to create a choice set with a title of ${this.getTitle().length} length. Only 1 - 500 characters are supported.`);
8690
}
8791
}
88-
if (this.getTimeout() !== null) {
89-
if (this.getTimeout() < 5 || this.getTimeout() > 100) {
90-
console.warn(`ChoiceSet: Attempted to create a choice set with a ${this.getTimeout()} second timeout; Only 5 - 100 seconds is valid`);
91-
}
92-
}
9392
if (this.getChoices() !== null) {
9493
if (this.getChoices().length === 0 || this.getChoices().length > 100) {
9594
console.warn(`ChoiceSet: Attempted to create a choice set with ${this.getChoices().length} choices; Only 1 - 100 choices are valid`);
@@ -245,17 +244,24 @@ class ChoiceSet {
245244

246245
/**
247246
* Get the state timeout
248-
* @returns {Number} - The timeout
247+
* @returns {Number} - The timeout of a touch interaction in seconds (Manual/touch only)
249248
*/
250249
getTimeout () {
250+
if (this._timeout === this._TIMEOUT_DEFAULT) {
251+
return this.getDefaultTimeout();
252+
} else if (this._timeout < this._TIMEOUT_MIN_CAP) {
253+
return this._TIMEOUT_MIN_CAP;
254+
} else if (this._timeout > this._TIMEOUT_MAX_CAP) {
255+
return this._TIMEOUT_MAX_CAP;
256+
}
251257
return this._timeout;
252258
}
253259

254260
/**
255261
* Set the state timeout
256-
* Maps to PerformInteraction.timeout. This applies only to a manual selection (not a voice
257-
* selection, which has its timeout handled by the system). Defaults to `defaultTimeout`.
258-
* @param {Number} timeout - The timeout
262+
* Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`. If this is set below the minimum, it will be capped at 5 seconds. Minimum 5 seconds, maximum 100 seconds. If this is set above the maximum, it will be capped at 100 seconds. Defaults to 0.
263+
* This applies only to a manual selection (not a voice selection, which has its timeout handled by the system).
264+
* @param {Number} timeout - The timeout of a touch interaction in seconds (Manual/touch only)
259265
* @returns {ChoiceSet} - A reference to this instance to support method chaining
260266
*/
261267
setTimeout (timeout) {
@@ -264,6 +270,34 @@ class ChoiceSet {
264270
return this;
265271
}
266272

273+
/**
274+
* Get the state default timeout
275+
* @returns {Number} - The default timeout
276+
*/
277+
getDefaultTimeout () {
278+
if (this._defaultTimeout < this._TIMEOUT_MIN_CAP) {
279+
return this._TIMEOUT_MIN_CAP;
280+
} else if (this._defaultTimeout > this._TIMEOUT_MAX_CAP) {
281+
return this._TIMEOUT_MAX_CAP;
282+
}
283+
284+
return this._defaultTimeout;
285+
}
286+
287+
/**
288+
* Set the state default timeout
289+
* Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object
290+
* (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details.
291+
* If this is not set by you, it will default to 10 seconds. The minimum is 5 seconds, the maximum is 100 seconds.
292+
* If this is set below the minimum, it will be capped at 5 seconds. If this is set above the maximum, it will be capped at 100 seconds.
293+
* @param {Number} defaultTimeout - The default timeout
294+
* @returns {ChoiceSet} - A reference to this instance to support method chaining
295+
*/
296+
setDefaultTimeout (defaultTimeout) {
297+
this._defaultTimeout = defaultTimeout;
298+
return this;
299+
}
300+
267301
/**
268302
* Get the state choices
269303
* @returns {ChoiceCell[]} - The choices

lib/js/src/manager/screen/utils/AlertView.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AlertView {
4141
this._text = null;
4242
this._secondaryText = null;
4343
this._tertiaryText = null;
44-
this._timeout = null;
44+
this._timeout = AlertView._TIMEOUT_DEFAULT;
4545
this._audio = null;
4646
this._showWaitIndicator = false;
4747
this._softButtons = [];
@@ -197,10 +197,15 @@ class AlertView {
197197

198198
/**
199199
* Get the Timeout
200-
* @returns {Number} - the _defaultTimeout value
200+
* @returns {Number} - the AlertView._DEFAULT_TIMEOUT value
201201
*/
202202
getDefaultTimeout () {
203-
return AlertView._defaultTimeout;
203+
if (AlertView._DEFAULT_TIMEOUT < AlertView._TIMEOUT_MIN) {
204+
return AlertView._TIMEOUT_MIN;
205+
} else if (AlertView._DEFAULT_TIMEOUT > AlertView._TIMEOUT_MAX) {
206+
return AlertView._TIMEOUT_MAX;
207+
}
208+
return AlertView._DEFAULT_TIMEOUT;
204209
}
205210

206211
/**
@@ -214,14 +219,7 @@ class AlertView {
214219
* @returns {AlertView} - A reference to this instance to support method chaining.
215220
*/
216221
setDefaultTimeout (defaultTimeout) {
217-
if (defaultTimeout <= TIMEOUT_MIN) {
218-
AlertView._defaultTimeout = TIMEOUT_MIN;
219-
return this;
220-
} else if (defaultTimeout >= TIMEOUT_MAX) {
221-
AlertView._defaultTimeout = TIMEOUT_MAX;
222-
return this;
223-
}
224-
AlertView._defaultTimeout = defaultTimeout;
222+
AlertView._DEFAULT_TIMEOUT = defaultTimeout;
225223
return this;
226224
}
227225

@@ -242,14 +240,12 @@ class AlertView {
242240
* @returns {Number} - the timeout value
243241
*/
244242
getTimeout () {
245-
if (this._timeout === null || this._timeout === undefined) {
246-
this._timeout = AlertView._defaultTimeout;
247-
} else if (this._timeout === AlertView._defaultTimeout) {
248-
return AlertView._defaultTimeout;
249-
} else if (this._timeout < TIMEOUT_MIN) {
250-
return TIMEOUT_MIN;
251-
} else if (this._timeout > TIMEOUT_MAX) {
252-
return TIMEOUT_MAX;
243+
if (this._timeout === AlertView._TIMEOUT_DEFAULT) {
244+
this._timeout = this.getDefaultTimeout();
245+
} else if (this._timeout < AlertView._TIMEOUT_MIN) {
246+
return AlertView._TIMEOUT_MIN;
247+
} else if (this._timeout > AlertView._TIMEOUT_MAX) {
248+
return AlertView._TIMEOUT_MAX;
253249
}
254250
return this._timeout;
255251
}
@@ -304,8 +300,9 @@ class AlertView {
304300
}
305301
}
306302

307-
AlertView._defaultTimeout = 5;
308-
const TIMEOUT_MIN = 3;
309-
const TIMEOUT_MAX = 10;
303+
AlertView._TIMEOUT_DEFAULT = 0;
304+
AlertView._DEFAULT_TIMEOUT = 5;
305+
AlertView._TIMEOUT_MIN = 3;
306+
AlertView._TIMEOUT_MAX = 10;
310307

311308
export { AlertView };

tests/managers/screen/AlertViewTests.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,90 @@ module.exports = function (appClient) {
9696

9797
done();
9898
});
99+
100+
it('testReturnDefaultTimeoutForUnsetTimeout', function () {
101+
const alertView = new SDL.manager.screen.utils.AlertView();
102+
const testDefaultTimeout = 6;
103+
alertView.setDefaultTimeout(testDefaultTimeout);
104+
105+
Validator.assertEquals(alertView.getDefaultTimeout(), testDefaultTimeout);
106+
Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
107+
});
108+
109+
it('testReturnDefaultTimeoutForSetTimeout', function () {
110+
const alertView = new SDL.manager.screen.utils.AlertView();
111+
const testTimeout = 7;
112+
const testDefaultTimeout = 9;
113+
alertView.setDefaultTimeout(testDefaultTimeout);
114+
alertView.setTimeout(testTimeout);
115+
116+
Validator.assertEquals(alertView.getDefaultTimeout(), testDefaultTimeout);
117+
Validator.assertEquals(alertView.getTimeout(), testTimeout);
118+
});
119+
120+
it('testReturnDefaultMaxTimeout', function () {
121+
const alertView = new SDL.manager.screen.utils.AlertView();
122+
const testDefaultTimeout = 155;
123+
alertView.setDefaultTimeout(testDefaultTimeout);
124+
125+
Validator.assertEquals(alertView.getDefaultTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
126+
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
127+
});
128+
129+
it('testReturnDefaultMinTimeout', function () {
130+
const alertView = new SDL.manager.screen.utils.AlertView();
131+
const testDefaultTimeout = -3;
132+
alertView.setDefaultTimeout(testDefaultTimeout);
133+
134+
Validator.assertEquals(alertView.getDefaultTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
135+
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
136+
});
137+
138+
it('testReturnTimeoutUnset', function () {
139+
const alertView = new SDL.manager.screen.utils.AlertView();
140+
const testDefaultTimeout = 7;
141+
alertView.setDefaultTimeout(testDefaultTimeout);
142+
143+
Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
144+
});
145+
146+
it('testReturnTimeoutZero', function () {
147+
const alertView = new SDL.manager.screen.utils.AlertView();
148+
const testDefaultTimeout = 7;
149+
alertView.setDefaultTimeout(testDefaultTimeout);
150+
alertView.setTimeout(0);
151+
152+
Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
153+
});
154+
155+
it('testReturnTimeout', function () {
156+
const alertView = new SDL.manager.screen.utils.AlertView();
157+
const testDefaultTimeout = 7;
158+
const testTimeout = 9;
159+
alertView.setDefaultTimeout(testDefaultTimeout);
160+
alertView.setTimeout(testTimeout);
161+
162+
Validator.assertEquals(alertView.getTimeout(), testTimeout);
163+
});
164+
165+
it('testReturnMaxTimeout', function () {
166+
const alertView = new SDL.manager.screen.utils.AlertView();
167+
const testDefaultTimeout = 7;
168+
const testTimeout = 214;
169+
alertView.setDefaultTimeout(testDefaultTimeout);
170+
alertView.setTimeout(testTimeout);
171+
172+
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
173+
});
174+
175+
it('testReturnMinTimeout', function () {
176+
const alertView = new SDL.manager.screen.utils.AlertView();
177+
const testDefaultTimeout = 7;
178+
const testTimeout = 2.25;
179+
alertView.setDefaultTimeout(testDefaultTimeout);
180+
alertView.setTimeout(testTimeout);
181+
182+
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
183+
});
99184
});
100185
};

tests/managers/screen/choiceset/ChoiceSetTests.js

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,90 @@ module.exports = function (appClient) {
3131
choiceSet.cancel();
3232
Validator.assertTrue(canceledHandlerCalled);
3333
});
34+
35+
it('testReturnDefaultTimeoutForUnsetTimeout', function () {
36+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
37+
const testDefaultTimeout = 6;
38+
choiceSet.setDefaultTimeout(testDefaultTimeout);
39+
40+
Validator.assertEquals(choiceSet.getDefaultTimeout(), testDefaultTimeout);
41+
Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
42+
});
43+
44+
it('testReturnDefaultTimeoutForSetTimeout', function () {
45+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
46+
const testTimeout = 7;
47+
const testDefaultTimeout = 9;
48+
choiceSet.setDefaultTimeout(testDefaultTimeout);
49+
choiceSet.setTimeout(testTimeout);
50+
51+
Validator.assertEquals(choiceSet.getDefaultTimeout(), testDefaultTimeout);
52+
Validator.assertEquals(choiceSet.getTimeout(), testTimeout);
53+
});
54+
55+
it('testReturnDefaultMaxTimeout', function () {
56+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
57+
const testDefaultTimeout = 155;
58+
choiceSet.setDefaultTimeout(testDefaultTimeout);
59+
60+
Validator.assertEquals(choiceSet.getDefaultTimeout(), 100);
61+
Validator.assertEquals(choiceSet.getTimeout(), 100);
62+
});
63+
64+
it('testReturnDefaultMinTimeout', function () {
65+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
66+
const testDefaultTimeout = -3;
67+
choiceSet.setDefaultTimeout(testDefaultTimeout);
68+
69+
Validator.assertEquals(choiceSet.getDefaultTimeout(), 5);
70+
Validator.assertEquals(choiceSet.getTimeout(), 5);
71+
});
72+
73+
it('testReturnTimeoutUnset', function () {
74+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
75+
const testDefaultTimeout = 7;
76+
choiceSet.setDefaultTimeout(testDefaultTimeout);
77+
78+
Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
79+
});
80+
81+
it('testReturnTimeoutZero', function () {
82+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
83+
const testDefaultTimeout = 7;
84+
choiceSet.setDefaultTimeout(testDefaultTimeout);
85+
choiceSet.setTimeout(0);
86+
87+
Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
88+
});
89+
90+
it('testReturnTimeout', function () {
91+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
92+
const testDefaultTimeout = 7;
93+
const testTimeout = 9;
94+
choiceSet.setDefaultTimeout(testDefaultTimeout);
95+
choiceSet.setTimeout(testTimeout);
96+
97+
Validator.assertEquals(choiceSet.getTimeout(), testTimeout);
98+
});
99+
100+
it('testReturnMaxTimeout', function () {
101+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
102+
const testDefaultTimeout = 7;
103+
const testTimeout = 214;
104+
choiceSet.setDefaultTimeout(testDefaultTimeout);
105+
choiceSet.setTimeout(testTimeout);
106+
107+
Validator.assertEquals(choiceSet.getTimeout(), 100);
108+
});
109+
110+
it('testReturnMinTimeout', function () {
111+
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
112+
const testDefaultTimeout = 7;
113+
const testTimeout = 2.25;
114+
choiceSet.setDefaultTimeout(testDefaultTimeout);
115+
choiceSet.setTimeout(testTimeout);
116+
117+
Validator.assertEquals(choiceSet.getTimeout(), 5);
118+
});
34119
});
35-
};
120+
};

0 commit comments

Comments
 (0)