Files

46 lines
1.6 KiB
TypeScript

import { screen } from '@testing-library/react'
import { describe, expect, test } from 'vitest'
import { ScopeGroupCard } from './ScopeGroupCard'
import type { OAuthScope } from '@/data/oauth-apps/types'
import { customRender } from '@/tests/lib/custom-render'
const SCOPE_GROUPS: OAuthScope[] = [
'database:read',
'database:write',
'environment:read',
'environment:write',
'projects:read',
'edge_functions:read',
'storage:read',
]
describe('ScopeGroupCard', () => {
test('renders Read only and Read and write headings', () => {
customRender(<ScopeGroupCard scopes={SCOPE_GROUPS} />)
expect(screen.getByText('Read and write')).toBeInTheDocument()
expect(screen.getByText('Read only')).toBeInTheDocument()
})
test('renders a Write heading for a write-only group', () => {
customRender(<ScopeGroupCard scopes={['analytics:write']} />)
expect(screen.getByText('Write')).toBeInTheDocument()
})
test('groups direct database read-write access with the requested database management permission', () => {
customRender(<ScopeGroupCard scopes={[...SCOPE_GROUPS, 'database_token_access:write']} />)
const databaseManagement = screen.getByRole('button', { name: 'Database management' })
const directDatabaseAccess = screen.getByRole('button', { name: 'Database token access' })
expect(databaseManagement.parentElement).toContainElement(directDatabaseAccess)
})
test('renders no over-role annotation', () => {
customRender(<ScopeGroupCard scopes={SCOPE_GROUPS} />)
expect(screen.queryByText('Read-only for your role')).not.toBeInTheDocument()
})
})