refactor(frontend): bring shared/ui and pages/public under the 4-file rule
Two directories had grown past the plan's ≤4 files per folder constraint: shared/ui (5 primitives, and the kit keeps growing) and pages/public (5 pages, counting auth/ as a subfolder). Split shared/ui by concept — text-field/ and share-code/ each with their own tests/ — and move PageTitle to shared/layout, where the rest of the page chrome lives. Flat UI tests become per-component tests; the PageTitle test follows the component. Move LoginPage and RegisterPage into the existing pages/public/auth/ beside the AuthSplit layout they both use. No behaviour change: 83 tests, clean tsc build, 1 known oxlint warning.
This commit is contained in:
parent
456366006e
commit
1c94e0ebea
21 changed files with 69 additions and 66 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { screen, within } from '@testing-library/react'
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { getI18n } from 'react-i18next'
|
||||
import { afterEach, expect, test } from 'vitest'
|
||||
import { routes } from '../../../app/routes'
|
||||
import { renderApp } from '../../../test/render'
|
||||
import { json, mockFetch } from '../../../test/fetch'
|
||||
import { PageTitle } from '../PageTitle'
|
||||
|
||||
afterEach(async () => {
|
||||
await getI18n().changeLanguage('ru')
|
||||
|
|
@ -103,3 +104,11 @@ test('footer carries the github link and the disclaimer', async () => {
|
|||
const gh = screen.getByRole('link', { name: 'GitHub' })
|
||||
expect(gh.getAttribute('href')).toMatch(/^https:\/\/github\.com\//)
|
||||
})
|
||||
|
||||
test('page title renders one h1 with an optional lead', () => {
|
||||
render(
|
||||
<PageTitle lead="Короткое описание">Мои конфиги</PageTitle>,
|
||||
)
|
||||
expect(screen.getByRole('heading', { level: 1, name: 'Мои конфиги' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Короткое описание')).toBeInTheDocument()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from './Button'
|
||||
import { Button } from '../Button'
|
||||
|
||||
export function ShareCode({ code, label }: { code: string; label?: string }) {
|
||||
const { t } = useTranslation('common')
|
||||
14
frontend/src/shared/ui/share-code/tests/share-code.test.tsx
Normal file
14
frontend/src/shared/ui/share-code/tests/share-code.test.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { expect, test, vi } from 'vitest'
|
||||
import { ShareCode } from '../ShareCode'
|
||||
|
||||
test('share code copies to clipboard and confirms', async () => {
|
||||
const user = userEvent.setup()
|
||||
const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue()
|
||||
render(<ShareCode code="7KQ3M9XA" />)
|
||||
expect(screen.getByText('7KQ3M9XA')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Скопировать' }))
|
||||
expect(writeText).toHaveBeenCalledWith('7KQ3M9XA')
|
||||
expect(await screen.findByText('Скопировано')).toBeInTheDocument()
|
||||
})
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { expect, test, vi } from 'vitest'
|
||||
import { Button } from '../Button'
|
||||
import { PageTitle } from '../PageTitle'
|
||||
import { TextField } from '../TextField'
|
||||
import { ShareCode } from '../ShareCode'
|
||||
import { Notice } from '../Notice'
|
||||
|
||||
test('busy button is disabled and announces busy', () => {
|
||||
render(<Button busy>Сохранить</Button>)
|
||||
const b = screen.getByRole('button', { name: 'Сохранить' })
|
||||
expect(b).toBeDisabled()
|
||||
expect(b).toHaveAttribute('aria-busy', 'true')
|
||||
})
|
||||
|
||||
test('text field links label and error', () => {
|
||||
render(<TextField label="Почта" error="Введи почту" />)
|
||||
const input = screen.getByLabelText('Почта')
|
||||
expect(input).toHaveAttribute('aria-invalid', 'true')
|
||||
expect(input).toHaveAccessibleDescription('Введи почту')
|
||||
})
|
||||
|
||||
test('share code copies to clipboard and confirms', async () => {
|
||||
const user = userEvent.setup()
|
||||
const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue()
|
||||
render(<ShareCode code="7KQ3M9XA" />)
|
||||
expect(screen.getByText('7KQ3M9XA')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Скопировать' }))
|
||||
expect(writeText).toHaveBeenCalledWith('7KQ3M9XA')
|
||||
expect(await screen.findByText('Скопировано')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('error notice is an alert', () => {
|
||||
render(<Notice tone="error">Неверный код</Notice>)
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Неверный код')
|
||||
})
|
||||
|
||||
test('page title renders one h1 with an optional lead', () => {
|
||||
render(
|
||||
<PageTitle lead="Короткое описание">Мои конфиги</PageTitle>,
|
||||
)
|
||||
expect(screen.getByRole('heading', { level: 1, name: 'Мои конфиги' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Короткое описание')).toBeInTheDocument()
|
||||
})
|
||||
24
frontend/src/shared/ui/text-field/tests/text-field.test.tsx
Normal file
24
frontend/src/shared/ui/text-field/tests/text-field.test.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import { expect, test } from 'vitest'
|
||||
import { Button } from '../../Button'
|
||||
import { Notice } from '../../Notice'
|
||||
import { TextField } from '../TextField'
|
||||
|
||||
test('busy button is disabled and announces busy', () => {
|
||||
render(<Button busy>Сохранить</Button>)
|
||||
const b = screen.getByRole('button', { name: 'Сохранить' })
|
||||
expect(b).toBeDisabled()
|
||||
expect(b).toHaveAttribute('aria-busy', 'true')
|
||||
})
|
||||
|
||||
test('text field links label and error', () => {
|
||||
render(<TextField label="Почта" error="Введи почту" />)
|
||||
const input = screen.getByLabelText('Почта')
|
||||
expect(input).toHaveAttribute('aria-invalid', 'true')
|
||||
expect(input).toHaveAccessibleDescription('Введи почту')
|
||||
})
|
||||
|
||||
test('error notice is an alert', () => {
|
||||
render(<Notice tone="error">Неверный код</Notice>)
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Неверный код')
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue