mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 20:35:39 -06:00
9aead8a897
Co-authored-by: Peter Steinberger <steipete@mac-studio-sf2.local>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
appendArrayRowIdentities,
|
|
discardArrayRowIdentities,
|
|
preserveArrayRowIdentities,
|
|
rowIdentitiesForArray,
|
|
} from "./config-form-array-identity.ts";
|
|
|
|
describe("config form array row identity", () => {
|
|
it("keeps appended primitive identities unique after an equal row is removed", () => {
|
|
const initial = ["same", "same"];
|
|
const initialIdentities = rowIdentitiesForArray(initial);
|
|
const afterRemoval = ["same"];
|
|
preserveArrayRowIdentities(afterRemoval, initialIdentities.slice(1));
|
|
|
|
const afterAppend = ["same", "same"];
|
|
appendArrayRowIdentities(afterAppend, rowIdentitiesForArray(afterRemoval), 1);
|
|
const appendedIdentities = rowIdentitiesForArray(afterAppend);
|
|
|
|
expect(new Set(appendedIdentities).size).toBe(appendedIdentities.length);
|
|
expect(appendedIdentities[0]).toBe(initialIdentities[1]);
|
|
});
|
|
|
|
it("removes row metadata from rejected candidate arrays", () => {
|
|
const candidate = ["same"];
|
|
const rejectedIdentity = Symbol("rejected-row");
|
|
preserveArrayRowIdentities(candidate, [rejectedIdentity]);
|
|
discardArrayRowIdentities(candidate);
|
|
|
|
expect(rowIdentitiesForArray(candidate)[0]).not.toBe(rejectedIdentity);
|
|
});
|
|
});
|