87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
|
/**
|
||
|
* @author Martin Karkowski
|
||
|
* @email m.karkowski@zema.de
|
||
|
* @create date 2021-11-13 08:17:19
|
||
|
* @modify date 2021-11-13 09:44:51
|
||
|
* @desc [description]
|
||
|
*/
|
||
|
|
||
|
import { assert } from "chai";
|
||
|
import "chai/register-should";
|
||
|
import { describe, it } from "mocha";
|
||
|
import { extractUniqueValues } from "./mapMethods";
|
||
|
import { MergeData } from "./mergedData";
|
||
|
|
||
|
describe("mergedData", function () {
|
||
|
// Describe the required Test:
|
||
|
it("data subscription", function (done) {
|
||
|
const m = new Map<string, string>();
|
||
|
const d = new MergeData(m, (m) => extractUniqueValues(m));
|
||
|
m.set("a", "b");
|
||
|
m.set("b", "b");
|
||
|
|
||
|
d.update();
|
||
|
|
||
|
d.data.subscribe((result) => {
|
||
|
assert.isTrue(
|
||
|
result.length === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result][0] === "b", "Element is element");
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("data subscription. Update called twice", function (done) {
|
||
|
const m = new Map<string, string>();
|
||
|
const d = new MergeData(m, (m) => extractUniqueValues(m));
|
||
|
m.set("a", "b");
|
||
|
m.set("b", "b");
|
||
|
d.update(m);
|
||
|
d.data.subscribe((result) => {
|
||
|
assert.isTrue(
|
||
|
result.length === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result][0] === "b", "Element is element");
|
||
|
done();
|
||
|
});
|
||
|
d.update(m);
|
||
|
});
|
||
|
|
||
|
it("onchange subscription: added", function (done) {
|
||
|
const m = new Map<string, string>();
|
||
|
const d = new MergeData(m, (m) => extractUniqueValues(m));
|
||
|
m.set("a", "b");
|
||
|
m.set("b", "b");
|
||
|
|
||
|
d.onChange.subscribe((result) => {
|
||
|
assert.isTrue(
|
||
|
result.added.length === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result.added][0] === "b", "Element is element");
|
||
|
done();
|
||
|
});
|
||
|
|
||
|
d.update(m);
|
||
|
});
|
||
|
|
||
|
it("onchange subscription: removed", function (done) {
|
||
|
const m = new Map<string, string>();
|
||
|
const d = new MergeData(m, (m) => extractUniqueValues(m));
|
||
|
m.set("a", "b");
|
||
|
m.set("b", "b");
|
||
|
|
||
|
d.onChange.subscribe((result) => {
|
||
|
assert.isTrue(
|
||
|
result.removed.length === 0,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
done();
|
||
|
});
|
||
|
|
||
|
d.update(m);
|
||
|
});
|
||
|
});
|