Skip to content

fix: add more tests for metadata hook functionality #13145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions site/src/hooks/useEmbeddedMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,39 @@ describe(useEmbeddedMetadata.name, () => {
cleanupTags();
});

it("Will delete the original metadata node when you try deleting a metadata state value", () => {
const key = "aardvark";
const tagToDelete: MetadataKey = "user";

const cleanupTags = seedInitialMetadata(key);
const { result } = renderMetadataHook(key);

const query = `meta[${key}=${tagToDelete}]`;
let userNode = document.querySelector(query);
expect(userNode).not.toBeNull();

act(() => result.current.clearMetadataByKey(tagToDelete));
userNode = document.querySelector(query);
expect(userNode).toBeNull();

cleanupTags();
});

it("Will not notify subscribers if you try deleting a metadata value that does not exist (or has already been deleted)", () => {
const key = "giraffe";
const tagToDelete: MetadataKey = "entitlements";

const cleanupTags = seedInitialMetadata(key);
const { result } = renderMetadataHook(key);
act(() => result.current.clearMetadataByKey(tagToDelete));

const resultBeforeNoOp = result.current.metadata;
act(() => result.current.clearMetadataByKey(tagToDelete));
expect(result.current.metadata).toBe(resultBeforeNoOp);

cleanupTags();
});

// Need to guarantee this, or else we could have a good number of bugs in the
// React UI
it("Always treats metadata as immutable values during all deletions", () => {
Expand Down
Loading