Skip to content

Commit 7d9c897

Browse files
committed
test(history): adding more tests with decorators on getters
1 parent c501a67 commit 7d9c897

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

test/command/library/ModifiableCommand.test.ts renamed to test/command/ModifiableCommand.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import {getModifiableCmdAttributes, isCmdModifiable, modifyCmdAttributes} from "../../../src/interacto";
1+
import {getModifiableCmdAttributes, isCmdModifiable, Modifiable, modifyCmdAttributes} from "../../src/interacto";
22
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+
}
518

619
describe("using a modifiable decorator on commands", () => {
720
describe("and an undoable command", () => {
@@ -101,6 +114,15 @@ describe("using a modifiable decorator on commands", () => {
101114
expect(attributes).toStrictEqual({"a": 0, "b": false});
102115
});
103116

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+
104126
describe("and an undoable command with incorrect usages of Modifiable", () => {
105127
test("get modifiable properties does not include the ones badly typed", () => {
106128
expect(getModifiableCmdAttributes(new CmdModifiableDouble3())).toStrictEqual({});
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ class CmdEditParagraph extends ExampleUndoableCmd {
4747
}
4848
}
4949

50+
class CmdEditParagraph2 extends ExampleUndoableCmd {
51+
public paragraph: Paragraph;
52+
53+
public txt: Txt;
54+
55+
public constructor(para: Paragraph, txt: Txt) {
56+
super();
57+
this.paragraph = para;
58+
this.txt = txt;
59+
}
60+
61+
@Selective
62+
public get paragraphId(): number {
63+
return this.paragraph.id;
64+
}
65+
}
66+
5067
describe("using a selective command", () => {
5168
afterEach(() => {
5269
jest.clearAllMocks();
@@ -225,7 +242,6 @@ describe("using a selective command", () => {
225242
const res = [...history.getAllSelectiveObjects()];
226243
expect(res).toHaveLength(1);
227244
expect(res).toContain(cmd1.key);
228-
// expect(res).toContain(cmd2.otherKey);
229245
});
230246

231247
test("getAllSelectiveObjects works with several keys", () => {
@@ -303,5 +319,13 @@ describe("using a selective command", () => {
303319
expect(res[1]).toHaveLength(0);
304320
expect(res[0]).toStrictEqual([[cmd1, 0], [cmd4, 3], [cmd5, 4]]);
305321
});
322+
323+
test("getAllSelectiveObjects works with getters", () => {
324+
history = new LinearHistoryImpl();
325+
history.add(new CmdEditParagraph2(p1, txt));
326+
const res = [...history.getAllSelectiveObjects()];
327+
expect(res).toHaveLength(1);
328+
expect(res[0]).toBe(p1.id);
329+
});
306330
});
307331
});

0 commit comments

Comments
 (0)