- Notifications
You must be signed in to change notification settings - Fork921
feat(site): support match option for auto create workspace flow#13836
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
48d0e39
6b6b32c
d9cb7ba
a64cdcd
dac8ada
1584695
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { username } from "../../constants"; | ||
import { | ||
createTemplate, | ||
createWorkspace, | ||
echoResponsesWithParameters, | ||
} from "../../helpers"; | ||
import { emptyParameter } from "../../parameters"; | ||
import type { RichParameter } from "../../provisionerGenerated"; | ||
test("create workspace in auto mode", async ({ page }) => { | ||
const richParameters: RichParameter[] = [ | ||
{ ...emptyParameter, name: "repo", type: "string" }, | ||
]; | ||
const template = await createTemplate( | ||
page, | ||
echoResponsesWithParameters(richParameters), | ||
); | ||
const name = "test-workspace"; | ||
await page.goto( | ||
`/templates/${template}/workspace?mode=auto¶m.repo=example&name=${name}`, | ||
{ | ||
waitUntil: "domcontentloaded", | ||
}, | ||
); | ||
await expect(page).toHaveTitle(`${username}/${name} - Coder`); | ||
}); | ||
test("use an existing workspace that matches the `match` parameter instead of creating a new one", async ({ | ||
page, | ||
}) => { | ||
const richParameters: RichParameter[] = [ | ||
{ ...emptyParameter, name: "repo", type: "string" }, | ||
]; | ||
const template = await createTemplate( | ||
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 haven't worked with the E2E stuff much yet, so just to make sure I'm understanding: these testsaren't isolated, right? That's how the second test is able to have a workspace already exist, even though it didn't explicitly make two of them? 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. They are not isolated, but I ensure that a previous workspace with the right match exists in line 39. | ||
page, | ||
echoResponsesWithParameters(richParameters), | ||
); | ||
const prevWorkspace = await createWorkspace(page, template); | ||
await page.goto( | ||
`/templates/${template}/workspace?mode=auto¶m.repo=example&name=new-name&match=name:${prevWorkspace}`, | ||
{ | ||
waitUntil: "domcontentloaded", | ||
}, | ||
); | ||
await expect(page).toHaveTitle(`${username}/${prevWorkspace} - Coder`); | ||
}); | ||
test("show error if `match` parameter is invalid", async ({ page }) => { | ||
const richParameters: RichParameter[] = [ | ||
{ ...emptyParameter, name: "repo", type: "string" }, | ||
]; | ||
const template = await createTemplate( | ||
page, | ||
echoResponsesWithParameters(richParameters), | ||
); | ||
const prevWorkspace = await createWorkspace(page, template); | ||
await page.goto( | ||
`/templates/${template}/workspace?mode=auto¶m.repo=example&name=new-name&match=not-valid-query:${prevWorkspace}`, | ||
{ | ||
waitUntil: "domcontentloaded", | ||
}, | ||
); | ||
await expect(page.getByText("Invalid match value")).toBeVisible(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -16,7 +16,6 @@ import type { | ||
UserParameter, | ||
Workspace, | ||
} from "api/typesGenerated"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
import { useEffectEvent } from "hooks/hookPolyfills"; | ||
@@ -37,7 +36,7 @@ const CreateWorkspacePage: FC = () => { | ||
const { template: templateName } = useParams() as { template: string }; | ||
const { user: me } = useAuthenticated(); | ||
const navigate = useNavigate(); | ||
const [searchParams] = useSearchParams(); | ||
const { experiments, organizationId } = useDashboard(); | ||
const customVersionId = searchParams.get("version") ?? undefined; | ||
@@ -118,15 +117,15 @@ const CreateWorkspacePage: FC = () => { | ||
const newWorkspace = await autoCreateWorkspaceMutation.mutateAsync({ | ||
templateName, | ||
organizationId, | ||
buildParameters: autofillParameters, | ||
workspaceName: defaultName ?? generateWorkspaceName(), | ||
templateVersionId: realizedVersionId, | ||
match: searchParams.get("match"), | ||
}); | ||
onCreateWorkspace(newWorkspace); | ||
} catch (err) { | ||
setMode("form"); | ||
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'm wondering if it might still be good to update the search params on top of the state change, but good catch with this 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've thought about this and I don't think it makes much of a difference in the user experience, based on what I can see. Since no other part of the component uses it, I just removed it and decided to set the mode only in the state. | ||
} | ||
}); | ||
@@ -175,7 +174,6 @@ const CreateWorkspacePage: FC = () => { | ||
<Helmet> | ||
<title>{pageTitle(title)}</title> | ||
</Helmet> | ||
{isLoadingFormData || isLoadingExternalAuth || autoCreateReady ? ( | ||
<Loader /> | ||
) : ( | ||
@@ -185,7 +183,12 @@ const CreateWorkspacePage: FC = () => { | ||
disabledParams={disabledParams} | ||
defaultOwner={me} | ||
autofillParameters={autofillParameters} | ||
error={ | ||
createWorkspaceMutation.error || | ||
autoCreateError || | ||
loadFormDataError || | ||
autoCreateWorkspaceMutation.error | ||
} | ||
resetMutation={createWorkspaceMutation.reset} | ||
template={templateQuery.data!} | ||
versionId={realizedVersionId} | ||
Uh oh!
There was an error while loading.Please reload this page.