(
page: Page,
username: keyof typeof testUsers,
options: {waitFor: 'idle' | 'syncing' | 'error'} = {waitFor: 'idle'},
)
| 191 | } |
| 192 | } |
| 193 | |
| 194 | export async function loginAsUser( |
| 195 | page: Page, |
| 196 | username: keyof typeof testUsers, |
| 197 | options: {waitFor: 'idle' | 'syncing' | 'error'} = {waitFor: 'idle'}, |
| 198 | ) { |
| 199 | // Set Wiremock scenario state based on the user. |
| 200 | await setUserWiremockScenarioState(page, username); |
| 201 | |
| 202 | // Clicking the log in button will create a popup that we need to capture. |
| 203 | const popupPromise = page.waitForEvent('popup'); |
| 204 | await page.goto('http://localhost:5555/'); |
| 205 | await waitForSidebarLoaded(page); |
| 206 | await page.getByRole('banner').getByText('Log in').click(); |
| 207 | const popup = await popupPromise; |
| 208 | |
| 209 | await popup.waitForLoadState(); |
| 210 | await popup.getByText(username).waitFor({timeout: 5000}); |
| 211 | await popup.getByText(username).hover(); // Needed for Firefox for some reason. |
| 212 | await popup.getByText(username).click(); |
| 213 | await popup.waitForEvent('close'); |
| 214 | |
| 215 | const email = testUsers[username]; |
| 216 | const loginButton = page.getByRole('button', {name: email}); |
| 217 | |
| 218 | // Wait for the button to become visible on the main page. |
| 219 | await expect(loginButton).toBeVisible(); |
| 220 | |
| 221 | switch (options.waitFor) { |
| 222 | case 'syncing': |
| 223 | // Wait for the loading spinner on the user button to appear. |
| 224 | await expect(loginButton.locator('sl-spinner')).toBeVisible(); |
| 225 | break; |
| 226 | case 'error': |
| 227 | // Wait for the error icon to be present in the DOM. |
| 228 | await expect( |
| 229 | page |
| 230 | .getByTestId('error-while-syncing-button') |
| 231 | .getByTestId('error-icon'), |
| 232 | ).toBeVisible(); |
| 233 | break; |
| 234 | case 'idle': |
| 235 | default: |
| 236 | // Wait for the loading spinner on the user button to disappear. |
| 237 | await expect(loginButton.locator('sl-spinner')).toBeHidden(); |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | export async function dismissToast(page: Page) { |
no test coverage detected