-
Notifications
You must be signed in to change notification settings - Fork 989
chore(site): update and refactor all custom hook tests that rely on React Router #12219
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
Changes from 1 commit
0b186bf
a7a0944
ec3ba4f
6d7ef9f
afffb26
590f02b
9e00ea6
d7110c5
2cc63d7
26089e3
8057397
f8f87a3
dcc89dc
1ab6f03
b32603f
b0fabde
b94decc
3e41877
1fcf9e2
13f5e53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,14 @@ type RenderHookResult = RenderResult["result"]; | |
|
||
async function performNavigation( | ||
result: RenderHookResult, | ||
getSnapshot: GetLocationSnapshot, | ||
getLocationSnapshot: GetLocationSnapshot, | ||
) { | ||
await waitFor(() => expect(result.current.isDuplicationReady).toBe(true)); | ||
void act(() => result.current.duplicateWorkspace()); | ||
|
||
const templateName = MockWorkspace.template_name; | ||
return waitFor(() => { | ||
const { pathname } = getSnapshot(); | ||
const { pathname } = getLocationSnapshot(); | ||
expect(pathname).toEqual(`/templates/${templateName}/workspace`); | ||
}); | ||
} | ||
|
@@ -66,12 +66,6 @@ describe(`${useWorkspaceDuplication.name}`, () => { | |
}); | ||
|
||
test("Navigating populates the URL search params with the workspace's build params", async () => { | ||
const { result, getLocationSnapshot } = await render(MockWorkspace); | ||
await performNavigation(result, getLocationSnapshot); | ||
|
||
const { search } = getLocationSnapshot(); | ||
const parsedParams = new URLSearchParams(search); | ||
|
||
const mockBuildParams = [ | ||
M.MockWorkspaceBuildParameter1, | ||
M.MockWorkspaceBuildParameter2, | ||
|
@@ -80,27 +74,29 @@ describe(`${useWorkspaceDuplication.name}`, () => { | |
M.MockWorkspaceBuildParameter5, | ||
]; | ||
|
||
const { result, getLocationSnapshot } = await render(MockWorkspace); | ||
await performNavigation(result, getLocationSnapshot); | ||
|
||
const { search } = getLocationSnapshot(); | ||
for (const { name, value } of mockBuildParams) { | ||
const key = `param.${name}`; | ||
expect(parsedParams.get(key)).toEqual(value); | ||
expect(search.get(key)).toEqual(value); | ||
} | ||
}); | ||
|
||
test("Navigating appends other necessary metadata to the search params", async () => { | ||
const { result, getLocationSnapshot } = await render(MockWorkspace); | ||
await performNavigation(result, getLocationSnapshot); | ||
|
||
const { search } = getLocationSnapshot(); | ||
const parsedParams = new URLSearchParams(search); | ||
|
||
const extraMetadataEntries = [ | ||
const extraMetadataEntries: readonly [string, string][] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the switch from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt like it would surface any accidental errors in a better way, and that it does a better job of communicating intent With the previous code, I could do something like this: const extraMetadataEntries = [
["mode", "duplicate"],
["name", `${MockWorkspace.name}-copy`],
["version", MockWorkspace.template_active_version_id],
function obviouslyWrong() {},
null,
["forgotToAddTheSecondTupleElement"]
] as const; And this would be valid still – the underlying type would get broadened. So while the type mismatch would get caught down the line, redefining the type to be an array of string tuples tells you what types should go in, and is more defensive against typos |
||
["mode", "duplicate"], | ||
["name", `${MockWorkspace.name}-copy`], | ||
["version", MockWorkspace.template_active_version_id], | ||
] as const; | ||
]; | ||
|
||
const { result, getLocationSnapshot } = await render(MockWorkspace); | ||
await performNavigation(result, getLocationSnapshot); | ||
|
||
const { search } = getLocationSnapshot(); | ||
for (const [key, value] of extraMetadataEntries) { | ||
expect(parsedParams.get(key)).toBe(value); | ||
expect(search.get(key)).toBe(value); | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another
void
/await
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup – will fix