mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-28 15:46:58 +09:00
Ref https://github.com/webstudio-is/webstudio/issues/3632 Here I finally got rid from "rich-text-child" necessity. With html elements in the tree it will no longer work so we need a new way to work with rich text. Added a few new utilities to content model which detect rich text by text inside or any textual tags. Span and links can still be detected as containers rather than children when not surrounded by text and other textual elements.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { expect, test } from "vitest";
|
|
import { mapGroupBy, setDifference, setIsSubsetOf, setUnion } from "./shim";
|
|
|
|
test("Set.prototype.difference", () => {
|
|
// this set is bigger than other
|
|
expect(setDifference(new Set([1, 2, 3, 4]), new Set([3, 4, 5]))).toEqual(
|
|
new Set([1, 2])
|
|
);
|
|
// this set is smaller than other
|
|
expect(setDifference(new Set([1, 2, 3]), new Set([2, 3, 4, 5]))).toEqual(
|
|
new Set([1])
|
|
);
|
|
});
|
|
|
|
test("Set.prototype.union", () => {
|
|
expect(setUnion(new Set([2, 4, 6, 8]), new Set([1, 4, 9]))).toEqual(
|
|
new Set([2, 4, 6, 8, 1, 9])
|
|
);
|
|
});
|
|
|
|
test("Set.prototype.isSubsetOf", () => {
|
|
expect(setIsSubsetOf(new Set([1, 2, 3]), new Set([1, 2, 3]))).toBeTruthy();
|
|
expect(setIsSubsetOf(new Set([1, 2]), new Set([1, 2, 3]))).toBeTruthy();
|
|
expect(setIsSubsetOf(new Set(), new Set([1, 2, 3]))).toBeTruthy();
|
|
expect(setIsSubsetOf(new Set(), new Set())).toBeTruthy();
|
|
expect(setIsSubsetOf(new Set([1, 2, 3]), new Set([1, 2]))).toBeFalsy();
|
|
expect(setIsSubsetOf(new Set([1, 2, 3]), new Set())).toBeFalsy();
|
|
});
|
|
|
|
test("Map.groupBy", () => {
|
|
expect(mapGroupBy([1, 2, 3, 4, 5], (item) => item % 2)).toEqual(
|
|
new Map([
|
|
[0, [2, 4]],
|
|
[1, [1, 3, 5]],
|
|
])
|
|
);
|
|
});
|