Skip to content

Commit

Permalink
fix local storage restore on useRole with preserveURL (DevExpress#2015)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Jan 18, 2018
1 parent a56be53 commit 60b03d1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/errors/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export class ActionStringArgumentError extends ActionArgumentErrorBase {
}
}

export class ActionNullableStringArgumentError extends ActionArgumentErrorBase {
constructor (argumentName, actualValue) {
super(TYPE.actionNullableStringArgumentError, argumentName, actualValue);
}
}

export class ActionIntegerArgumentError extends ActionArgumentErrorBase {
constructor (argumentName, actualValue) {
super(TYPE.actionIntegerArgumentError, argumentName, actualValue);
Expand Down
4 changes: 4 additions & 0 deletions src/errors/test-run/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export default {
The "${err.argumentName}" argument is expected to be a non-empty string, but it was ${err.actualValue}.
`),

[TYPE.actionNullableStringArgumentError]: err => markup(err, `
The "${err.argumentName}" argument is expected to be a a null or a string, but it was ${err.actualValue}.
`),

[TYPE.actionStringOrStringArrayArgumentError]: err => markup(err, `
The "${err.argumentName}" argument is expected to be a non-empty string or a string array, but it was ${err.actualValue}.
`),
Expand Down
1 change: 1 addition & 0 deletions src/errors/test-run/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
actionSpeedOptionError: 'actionSpeedOptionError',
actionOptionsTypeError: 'actionOptionsTypeError',
actionStringArgumentError: 'actionStringArgumentError',
actionNullableStringArgumentError: 'actionNullableStringArgumentError',
actionStringOrStringArrayArgumentError: 'actionStringOrStringArrayArgumentError',
actionStringArrayElementError: 'actionStringArrayElementError',
actionIntegerArgumentError: 'actionIntegerArgumentError',
Expand Down
2 changes: 1 addition & 1 deletion src/test-run/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class TestRunBookmark {
var preserveUrl = this.role.opts.preserveUrl;
var url = preserveUrl ? this.role.url : this.url;

await this._restorePage(url, storages);
await this._restorePage(url, JSON.stringify(storages));

if (!preserveUrl)
await this._restoreWorkingFrame();
Expand Down
3 changes: 2 additions & 1 deletion src/test-run/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
integerArgument,
positiveIntegerArgument,
nonEmptyStringArgument,
nullableStringArgument,
urlArgument,
stringOrStringArrayArgument,
setSpeedArgument,
Expand Down Expand Up @@ -332,7 +333,7 @@ export class NavigateToCommand extends Assignable {
_getAssignableProperties () {
return [
{ name: 'url', type: urlArgument, required: true },
{ name: 'storages' }
{ name: 'storages', type: nullableStringArgument }
];
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test-run/commands/validations/argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ActionOptionsTypeError,
ActionBooleanArgumentError,
ActionStringArgumentError,
ActionNullableStringArgumentError,
ActionIntegerArgumentError,
ActionRoleArgumentError,
ActionPositiveIntegerArgumentError,
Expand Down Expand Up @@ -57,6 +58,15 @@ export function nonEmptyStringArgument (argument, val, createError) {
throw createError('""');
}

export function nullableStringArgument (argument, val) {
if (val === null) return;

var type = typeof val;

if (type !== 'string')
throw new ActionNullableStringArgumentError(argument, type);
}

export function urlArgument (name, val) {
nonEmptyStringArgument(name, val);

Expand Down
2 changes: 1 addition & 1 deletion src/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export default class TestRun extends Session {
const command = this.currentDriverTask.command;

if (command.type === COMMAND_TYPE.navigateTo && command.storages)
this.useStateSnapshot({ storages: command.storages });
this.useStateSnapshot({ storages: JSON.parse(command.storages) });

return command;
}
Expand Down

0 comments on commit 60b03d1

Please sign in to comment.