Skip to content
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

Create first e2e tests for cert creation #28

Merged
merged 22 commits into from Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Expand Up @@ -5,9 +5,9 @@ name: Tests, style checks, and type checks

on:
push:
branches: ['main', 'beta', 'development', 'test-system']
branches: '**'
pull_request:
branches: ['main', 'beta', 'development', 'test-system']
branches: '**'

jobs:
test-unit:
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Expand Up @@ -25,8 +25,8 @@ const config: PlaywrightTestConfig = {
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Retry on both CI and local dev */
retries: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you already notice brittleness or is this just in case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed, pretty frequently, the Chromium browser will just sit and timeout after 30 seconds waiting for the first page to load. Retries have made it work.

Not sure why; Firefox and Webkit have not experienced this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, weird. Thanks!

/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
Expand Down
70 changes: 70 additions & 0 deletions tests/e2e/create-cert.test.ts
@@ -0,0 +1,70 @@
import { type Page, expect, test } from '@playwright/test'

const proofText = 'https://forum.effectivealtruism.org'
const counterfactualText = 'I would be sitting around doing nothing.'
const descriptionText = 'Just a random description.'

test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/')
await page.click('text=Log in')
await page.click('text=Sign in with Mock Login')
})

test.describe('Create Certificate', () => {
test('should allow creating new certificate', async ({ page }) => {
const titleText = 'My test project 0001'

await page.click('text=New project')
await fillInDefaultValues(page, titleText)
await page.locator('button:has-text("Submit")').click()

// Check we've landed on the cert page.
await expect(page).toHaveTitle(new RegExp('.*' + titleText + '.*'))
})

test('should fill in all certificate values', async ({ page }) => {
const titleText = 'My test project 0002'

await page.click('text=New project')
await fillInDefaultValues(page, titleText)
await page.locator('button:has-text("Submit")').click()

// Check we've landed on the cert page.
await expect(page).toHaveTitle(new RegExp('.*' + titleText + '.*'))

// Verify certificate values.
await expect(page.getByRole('heading', { level: 1 })).toContainText(
titleText
)
await expect(page.locator('text=Proof of ownership')).toHaveAttribute(
'href',
proofText
)
await page.locator('text=' + descriptionText).click() // Just clicking to verify it's there.
})
})

async function fillInDefaultValues(page: Page, titleText: string) {
await page.getByRole('textbox', { name: 'title' }).fill(titleText)
await page.getByRole('textbox', { name: 'proof' }).fill(proofText)

// TODO: start + end dates
//await page.getByRole('textbox', { name: 'actionStart' }).fill(actionStartText)
//await page.getByRole('textbox', { name: 'actionEnd' }).fill(actionEndText)

await page
.getByRole('textbox', { name: 'counterfactual' })
.fill(counterfactualText)

// TODO: Tags
//await page.selectOption('#tags', [{label: tagLabel}])

await page.locator(':nth-match(textarea, 1)').fill(descriptionText)

// TODO: Advanced options

await page.click('text=I will never sell these rights more than once')
await page.click(
'text=I am happy for this record to be publicly accessible forever'
)
}