Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.2 KB
Raw Blame
import '@testing-library/jest-dom'

import { cleanup, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { router } from 'kea-router'

import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'

import { ConfirmOrganization } from './ConfirmOrganization'

describe('ConfirmOrganization', () => {
    beforeEach(() => {
        useMocks({
            get: {
                // The page only renders for a logged-out person
                '/api/users/@me/': () => [401, { detail: 'Not authenticated' }],
            },
        })
        window.POSTHOG_APP_CONTEXT = { current_user: null } as any
        initKeaTests()
        // The social signup redirect fills in everything except the organization name
        router.actions.push('/organization/confirm-creation', { email: '[email protected]', first_name: 'Spike' })
        render(
            <Provider>
                <ConfirmOrganization />
            </Provider>
        )
    })

    afterEach(() => {
        cleanup()
    })

    it('points a failed submit at the organization name input', async () => {
        await userEvent.click(screen.getByText('Create organization'))

        expect(screen.getByLabelText('Organization name')).toHaveFocus()
        expect(screen.getByText(/You can use your own name/)).toBeInTheDocument()
    })

    it('prompts for a role while the dropdown has nothing selected', () => {
        // The form defaults the role to an empty string, which LemonSelect would otherwise render
        // as a blank button
        expect(screen.getByText('Select your role')).toBeInTheDocument()
    })

    it('points a submit with no role at the role dropdown', async () => {
        await userEvent.type(screen.getByLabelText('Organization name'), 'Spikes Inc')
        await userEvent.click(screen.getByText('Create organization'))

        const roleSelect = screen.getByText('Select your role').closest('button')
        expect(roleSelect).toHaveFocus()
        expect(roleSelect).toHaveClass('LemonButton--status-danger')
        expect(screen.getByText('Please select your role to continue')).toBeInTheDocument()
    })
})