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
60 changes: 47 additions & 13 deletions lib/js/src/manager/screen/choiceset/ChoiceSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class ChoiceSet {
/**
* Create a new instance of ChoiceSet
* Initialize with a title, choices, and listener. It will use the default timeout and layout, all other properties (such as prompts) will be null.
* WARNING: If you display multiple cells with the same title with the only uniquing property between cells being different `vrCommands` or a feature
* 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)
* WARNING: If you display multiple cells with the same title with the only uniquing property between cells being different `vrCommands` or a feature
* 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)
* then the cells may appear to be the same to the user in `Manual` mode. This only applies to RPC connections >= 7.1.0.
* 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
* 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
* always appear differently on-screen when they are displayed. Unique text will be created by appending " (2)", " (3)", etc.
* @class
* @param {String} title - The choice set's title
Expand All @@ -54,7 +54,11 @@ class ChoiceSet {
// defaults
this._defaultLayout = ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST;
this._layout = this._defaultLayout;
this._timeout = 10;
this._defaultTimeout = 10;
this._TIMEOUT_DEFAULT = 0;
this._TIMEOUT_MIN_CAP = 5;
this._TIMEOUT_MAX_CAP = 100;
this._timeout = this._TIMEOUT_DEFAULT;

this._initialPrompt = null;
this._timeoutPrompt = null;
Expand Down Expand Up @@ -85,11 +89,6 @@ class ChoiceSet {
console.warn(`ChoiceSet: Attempted to create a choice set with a title of ${this.getTitle().length} length. Only 1 - 500 characters are supported.`);
}
}
if (this.getTimeout() !== null) {
if (this.getTimeout() < 5 || this.getTimeout() > 100) {
console.warn(`ChoiceSet: Attempted to create a choice set with a ${this.getTimeout()} second timeout; Only 5 - 100 seconds is valid`);
}
}
if (this.getChoices() !== null) {
if (this.getChoices().length === 0 || this.getChoices().length > 100) {
console.warn(`ChoiceSet: Attempted to create a choice set with ${this.getChoices().length} choices; Only 1 - 100 choices are valid`);
Expand Down Expand Up @@ -245,17 +244,24 @@ class ChoiceSet {

/**
* Get the state timeout
* @returns {Number} - The timeout
* @returns {Number} - The timeout of a touch interaction in seconds (Manual/touch only)
*/
getTimeout () {
if (this._timeout === this._TIMEOUT_DEFAULT) {
return this.getDefaultTimeout();
} else if (this._timeout < this._TIMEOUT_MIN_CAP) {
return this._TIMEOUT_MIN_CAP;
} else if (this._timeout > this._TIMEOUT_MAX_CAP) {
return this._TIMEOUT_MAX_CAP;
}
return this._timeout;
}

/**
* Set the state timeout
* Maps to PerformInteraction.timeout. This applies only to a manual selection (not a voice
* selection, which has its timeout handled by the system). Defaults to `defaultTimeout`.
* @param {Number} timeout - The timeout
* 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.
* This applies only to a manual selection (not a voice selection, which has its timeout handled by the system).
* @param {Number} timeout - The timeout of a touch interaction in seconds (Manual/touch only)
* @returns {ChoiceSet} - A reference to this instance to support method chaining
*/
setTimeout (timeout) {
Expand All @@ -264,6 +270,34 @@ class ChoiceSet {
return this;
}

/**
* Get the state default timeout
* @returns {Number} - The default timeout
*/
getDefaultTimeout () {
if (this._defaultTimeout < this._TIMEOUT_MIN_CAP) {
return this._TIMEOUT_MIN_CAP;
} else if (this._defaultTimeout > this._TIMEOUT_MAX_CAP) {
return this._TIMEOUT_MAX_CAP;
}

return this._defaultTimeout;
}

/**
* Set the state default timeout
* Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object
* (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details.
* If this is not set by you, it will default to 10 seconds. The minimum is 5 seconds, the maximum is 100 seconds.
* 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.
* @param {Number} defaultTimeout - The default timeout
* @returns {ChoiceSet} - A reference to this instance to support method chaining
*/
setDefaultTimeout (defaultTimeout) {
this._defaultTimeout = defaultTimeout;
return this;
}

/**
* Get the state choices
* @returns {ChoiceCell[]} - The choices
Expand Down
41 changes: 19 additions & 22 deletions lib/js/src/manager/screen/utils/AlertView.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AlertView {
this._text = null;
this._secondaryText = null;
this._tertiaryText = null;
this._timeout = null;
this._timeout = AlertView._TIMEOUT_DEFAULT;
this._audio = null;
this._showWaitIndicator = false;
this._softButtons = [];
Expand Down Expand Up @@ -197,10 +197,15 @@ class AlertView {

/**
* Get the Timeout
* @returns {Number} - the _defaultTimeout value
* @returns {Number} - the AlertView._DEFAULT_TIMEOUT value
*/
getDefaultTimeout () {
return AlertView._defaultTimeout;
if (AlertView._DEFAULT_TIMEOUT < AlertView._TIMEOUT_MIN) {
return AlertView._TIMEOUT_MIN;
} else if (AlertView._DEFAULT_TIMEOUT > AlertView._TIMEOUT_MAX) {
return AlertView._TIMEOUT_MAX;
}
return AlertView._DEFAULT_TIMEOUT;
}

/**
Expand All @@ -214,14 +219,7 @@ class AlertView {
* @returns {AlertView} - A reference to this instance to support method chaining.
*/
setDefaultTimeout (defaultTimeout) {
if (defaultTimeout <= TIMEOUT_MIN) {
AlertView._defaultTimeout = TIMEOUT_MIN;
return this;
} else if (defaultTimeout >= TIMEOUT_MAX) {
AlertView._defaultTimeout = TIMEOUT_MAX;
return this;
}
AlertView._defaultTimeout = defaultTimeout;
AlertView._DEFAULT_TIMEOUT = defaultTimeout;
return this;
}

Expand All @@ -242,14 +240,12 @@ class AlertView {
* @returns {Number} - the timeout value
*/
getTimeout () {
if (this._timeout === null || this._timeout === undefined) {
this._timeout = AlertView._defaultTimeout;
} else if (this._timeout === AlertView._defaultTimeout) {
return AlertView._defaultTimeout;
} else if (this._timeout < TIMEOUT_MIN) {
return TIMEOUT_MIN;
} else if (this._timeout > TIMEOUT_MAX) {
return TIMEOUT_MAX;
if (this._timeout === AlertView._TIMEOUT_DEFAULT) {
this._timeout = this.getDefaultTimeout();
} else if (this._timeout < AlertView._TIMEOUT_MIN) {
return AlertView._TIMEOUT_MIN;
} else if (this._timeout > AlertView._TIMEOUT_MAX) {
return AlertView._TIMEOUT_MAX;
}
return this._timeout;
}
Expand Down Expand Up @@ -304,8 +300,9 @@ class AlertView {
}
}

AlertView._defaultTimeout = 5;
const TIMEOUT_MIN = 3;
const TIMEOUT_MAX = 10;
AlertView._TIMEOUT_DEFAULT = 0;
AlertView._DEFAULT_TIMEOUT = 5;
AlertView._TIMEOUT_MIN = 3;
AlertView._TIMEOUT_MAX = 10;

export { AlertView };
85 changes: 85 additions & 0 deletions tests/managers/screen/AlertViewTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,90 @@ module.exports = function (appClient) {

done();
});

it('testReturnDefaultTimeoutForUnsetTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 6;
alertView.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(alertView.getDefaultTimeout(), testDefaultTimeout);
Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
});

it('testReturnDefaultTimeoutForSetTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testTimeout = 7;
const testDefaultTimeout = 9;
alertView.setDefaultTimeout(testDefaultTimeout);
alertView.setTimeout(testTimeout);

Validator.assertEquals(alertView.getDefaultTimeout(), testDefaultTimeout);
Validator.assertEquals(alertView.getTimeout(), testTimeout);
});

it('testReturnDefaultMaxTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 155;
alertView.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(alertView.getDefaultTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
});

it('testReturnDefaultMinTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = -3;
alertView.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(alertView.getDefaultTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
});

it('testReturnTimeoutUnset', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 7;
alertView.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
});

it('testReturnTimeoutZero', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 7;
alertView.setDefaultTimeout(testDefaultTimeout);
alertView.setTimeout(0);

Validator.assertEquals(alertView.getTimeout(), testDefaultTimeout);
});

it('testReturnTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 7;
const testTimeout = 9;
alertView.setDefaultTimeout(testDefaultTimeout);
alertView.setTimeout(testTimeout);

Validator.assertEquals(alertView.getTimeout(), testTimeout);
});

it('testReturnMaxTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 7;
const testTimeout = 214;
alertView.setDefaultTimeout(testDefaultTimeout);
alertView.setTimeout(testTimeout);

Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MAX);
});

it('testReturnMinTimeout', function () {
const alertView = new SDL.manager.screen.utils.AlertView();
const testDefaultTimeout = 7;
const testTimeout = 2.25;
alertView.setDefaultTimeout(testDefaultTimeout);
alertView.setTimeout(testTimeout);

Validator.assertEquals(alertView.getTimeout(), SDL.manager.screen.utils.AlertView._TIMEOUT_MIN);
});
});
};
87 changes: 86 additions & 1 deletion tests/managers/screen/choiceset/ChoiceSetTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,90 @@ module.exports = function (appClient) {
choiceSet.cancel();
Validator.assertTrue(canceledHandlerCalled);
});

it('testReturnDefaultTimeoutForUnsetTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 6;
choiceSet.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(choiceSet.getDefaultTimeout(), testDefaultTimeout);
Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
});

it('testReturnDefaultTimeoutForSetTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testTimeout = 7;
const testDefaultTimeout = 9;
choiceSet.setDefaultTimeout(testDefaultTimeout);
choiceSet.setTimeout(testTimeout);

Validator.assertEquals(choiceSet.getDefaultTimeout(), testDefaultTimeout);
Validator.assertEquals(choiceSet.getTimeout(), testTimeout);
});

it('testReturnDefaultMaxTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 155;
choiceSet.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(choiceSet.getDefaultTimeout(), 100);
Validator.assertEquals(choiceSet.getTimeout(), 100);
});

it('testReturnDefaultMinTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = -3;
choiceSet.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(choiceSet.getDefaultTimeout(), 5);
Validator.assertEquals(choiceSet.getTimeout(), 5);
});

it('testReturnTimeoutUnset', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 7;
choiceSet.setDefaultTimeout(testDefaultTimeout);

Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
});

it('testReturnTimeoutZero', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 7;
choiceSet.setDefaultTimeout(testDefaultTimeout);
choiceSet.setTimeout(0);

Validator.assertEquals(choiceSet.getTimeout(), testDefaultTimeout);
});

it('testReturnTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 7;
const testTimeout = 9;
choiceSet.setDefaultTimeout(testDefaultTimeout);
choiceSet.setTimeout(testTimeout);

Validator.assertEquals(choiceSet.getTimeout(), testTimeout);
});

it('testReturnMaxTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 7;
const testTimeout = 214;
choiceSet.setDefaultTimeout(testDefaultTimeout);
choiceSet.setTimeout(testTimeout);

Validator.assertEquals(choiceSet.getTimeout(), 100);
});

it('testReturnMinTimeout', function () {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet(Test.GENERAL_STRING, choices, listener);
const testDefaultTimeout = 7;
const testTimeout = 2.25;
choiceSet.setDefaultTimeout(testDefaultTimeout);
choiceSet.setTimeout(testTimeout);

Validator.assertEquals(choiceSet.getTimeout(), 5);
});
});
};
};