auth-pages.spec.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { expect, test } from '@playwright/test'
  2. import { signUpWithPassword } from '../../support/cloud'
  3. import { settle } from '../../support/hydration'
  4. /**
  5. * The sign-up and sign-in pages as a stranger meets them, in cloud mode.
  6. *
  7. * Four in ten people who landed on sign-up left without touching the form, on
  8. * a page that said nothing about what they were signing up for. The pages now
  9. * make the case beside the form, point a newcomer who clicked "Login" at a
  10. * free account before the form, and let a visitor change the language before
  11. * they have an account to keep it on. The last is the one that can quietly
  12. * break: a language picked on sign-up has to survive the sign-up itself.
  13. */
  14. test.use({ storageState: { cookies: [], origins: [] } })
  15. const stamp = Date.now()
  16. test.describe('the sign-up page', () => {
  17. test('makes its case beside the form', async ({ page }) => {
  18. await page.goto('/auth/sign-up')
  19. await settle(page)
  20. await expect(page.getByRole('heading', { name: 'Start your free workshop' })).toBeVisible()
  21. await expect(page.getByText('Ready in under a minute. No credit card required.')).toBeVisible()
  22. await expect(page.getByRole('heading', { name: /Workshop management/ })).toBeVisible()
  23. await expect(page.getByText('Free plan, no credit card')).toBeVisible()
  24. // And the form is still the thing to do.
  25. for (const field of ['#name', '#email', '#password']) {
  26. await expect(page.locator(field)).toBeVisible()
  27. }
  28. await expect(page.getByRole('button', { name: 'Create free account' })).toBeVisible()
  29. })
  30. test('keeps a language picked before signing up, into onboarding', async ({ page, context }) => {
  31. await page.goto('/auth/sign-up')
  32. await settle(page)
  33. await expect(async () => {
  34. await page.getByRole('combobox', { name: 'Language' }).click()
  35. await expect(page.getByRole('option', { name: 'Norsk Bokmål' })).toBeVisible({
  36. timeout: 2_000,
  37. })
  38. }).toPass({ timeout: 30_000 })
  39. await page.getByRole('option', { name: 'Norsk Bokmål' }).click()
  40. await expect(page.getByRole('heading', { name: 'Start ditt gratis verksted' })).toBeVisible({
  41. timeout: 30_000,
  42. })
  43. const cookie = (await context.cookies()).find((c) => c.name === 'locale')
  44. expect(cookie?.value, 'kept for the visits after this one').toBe('nb')
  45. // Signed up in Norwegian, and onboarding speaks it too.
  46. await signUpWithPassword(page, {
  47. name: 'E2E Norsk',
  48. email: `e2e-norsk-${stamp}@example.com`,
  49. password: `E2e-pass-${stamp}`,
  50. })
  51. await expect(page.getByRole('heading', { name: 'Sett opp verkstedet ditt' })).toBeVisible()
  52. })
  53. })
  54. test.describe('the sign-in page', () => {
  55. test('points a newcomer at a free account before the form', async ({ page }) => {
  56. await page.goto('/auth/sign-in')
  57. await settle(page)
  58. await expect(page.getByText('New to Torqvoice?')).toBeVisible()
  59. const link = page.getByRole('link', { name: 'Create a free account' })
  60. await expect(link).toHaveAttribute('href', /\/auth\/sign-up/)
  61. // Above the form, where a newcomer who clicked "Login" reads, rather than
  62. // under it.
  63. const linkBox = await link.boundingBox()
  64. const emailBox = await page.locator('#email').boundingBox()
  65. expect(linkBox && emailBox && linkBox.y < emailBox.y, 'the link sits above the form').toBe(true)
  66. await link.click()
  67. await page.waitForURL(/\/auth\/sign-up/)
  68. await expect(page.getByRole('heading', { name: 'Start your free workshop' })).toBeVisible()
  69. })
  70. })