nope/lib/helpers/mergedData.spec.ts
Martin Karkowski d911380511 # 1.0.27
- Fixes:
  - helpers.jsonSchemaMethods: -> renamed flatten to nested.
- Added:
  - helpers.descriptors: -> parseFunctionToJsonSchema
  - helpers.jsonSchemaMethods: -> added `flattenSchema` and `reduceSchema`. This Function will create a nested JSON-Schema.
2022-03-22 10:12:32 +01:00

205 lines
5.0 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @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);
});
});