(
page: Page,
template: string | { organization: string; name: string },
options: CreateWorkspaceOptions = {},
)
| 107 | * to be running, but it does navigate to the page. |
| 108 | */ |
| 109 | export const createWorkspace = async ( |
| 110 | page: Page, |
| 111 | template: string | { organization: string; name: string }, |
| 112 | options: CreateWorkspaceOptions = {}, |
| 113 | ): Promise<string> => { |
| 114 | const { |
| 115 | richParameters = [], |
| 116 | buildParameters = [], |
| 117 | useExternalAuth, |
| 118 | } = options; |
| 119 | |
| 120 | const templatePath = |
| 121 | typeof template === "string" |
| 122 | ? template |
| 123 | : `${template.organization}/${template.name}`; |
| 124 | |
| 125 | await page.goto(`/templates/${templatePath}/workspace`, { |
| 126 | waitUntil: "domcontentloaded", |
| 127 | }); |
| 128 | await expectUrl(page).toHavePathName(`/templates/${templatePath}/workspace`); |
| 129 | |
| 130 | const name = randomName(); |
| 131 | await page.getByLabel("name").fill(name); |
| 132 | |
| 133 | if (buildParameters.length > 0) { |
| 134 | await page.waitForSelector("form", { state: "visible" }); |
| 135 | } |
| 136 | |
| 137 | await fillParameters(page, richParameters, buildParameters); |
| 138 | |
| 139 | if (useExternalAuth) { |
| 140 | // Create a new context for the popup which will be created when clicking the button |
| 141 | const popupPromise = page.waitForEvent("popup"); |
| 142 | |
| 143 | // Find the "Login with <Provider>" button |
| 144 | const externalAuthLoginButton = page |
| 145 | .getByRole("button") |
| 146 | .getByText("Login with GitHub"); |
| 147 | await expect(externalAuthLoginButton).toBeVisible(); |
| 148 | |
| 149 | // Click it |
| 150 | await externalAuthLoginButton.click(); |
| 151 | |
| 152 | // Wait for authentication to occur |
| 153 | const popup = await popupPromise; |
| 154 | await popup.waitForSelector("text=You are now authenticated."); |
| 155 | } |
| 156 | |
| 157 | await page.getByRole("button", { name: /create workspace/i }).click(); |
| 158 | |
| 159 | const user = currentUser(page); |
| 160 | await expectUrl(page).toHavePathName(`/@${user.username}/${name}`); |
| 161 | |
| 162 | await page.waitForSelector("text=Workspace status: Running", { |
| 163 | state: "visible", |
| 164 | }); |
| 165 | return name; |
| 166 | }; |
no test coverage detected