このコミットが含まれているのは:
@@ -1,12 +1,13 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import SettingPage from '@/pages/users/SettingPage'
|
||||
import { buildUser } from '@/test/factories'
|
||||
import { renderWithProviders } from '@/test/render'
|
||||
|
||||
const api = vi.hoisted (() => ({
|
||||
apiPut: vi.fn (),
|
||||
apiPut: vi.fn (),
|
||||
isApiError: vi.fn (),
|
||||
}))
|
||||
|
||||
const toastApi = vi.hoisted (() => ({
|
||||
@@ -23,6 +24,11 @@ vi.mock ('@/components/users/InheritDialogue', () => ({
|
||||
}))
|
||||
|
||||
describe ('SettingPage', () => {
|
||||
beforeEach (() => {
|
||||
vi.clearAllMocks ()
|
||||
api.isApiError.mockReturnValue (false)
|
||||
})
|
||||
|
||||
it ('shows loading when user is absent', () => {
|
||||
renderWithProviders (<SettingPage user={null} setUser={vi.fn ()}/>)
|
||||
|
||||
@@ -51,4 +57,28 @@ describe ('SettingPage', () => {
|
||||
expect (setUser).toHaveBeenCalled ()
|
||||
expect (toastApi.toast).toHaveBeenCalledWith ({ title: '設定を更新しました.' })
|
||||
})
|
||||
|
||||
it ('shows validation errors returned for the name field', async () => {
|
||||
const user = buildUser ({ id: 11, name: 'old' })
|
||||
api.isApiError.mockReturnValue (true)
|
||||
api.apiPut.mockRejectedValueOnce ({
|
||||
response: {
|
||||
status: 422,
|
||||
data: {
|
||||
type: 'validation_error',
|
||||
message: '入力内容を確認してください.',
|
||||
errors: { name: ['名前は必須です.'] },
|
||||
base_errors: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
renderWithProviders (<SettingPage user={user} setUser={vi.fn ()}/>)
|
||||
|
||||
fireEvent.change (screen.getByRole ('textbox'), { target: { value: '' } })
|
||||
fireEvent.click (screen.getByRole ('button', { name: '更新' }))
|
||||
|
||||
expect (await screen.findByText ('名前は必須です.')).toBeInTheDocument ()
|
||||
expect (screen.getByRole ('textbox')).toHaveAttribute ('aria-invalid', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
新しい課題から参照
ユーザをブロックする