|
1 | | -import {getModifiableCmdAttributes, isCmdModifiable, modifyCmdAttributes} from "../../../src/interacto"; |
| 1 | +import {getModifiableCmdAttributes, isCmdModifiable, Modifiable, modifyCmdAttributes} from "../../src/interacto"; |
2 | 2 | import {beforeEach, describe, expect, test} from "@jest/globals"; |
3 | | -import type {UndoableCommand} from "../../../src/interacto"; |
4 | | -import {CmdModifiableDouble, CmdModifiableDouble2, CmdModifiableDouble3} from "../StubCmd"; |
| 3 | +import type {UndoableCommand} from "../../src/interacto"; |
| 4 | +import {CmdModifiableDouble, CmdModifiableDouble2, CmdModifiableDouble3, ExampleUndoableCmd} from "./StubCmd"; |
| 5 | + |
| 6 | +class CmdModifiableGet extends ExampleUndoableCmd { |
| 7 | + public theX = 10; |
| 8 | + |
| 9 | + @Modifiable |
| 10 | + public get x(): number { |
| 11 | + return this.theX; |
| 12 | + } |
| 13 | + |
| 14 | + public set x(value: number) { |
| 15 | + this.theX = value; |
| 16 | + } |
| 17 | +} |
5 | 18 |
|
6 | 19 | describe("using a modifiable decorator on commands", () => { |
7 | 20 | describe("and an undoable command", () => { |
@@ -101,6 +114,15 @@ describe("using a modifiable decorator on commands", () => { |
101 | 114 | expect(attributes).toStrictEqual({"a": 0, "b": false}); |
102 | 115 | }); |
103 | 116 |
|
| 117 | + test("get modifiable properties on getter", () => { |
| 118 | + const cmd2 = new CmdModifiableGet(); |
| 119 | + const res = modifyCmdAttributes(cmd2, { |
| 120 | + "x": 42 |
| 121 | + }); |
| 122 | + expect(res).toBeTruthy(); |
| 123 | + expect(cmd2.theX).toBe(42); |
| 124 | + }); |
| 125 | + |
104 | 126 | describe("and an undoable command with incorrect usages of Modifiable", () => { |
105 | 127 | test("get modifiable properties does not include the ones badly typed", () => { |
106 | 128 | expect(getModifiableCmdAttributes(new CmdModifiableDouble3())).toStrictEqual({}); |
|
0 commit comments