##// END OF EJS Templates
updated tests
updated tests

File last commit:

r144:63215d91ae4b v1.9.0-rc6 default
r152:956dc3113836 default
Show More
observable-store-tests.ts
88 lines | 2.3 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / observable-store-tests.ts
import Memory = require("dojo/store/Memory");
import Observerable = require("dojo/store/Observable");
import { get, queryEx } from "./store";
import tap = require("tap");
interface Person {
id: string;
name: string;
age: number;
}
tap.test("store::get(...) tests", async t => {
const store = new Observerable(new Memory<Person>());
const getPerson = get(store);
const peterId = "id:peter";
const samId = "id:sam";
const peter = getPerson(peterId);
const sam = getPerson(samId);
const seq1 = await getPerson(peterId, { observe: false }).collect();
t.ok(seq1.length === 0, "Should be empty sequence");
let peterChangeCount = 0;
let samChangeCount = 0;
let peterDeleted = 0;
const peterSubscription = peter.subscribe({
next: () => peterChangeCount++,
complete: () => peterDeleted++
});
const samSubscription = sam.subscribe({
next: () => samChangeCount++
});
try {
t.equal(peterChangeCount, 0, "Should be no changes recorded");
store.put({id: peterId, name: "Peter", age: 30 });
t.equal(peterChangeCount, 1, "Should record 1 object change");
t.equal(samChangeCount, 0, "Should not record other object changes");
store.remove(peterId);
t.equal(peterDeleted, 1, "Should complete sequence");
t.equal(peterChangeCount, 1, "Should not record remove operations");
store.put({id: peterId, name: "Peter", age: 29});
t.equal(peterChangeCount, 1, "Should not record changes after completion");
} finally {
peterSubscription.unsubscribe();
samSubscription.unsubscribe();
}
store.put({ id: samId, name: "Sam", age: 29});
const [data, updates] = queryEx(store)({ age: 29}, { sort: [{attribute: "id"}] });
const dump: string[] = [];
const subscription = data
.tap({
complete: () => dump.push("eof")
})
.cat(updates)
.tap({
next: ({item: {id}}) => dump.push(id),
complete: () => dump.push("eof")
})
.subscribe({});
t.same(dump, ["id:peter", "id:sam", "eof"]);
store.put({ id: "id:mary", name: "Mary", age: 29});
t.same(dump, ["id:peter", "id:sam", "eof", "id:mary"]);
subscription.unsubscribe();
}).catch(() => { });