Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: ensure signing out cannot cause any runtime render errors#13137

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Parkreiner merged 21 commits intomainfrommes/login-fix
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
21 commits
Select commitHold shift + click to select a range
4da94ef
fix: remove some of the jank around our core App component
ParkreinerMay 2, 2024
9986024
refactor: scope navigation logic more aggressively
ParkreinerMay 2, 2024
7004c9c
refactor: add explicit return type to useAuthenticated
ParkreinerMay 2, 2024
ebfaec5
refactor: clean up ProxyContext code
ParkreinerMay 2, 2024
1192eb3
wip: add code for consolidating the HTML metadata
ParkreinerMay 2, 2024
bbe2ae0
refactor: clean up hook logic
ParkreinerMay 2, 2024
1c41937
refactor: rename useHtmlMetadata to useEmbeddedMetadata
ParkreinerMay 2, 2024
79e9c45
fix: correct names that weren't updated
ParkreinerMay 2, 2024
81f2cd9
fix: update type-safety of useEmbeddedMetadata further
ParkreinerMay 2, 2024
390418f
wip: switch codebase to use metadata hook
ParkreinerMay 3, 2024
486f292
Merge branch 'main' into mes/login-fix
ParkreinerMay 3, 2024
b77af73
Merge branch 'mes/login-fix' of https://github.com/coder/coder into m…
ParkreinerMay 3, 2024
e072f7a
refactor: simplify design of metadata hook
ParkreinerMay 3, 2024
2a58322
fix: update stray type mismatches
ParkreinerMay 3, 2024
b55abb7
fix: more type fixing
ParkreinerMay 3, 2024
c45e1b7
fix: resolve illegal invocation error
ParkreinerMay 3, 2024
2a63c1d
fix: get metadata issue resolved
ParkreinerMay 3, 2024
4d3b155
fix: update comments
ParkreinerMay 3, 2024
8067e77
chore: add unit tests for MetadataManager
ParkreinerMay 3, 2024
5e6e974
fix: beef up tests
ParkreinerMay 3, 2024
772b96f
fix: update typo in tests
ParkreinerMay 3, 2024
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
PrevPrevious commit
NextNext commit
fix: beef up tests
  • Loading branch information
@Parkreiner
Parkreiner committedMay 3, 2024
commit5e6e974abf64a1022396041fc28aa641a0320e05
38 changes: 18 additions & 20 deletionssite/src/hooks/useEmbeddedMetadata.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
/**
* Qualities I want to test:
* 1. Logic is able to detect when specific types of metadata are available
* 2. Logic detects when metadata just doesn't exist
* 2. Lets external systems subscribe to React changes
* 3. Hook lets external systems know when metadata is deleted
* 4. Metadata is treated as an immutable value when anything is deleted
*
* Setup helpers I'll need
* 1. A way to populate the DOM with fake metadata nodes
*/
import { act, renderHook } from "@testing-library/react";
import type { Region } from "api/typesGenerated";
import type { Region, User } from "api/typesGenerated";
import {
MockAppearanceConfig,
MockBuildInfo,
Expand DownExpand Up@@ -192,9 +181,7 @@ describe(useEmbeddedMetadata.name, () => {
// itself
act(() => manager.clearMetadataByKey(tag1));
expect(reactResult.current.metadata).toEqual(expectedUpdate1);
expect(nonReactSubscriber).toBeCalledWith(
expect.objectContaining(expectedUpdate1),
);
expect(nonReactSubscriber).toBeCalledWith(expectedUpdate1);

nonReactSubscriber.mockClear();
const expectedUpdate2: RuntimeHtmlMetadata = {
Expand All@@ -209,13 +196,13 @@ describe(useEmbeddedMetadata.name, () => {
// through the React hooks
act(() => reactResult.current.clearMetadataByKey("appearance"));
expect(reactResult.current.metadata).toEqual(expectedUpdate2);
expect(nonReactSubscriber).toBeCalledWith(
expect.objectContaining(expectedUpdate2),
);
expect(nonReactSubscriber).toBeCalledWith(expectedUpdate2);

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", () => {
const key = "hamster";
const tagToDelete = "user";
Expand All@@ -226,9 +213,20 @@ describe(useEmbeddedMetadata.name, () => {
const initialResult = result.current.metadata;
act(() => result.current.clearMetadataByKey(tagToDelete));
const newResult = result.current.metadata;

// Need to use toBe, not toEqual here
expect(initialResult).not.toBe(newResult);

// Mutate the initial result, and make sure the change doesn't propagate to
// the updated result
const mutableUser = initialResult.user as {
available: boolean;
value: User | undefined;
};

mutableUser.available = false;
mutableUser.value = undefined;
expect(mutableUser).toEqual(newResult.user);
expect(mutableUser).not.toBe(newResult.user);

cleanupTags();
});
});
5 changes: 3 additions & 2 deletionssite/src/hooks/useEmbeddedMetadata.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,9 +16,10 @@ export const DEFAULT_METADATA_KEY = "property";
* so they will never exist when using a JavaScript runtime for the backend
*
* If you want to add new metadata in a type-safe way, add it to this type.
* Each key should the name of the "property" attribute that will be used on the
* HTML elements themselves (current selector is meta[property=${key}]), and the
* Each key shouldbethe name of the "property" attribute that will be used on
*theHTMLmetaelements themselves (e.g., meta[property=${key}]), and the
* values should be the data you get back from parsing those element's content
* attributes
*/
type AvailableMetadata = Readonly<{
user: User;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp