refactor(editor): Refactor utils files and mixins (#4654)

*  Added `utils` module. Moved `canvasHelpers` and old `utils.ts` file to it
*  Moved rest of utils and helpers
*  Fixing sytax errors
* 🔨 Refactoring new utils files
* 🔨 Organizing imports, adding comments and a bit more refactoring
* ✔️ Fixing tests
* 🔨 Moving mixins to `src`
This commit is contained in:
Milorad FIlipović
2022-11-23 13:41:53 +01:00
committed by GitHub
parent 67983e8f94
commit 5059c57f4a
167 changed files with 748 additions and 674 deletions

View File

@@ -0,0 +1,41 @@
import { isEmpty, intersection } from "@/utils";
describe("Utils", () => {
describe("isEmpty", () => {
it.each([
[undefined, true],
[null, true],
[{}, true],
[{ a: {}}, true],
[{ a: { b: []}}, true],
[{ a: { b: [1]}}, false],
[[], true],
[[{}, {}, {}], true],
[[{}, null, false], true],
[[{}, null, false, 1], false],
[[[], [], []], true],
["", true],
["0", false],
[0, false],
[1, false],
[false, true],
[true, false],
])(`for value %s should return %s`, (value, expected) => {
expect(isEmpty(value)).toBe(expected);
});
});
describe("intersection", () => {
it("should return the intersection of two arrays", () => {
expect(intersection([1, 2, 3], [2, 3, 4])).toEqual([2, 3]);
});
it("should return the intersection of two arrays without duplicates", () => {
expect(intersection([1, 2, 2, 3], [2, 2, 3, 4])).toEqual([2, 3]);
});
it("should return the intersection of four arrays without duplicates", () => {
expect(intersection([1, 2, 2, 3, 4], [2, 3, 3, 4], [2, 1, 5, 4, 4, 1], [2, 4, 5, 5, 6, 7])).toEqual([2, 4]);
});
});
});