2022-08-16 14:05:03 +02:00
|
|
|
import { BehaviorSubject } from "rxjs";
|
|
|
|
|
|
|
|
import { sessionSync } from "./session-sync.decorator";
|
|
|
|
|
|
|
|
describe("sessionSync decorator", () => {
|
|
|
|
const initializer = (s: string) => "test";
|
|
|
|
class TestClass {
|
2023-02-16 16:36:50 +01:00
|
|
|
@sessionSync({ initializer: initializer })
|
2022-11-01 11:25:46 +01:00
|
|
|
private testProperty = new BehaviorSubject("");
|
2023-02-16 16:36:50 +01:00
|
|
|
@sessionSync({ initializer: initializer, initializeAs: "array" })
|
2022-11-30 00:40:39 +01:00
|
|
|
private secondTestProperty = new BehaviorSubject("");
|
2022-11-01 11:25:46 +01:00
|
|
|
|
|
|
|
complete() {
|
|
|
|
this.testProperty.complete();
|
2022-11-30 00:40:39 +01:00
|
|
|
this.secondTestProperty.complete();
|
2022-11-01 11:25:46 +01:00
|
|
|
}
|
2022-08-16 14:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
it("should add __syncedItemKeys to prototype", () => {
|
|
|
|
const testClass = new TestClass();
|
|
|
|
expect((testClass as any).__syncedItemMetadata).toEqual([
|
|
|
|
expect.objectContaining({
|
2022-08-16 17:59:50 +02:00
|
|
|
propertyKey: "testProperty",
|
2022-11-30 00:40:39 +01:00
|
|
|
sessionKey: "testProperty_0",
|
|
|
|
initializer: initializer,
|
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
|
|
|
propertyKey: "secondTestProperty",
|
|
|
|
sessionKey: "secondTestProperty_1",
|
|
|
|
initializer: initializer,
|
|
|
|
initializeAs: "array",
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
testClass.complete();
|
|
|
|
});
|
|
|
|
|
|
|
|
class TestClass2 {
|
2023-02-16 16:36:50 +01:00
|
|
|
@sessionSync({ initializer: initializer })
|
2022-11-30 00:40:39 +01:00
|
|
|
private testProperty = new BehaviorSubject("");
|
|
|
|
|
|
|
|
complete() {
|
|
|
|
this.testProperty.complete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it("should maintain sessionKey index count for other test classes", () => {
|
|
|
|
const testClass = new TestClass2();
|
|
|
|
expect((testClass as any).__syncedItemMetadata).toEqual([
|
|
|
|
expect.objectContaining({
|
|
|
|
propertyKey: "testProperty",
|
|
|
|
sessionKey: "testProperty_2",
|
2022-08-16 14:05:03 +02:00
|
|
|
initializer: initializer,
|
|
|
|
}),
|
|
|
|
]);
|
2022-11-30 00:40:39 +01:00
|
|
|
testClass.complete();
|
2022-08-16 14:05:03 +02:00
|
|
|
});
|
|
|
|
});
|