Files
webstudio/apps/builder/app/shared/array-utils.test.ts
T
Bogdan Chadkin 59b9c6fedc Support cross-project instance copy paste (#1326)
Here a little refactored copy paste instance plugin.

Now we copy all data including slots and tokens though paste write them
as is or do not write at all if already exist.

This let us to not do unnecessary patches for copy paste within project
while still have whole UI pasted in different project.

There is still a problem with pasting styles which always have different
breakpoint ids in each project. We will need to implement merging in
other PR.
2023-03-31 11:38:19 +07:00

65 lines
1.2 KiB
TypeScript

import { expect, test } from "@jest/globals";
import {
getMapValuesBy,
getMapValuesByKeysSet,
removeByMutable,
} from "./array-utils";
test("removeByMutable", () => {
const array = [
{ param: 1 },
{ param: 2 },
{ param: 3 },
{ param: 4 },
{ param: 5 },
{ param: 6 },
];
removeByMutable(array, (item) => item.param % 2 === 1);
expect(array).toMatchInlineSnapshot(`
[
{
"param": 2,
},
{
"param": 4,
},
{
"param": 6,
},
]
`);
removeByMutable(array, (item) => item.param !== 4);
expect(array).toMatchInlineSnapshot(`
[
{
"param": 4,
},
]
`);
});
test("getMapValuesByKeysSet", () => {
const map = new Map([
[1, "value1"],
[2, "value2"],
[3, "value3"],
[4, "value4"],
[5, "value5"],
]);
const keys = new Set([2, 4]);
expect(getMapValuesByKeysSet(map, keys)).toEqual(["value2", "value4"]);
});
test("getMapValuesBy", () => {
const map = new Map([
[1, "value1"],
[2, "value2"],
[3, "value3"],
[4, "value4"],
[5, "value5"],
]);
expect(
getMapValuesBy(map, (value) => value.includes("3") || value.includes("5"))
).toEqual(["value3", "value5"]);
});