|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +import type { FakeOrganization, FakeUser } from '../testUtils'; |
| 4 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 5 | + |
| 6 | +const INVITEE_EMAIL = 'one+clerk_test@clerk.dev'; |
| 7 | + |
| 8 | +test.describe.configure({ mode: 'serial' }); |
| 9 | + |
| 10 | +testAgainstRunningApps({})('per-seat pricing @billing', ({ app }) => { |
| 11 | + let fakeAdmin: FakeUser; |
| 12 | + let fakeOrganization: FakeOrganization; |
| 13 | + |
| 14 | + test.beforeAll(async () => { |
| 15 | + const u = createTestUtils({ app }); |
| 16 | + |
| 17 | + fakeAdmin = u.services.users.createFakeUser(); |
| 18 | + const admin = await u.services.users.createBapiUser(fakeAdmin); |
| 19 | + fakeOrganization = await u.services.users.createFakeOrganization(admin.id); |
| 20 | + }); |
| 21 | + |
| 22 | + test.afterAll(async () => { |
| 23 | + await fakeOrganization.delete(); |
| 24 | + await fakeAdmin.deleteIfExists(); |
| 25 | + await app.teardown(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('invites a member after purchasing additional seats', async ({ page, context }) => { |
| 29 | + const u = createTestUtils({ app, page, context }); |
| 30 | + const fillInviteForm = async () => { |
| 31 | + const emailInput = u.po.page.getByTestId('tag-input'); |
| 32 | + await emailInput.fill(INVITEE_EMAIL); |
| 33 | + await emailInput.press('Enter'); |
| 34 | + |
| 35 | + await u.po.page.getByRole('button', { name: /select role/i }).click(); |
| 36 | + await u.po.page.getByRole('option', { name: /^member$/i }).click(); |
| 37 | + }; |
| 38 | + |
| 39 | + await u.po.signIn.goTo(); |
| 40 | + await u.po.signIn.waitForMounted(); |
| 41 | + await u.po.signIn.signInWithEmailAndInstantPassword({ |
| 42 | + email: fakeAdmin.email, |
| 43 | + password: fakeAdmin.password, |
| 44 | + }); |
| 45 | + await u.po.expect.toBeSignedIn(); |
| 46 | + |
| 47 | + await u.po.organizationProfile.goTo(); |
| 48 | + await u.po.organizationProfile.switchToBillingTab(); |
| 49 | + await expect(u.po.page.getByRole('heading', { name: 'Billing' })).toBeVisible(); |
| 50 | + |
| 51 | + await u.po.page.getByText(/^Switch plans$/).click(); |
| 52 | + await u.po.pricingTable.waitForMounted(); |
| 53 | + await u.po.pricingTable.startCheckout({ planSlug: 'bronze' }); |
| 54 | + await u.po.checkout.waitForMounted(); |
| 55 | + await u.po.checkout.fillTestCard(); |
| 56 | + await u.po.checkout.clickPayOrSubscribe(); |
| 57 | + await expect(u.po.checkout.root.getByText('Payment was successful!')).toBeVisible({ |
| 58 | + timeout: 15_000, |
| 59 | + }); |
| 60 | + await u.po.checkout.confirmAndContinue(); |
| 61 | + |
| 62 | + await u.po.page.getByText(/^Members$/).click(); |
| 63 | + await expect(u.po.page.getByRole('heading', { name: 'Members' })).toBeVisible(); |
| 64 | + |
| 65 | + await u.po.page.getByRole('button', { name: 'Invite' }).click(); |
| 66 | + await fillInviteForm(); |
| 67 | + |
| 68 | + const purchaseSeatsButton = u.po.page.getByRole('button', { name: 'Purchase additional seats' }); |
| 69 | + await expect(purchaseSeatsButton).toBeVisible(); |
| 70 | + await purchaseSeatsButton.click(); |
| 71 | + |
| 72 | + await u.po.checkout.waitForMounted(); |
| 73 | + await u.po.checkout.clickPayOrSubscribe(); |
| 74 | + await expect(u.po.checkout.root.getByText('Payment was successful!')).toBeVisible({ |
| 75 | + timeout: 15_000, |
| 76 | + }); |
| 77 | + await u.po.checkout.confirmAndContinue(); |
| 78 | + await u.po.checkout.root.waitFor({ state: 'hidden', timeout: 15_000 }); |
| 79 | + |
| 80 | + await u.po.organizationProfile.goTo(); |
| 81 | + await u.po.page.getByText(/^Members$/).click(); |
| 82 | + await expect(u.po.page.getByRole('heading', { name: 'Members' })).toBeVisible(); |
| 83 | + await u.po.page.getByRole('button', { name: 'Invite' }).click(); |
| 84 | + await fillInviteForm(); |
| 85 | + |
| 86 | + const sendInvitationsButton = u.po.page.getByRole('button', { name: 'Send invitations' }); |
| 87 | + await expect(sendInvitationsButton).toBeEnabled({ timeout: 15_000 }); |
| 88 | + await sendInvitationsButton.click({ timeout: 15_000 }); |
| 89 | + |
| 90 | + await expect(u.po.page.getByText('Invitations successfully sent')).toBeVisible({ |
| 91 | + timeout: 15_000, |
| 92 | + }); |
| 93 | + await u.po.page.getByRole('button', { name: 'Finish' }).click(); |
| 94 | + |
| 95 | + await u.po.page.getByRole('tab', { name: /Invitations/i }).click(); |
| 96 | + await expect(u.po.page.getByText(INVITEE_EMAIL)).toBeVisible({ |
| 97 | + timeout: 15_000, |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments