Skip to content

Commit

Permalink
Merge pull request #5181 from hallieswan/SWC-6531
Browse files Browse the repository at this point in the history
SWC-6531/SWC-6536: fixes for using a larger runner and SRC methods
  • Loading branch information
hallieswan authored Sep 8, 2023
2 parents be7306b + 95bc7b6 commit ad83c64
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions e2e/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
loginTestUser,
} from './helpers/testUser'
import { userConfigs } from './helpers/userConfig'
import { waitForInitialPageLoad } from './helpers/utils'

for (const {
testName,
Expand All @@ -28,6 +29,8 @@ for (const {
setup.describe(`Setup: ${testName}`, () => {
setup.beforeAll(async ({ browser }) => {
userPage = await browser.newPage()
await userPage.goto('/')
await waitForInitialPageLoad(userPage)
})

setup('create and authenticate user', async () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/create_account.loggedout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test'
import { waitForInitialPageLoad } from './helpers/testUser'
import { waitForInitialPageLoad } from './helpers/utils'

test.describe('Create Account', () => {
test('should show an alert when an invalid email address is used', async ({
Expand Down
2 changes: 1 addition & 1 deletion e2e/helpers/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Page, expect } from '@playwright/test'
import { navigateToHomepageIfPageHasNotBeenLoaded } from './localStorage'
import { navigateToHomepageIfPageHasNotBeenLoaded } from './utils'

export enum BackendDestinationEnum {
REPO_ENDPOINT,
Expand Down
8 changes: 1 addition & 7 deletions e2e/helpers/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Page } from '@playwright/test'

export async function navigateToHomepageIfPageHasNotBeenLoaded(page: Page) {
if (page.url() === 'about:blank') {
// Navigate to homepage, so that localStorage is available
await page.goto('/')
}
}
import { navigateToHomepageIfPageHasNotBeenLoaded } from './utils'

export async function setLocalStorage(page: Page, key: string, value: string) {
await navigateToHomepageIfPageHasNotBeenLoaded(page)
Expand Down
15 changes: 7 additions & 8 deletions e2e/helpers/testUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Page, expect } from '@playwright/test'
import { BackendDestinationEnum, doDelete, doPost } from './http'
import { getLocalStorage } from './localStorage'
import { LoginResponse, TestUser } from './types'
import { waitForInitialPageLoad } from './utils'
import { deleteVerificationSubmissionIfExists } from './verification'

const BASE64_ENCODING = 'base64'
Expand Down Expand Up @@ -59,14 +60,6 @@ export async function cleanupTestUser(testUserId: string, userPage: Page) {
expect(result).toEqual(testUserId)
}

// Use after initially navigating to baseURL
// ...to give SWC time to compile, if necessary
export async function waitForInitialPageLoad(page: Page) {
await expect(page.getByRole('heading', { name: 'Loading…' })).not.toBeVisible(
{ timeout: 2 * 60 * 1000 }, // ...wait 2 minutes if necessary
)
}

export async function loginTestUser(
page: Page,
testUserName: string,
Expand All @@ -82,6 +75,11 @@ export async function loginTestUser(
await page.getByLabel('Password').fill(testUserPassword)
await page.getByRole('button', { name: 'Sign in' }).click()

// Wait for redirect
await expect(async () => {
expect(page.url()).not.toContain('LoginPlace')
}).toPass()

// Wait until the page reaches a state where all cookies are set
await expect(page.getByLabel('Search')).toBeVisible()
await expect(page.getByLabel('Projects')).toBeVisible()
Expand All @@ -92,6 +90,7 @@ export async function loginTestUser(

export async function goToDashboard(page: Page) {
await page.goto('/')
await waitForInitialPageLoad(page)
await page.getByRole('link', { name: 'View Your Dashboard' }).first().click()

// wait for page to load
Expand Down
17 changes: 17 additions & 0 deletions e2e/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page, expect } from '@playwright/test'

// Use after initially navigating to baseURL
// ...to give SWC time to compile, if necessary
export async function waitForInitialPageLoad(page: Page) {
await expect(page.getByRole('heading', { name: 'Loading…' })).not.toBeVisible(
{ timeout: 2 * 60 * 1000 }, // ...wait 2 minutes if necessary
)
}

export async function navigateToHomepageIfPageHasNotBeenLoaded(page: Page) {
if (page.url() === 'about:blank') {
// Navigate to homepage, so that localStorage and SRC are available
await page.goto('/')
await waitForInitialPageLoad(page)
}
}

0 comments on commit ad83c64

Please sign in to comment.