Martin Karkowski
c42dec645a
Fixing mapMethods, Adding additional Tests Fixing Testing Location in package.json
209 lines
5.1 KiB
TypeScript
209 lines
5.1 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, expect } from "chai";
|
|
import { describe, it } from "mocha";
|
|
import { extractUniqueValues } from "./mapMethods";
|
|
import { MapBasedMergeData, 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,
|
|
"Exactly one element different data has been added"
|
|
);
|
|
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,
|
|
"Exactly one element different data has been added"
|
|
);
|
|
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,
|
|
"Exactly one element has been added"
|
|
);
|
|
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,
|
|
"No element has been removed!"
|
|
);
|
|
done();
|
|
});
|
|
|
|
d.update(m);
|
|
});
|
|
});
|
|
|
|
describe("MapBasedMergeData", function () {
|
|
// Describe the required Test:
|
|
it("data handeling - flat data", function (done) {
|
|
const m = new Map<string, string>();
|
|
const d = new MapBasedMergeData(m);
|
|
m.set("a", "b");
|
|
m.set("b", "b");
|
|
|
|
d.update();
|
|
|
|
expect([...d.reverseSimplified.keys()]).contains("b");
|
|
|
|
|
|
done();
|
|
});
|
|
|
|
it("data handeling - flat data", function (done) {
|
|
const m = new Map<string, string[]>();
|
|
const d = new MapBasedMergeData(m);
|
|
m.set("a", ["a", "b"]);
|
|
m.set("b", ["c", "b"]);
|
|
|
|
d.update();
|
|
|
|
expect([...d.reverseSimplified.keys()]).contains("b");
|
|
|
|
|
|
done();
|
|
});
|
|
|
|
// Describe the required Test:
|
|
it("data subscription - simple data", function (done) {
|
|
const m = new Map<string, string>();
|
|
const d = new MapBasedMergeData(m);
|
|
m.set("a", "b");
|
|
m.set("b", "b");
|
|
|
|
d.update();
|
|
|
|
d.data.subscribe((result) => {
|
|
assert.isTrue(
|
|
result.length === 1,
|
|
"Exactly one element different data has been added"
|
|
);
|
|
assert.isTrue([...result][0] === "b", "Element is element");
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("data subscription - array data", function (done) {
|
|
const m = new Map<string, string[]>();
|
|
const d = new MapBasedMergeData(m);
|
|
m.set("a", ["a","b"]);
|
|
m.set("b", ["c", "b"]);
|
|
|
|
d.update();
|
|
|
|
d.data.subscribe((result) => {
|
|
assert.isTrue(
|
|
result.length === 3,
|
|
"The Element contains 3 different items."
|
|
);
|
|
|
|
expect([...result]).to.contain("a");
|
|
expect([...result]).to.contain("b");
|
|
expect([...result]).to.contain("c");
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("data subscription. Update called twice", function (done) {
|
|
const m = new Map<string, string>();
|
|
const d = new MapBasedMergeData(m);
|
|
m.set("a", "b");
|
|
m.set("b", "b");
|
|
d.update(m);
|
|
d.data.subscribe((result) => {
|
|
assert.isTrue(
|
|
result.length === 1,
|
|
"Exactly one element different data has been added"
|
|
);
|
|
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 MapBasedMergeData(m);
|
|
m.set("a", "b");
|
|
m.set("b", "b");
|
|
|
|
d.onChange.subscribe((result) => {
|
|
assert.isTrue(
|
|
result.added.length === 1,
|
|
"Exactly one element has been added"
|
|
);
|
|
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 MapBasedMergeData(m);
|
|
m.set("a", "b");
|
|
m.set("b", "b");
|
|
|
|
d.onChange.subscribe((result) => {
|
|
assert.isTrue(
|
|
result.removed.length === 0,
|
|
"No element has been removed!"
|
|
);
|
|
done();
|
|
});
|
|
|
|
d.update(m);
|
|
});
|
|
});
|