Skip to content

Commit ead31de

Browse files
committed
Fix setting choice set timeouts
1 parent 88907de commit ead31de

2 files changed

Lines changed: 133 additions & 14 deletions

File tree

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

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)