askui
Version:
Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on
26 lines (25 loc) • 1.04 kB
JavaScript
import { Action } from './action';
import { ControlCommandCode } from './control-command-code';
import { InputEvent } from './input-event';
export class ControlCommand {
constructor(code, actions, tryToRepeat = false) {
this.code = code;
this.actions = actions;
this.tryToRepeat = tryToRepeat;
}
static fromJson(json, resizeRatio = 1) {
const controlCommand = json;
return new ControlCommand(ControlCommandCode[controlCommand.code], controlCommand.actions.map((action) => Action.fromJson(action, resizeRatio)), controlCommand.tryToRepeat);
}
setTextToBeTyped(text) {
this.actions = this.actions.map((action) => ([InputEvent.TYPE, InputEvent.TYPE_TEXT].includes(action.inputEvent)
? new Action(action.inputEvent, action.position, text, action.parameters) : action));
}
toJson() {
return {
actions: this.actions.map((action) => action.toJson()),
code: this.code,
tryToRepeat: this.tryToRepeat,
};
}
}