forked from xiangechen/chili3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11c065b
commit b0df04d
Showing
5 changed files
with
250 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { Observable, PathBinding } from "../src"; | ||
|
||
class TestObjectValue extends Observable { | ||
get value(): string | undefined { | ||
return this.getPrivateValue("value", "value"); | ||
} | ||
set value(value: string | undefined) { | ||
this.setProperty("value", value); | ||
} | ||
} | ||
|
||
class TestObjectA extends Observable { | ||
get propA(): TestObjectValue | undefined { | ||
return this.getPrivateValue("propA"); | ||
} | ||
set propA(value: TestObjectValue | undefined) { | ||
this.setProperty("propA", value); | ||
} | ||
} | ||
|
||
class TestObjectB extends Observable { | ||
get propB(): TestObjectA | undefined { | ||
return this.getPrivateValue("propB"); | ||
} | ||
set propB(value: TestObjectA | undefined) { | ||
this.setProperty("propB", value); | ||
} | ||
|
||
get propC(): string | undefined { | ||
return this.getPrivateValue("propC", "propC"); | ||
} | ||
set propC(value: string | undefined) { | ||
this.setProperty("propC", value); | ||
} | ||
} | ||
|
||
describe("PathBinding test", () => { | ||
test("test PathBinding1", () => { | ||
let obj2 = new TestObjectB(); | ||
const binding = new PathBinding(obj2, "propB.propA.value"); | ||
let target = { value: "v1" }; | ||
binding.setBinding(target, "value"); | ||
expect(target.value).toBe("v1"); | ||
obj2.propB = new TestObjectA(); | ||
expect(target.value).toBe("v1"); | ||
|
||
let obj3 = new TestObjectValue(); | ||
obj2.propB.propA = obj3; | ||
expect(target.value).toBe("value"); | ||
obj2.propB.propA.value = "value2"; | ||
expect(target.value).toBe("value2"); | ||
|
||
obj2.propB = undefined; | ||
expect(target.value).toBe("value2"); | ||
obj3.value = "value3"; | ||
expect(target.value).toBe("value2"); | ||
|
||
obj2.propB = new TestObjectA(); | ||
expect(target.value).toBe("value2"); | ||
obj2.propB.propA = new TestObjectValue(); | ||
expect(target.value).toBe("value"); | ||
obj2.propB.propA = obj3; | ||
expect(target.value).toBe("value3"); | ||
|
||
obj2.propB = undefined; | ||
expect(target.value).toBe("value3"); | ||
obj3.value = "value"; | ||
expect(target.value).toBe("value3"); | ||
|
||
obj2.propB = new TestObjectA(); | ||
obj2.propB.propA = obj3; | ||
expect(target.value).toBe("value"); | ||
obj3.value = "value4"; | ||
expect(target.value).toBe("value4"); | ||
}); | ||
|
||
test("test PathBinding2", () => { | ||
let obj = new TestObjectB(); | ||
obj.propB = new TestObjectA(); | ||
obj.propB.propA = new TestObjectValue(); | ||
let target = { value1: "v1", value2: "v2" }; | ||
const binding1 = new PathBinding(obj, "propB.propA.value"); | ||
binding1.setBinding(target, "value1"); | ||
expect(target.value1).toBe("value"); | ||
|
||
const binding2 = new PathBinding(obj, "propC"); | ||
binding2.setBinding(target, "value2"); | ||
expect(target.value2).toBe("propC"); | ||
obj.propC = "propC2"; | ||
expect(target.value2).toBe("propC2"); | ||
}); | ||
}); |
Oops, something went wrong.