Reviewed-on: #379 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #379 でマージされました.
このコミットが含まれているのは:
@@ -18,6 +18,21 @@ describe ('TagLink', () => {
|
||||
expect (screen.getByText ('4')).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('does not append deprecated state to the rendered tag name', () => {
|
||||
renderWithProviders (
|
||||
<TagLink
|
||||
tag={buildTag ({
|
||||
name: '旧タグ',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
})}
|
||||
withWiki={false}
|
||||
withCount={false}/>,
|
||||
)
|
||||
|
||||
expect (screen.getByRole ('link', { name: '旧タグ' })).toBeInTheDocument ()
|
||||
expect (screen.queryByText ('(廃止)')).not.toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('links wiki markers to the correct detail route', () => {
|
||||
renderWithProviders (
|
||||
<TagLink tag={buildTag ({ hasWiki: true, name: 'a/b' })}/>,
|
||||
|
||||
@@ -128,4 +128,4 @@ const TagLink: FC<Props> = ({ tag,
|
||||
</>)
|
||||
}
|
||||
|
||||
export default TagLink
|
||||
export default TagLink
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { apiPost } from '@/lib/api'
|
||||
import { apiGet, apiPost } from '@/lib/api'
|
||||
import {
|
||||
buildGekanatorQuestions,
|
||||
expectedAnswerForQuestion,
|
||||
fetchGekanatorPosts,
|
||||
fetchGekanatorQuestions,
|
||||
learnedSemanticSideForPost,
|
||||
questionIdForCondition,
|
||||
restoreGekanatorQuestion,
|
||||
@@ -24,6 +26,7 @@ vi.mock('@/lib/api', () => ({
|
||||
}))
|
||||
|
||||
const mockedApiPost = vi.mocked(apiPost)
|
||||
const mockedApiGet = vi.mocked(apiGet)
|
||||
|
||||
const post = (overrides: Partial<Post> = {}): Post => ({
|
||||
id: 1,
|
||||
@@ -43,6 +46,24 @@ const post = (overrides: Partial<Post> = {}): Post => ({
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('Gekanator API functions', () => {
|
||||
it('returns posts from the Gekanator posts endpoint', async () => {
|
||||
const posts = [post()]
|
||||
mockedApiGet.mockResolvedValueOnce({ posts })
|
||||
|
||||
await expect(fetchGekanatorPosts()).resolves.toEqual(posts)
|
||||
expect(mockedApiGet).toHaveBeenCalledWith('/gekanator/posts')
|
||||
})
|
||||
|
||||
it('returns questions from the Gekanator questions endpoint', async () => {
|
||||
const questions: StoredGekanatorQuestion[] = []
|
||||
mockedApiGet.mockResolvedValueOnce({ questions })
|
||||
|
||||
await expect(fetchGekanatorQuestions()).resolves.toEqual(questions)
|
||||
expect(mockedApiGet).toHaveBeenCalledWith('/gekanator/questions')
|
||||
})
|
||||
})
|
||||
|
||||
describe('expectedAnswerForQuestion', () => {
|
||||
it('returns a direct example answer when present', () => {
|
||||
const question: StoredGekanatorQuestion = {
|
||||
@@ -126,6 +147,7 @@ describe('expectedAnswerForQuestion', () => {
|
||||
postCount: 1,
|
||||
createdAt: '2026-06-10T00:00:00.000Z',
|
||||
updatedAt: '2026-06-10T00:00:00.000Z',
|
||||
deprecatedAt: null,
|
||||
hasWiki: false,
|
||||
hasDeerjikists: false,
|
||||
materialId: null,
|
||||
|
||||
@@ -17,6 +17,10 @@ const mWiki = match<{ title: string }> ('/wiki/:title')
|
||||
const mTag = match<{ id: string }> ('/tags/:id')
|
||||
|
||||
|
||||
const boolFromQuery = (value: string | null): boolean =>
|
||||
['1', 'true', 'on', 'yes', ''].includes ((value ?? '').toLowerCase ())
|
||||
|
||||
|
||||
const prefetchWikiPagesIndex: Prefetcher = async (qc, url) => {
|
||||
const title = url.searchParams.get ('title') ?? ''
|
||||
|
||||
@@ -156,13 +160,16 @@ const prefetchTagsIndex: Prefetcher = async (qc, url) => {
|
||||
const createdTo = url.searchParams.get ('created_to') ?? ''
|
||||
const updatedFrom = url.searchParams.get ('updated_from') ?? ''
|
||||
const updatedTo = url.searchParams.get ('updated_to') ?? ''
|
||||
const deprecated = url.searchParams.has ('deprecated')
|
||||
? boolFromQuery (url.searchParams.get ('deprecated'))
|
||||
: null
|
||||
const page = Number (url.searchParams.get ('page') || 1)
|
||||
const limit = Number (url.searchParams.get ('limit') || 20)
|
||||
const order = (url.searchParams.get ('order') ?? 'post_count:desc') as FetchTagsOrder
|
||||
|
||||
const keys = {
|
||||
post, name, category, postCountGTE, postCountLTE, createdFrom, createdTo,
|
||||
updatedFrom, updatedTo, page, limit, order }
|
||||
updatedFrom, updatedTo, deprecated, page, limit, order }
|
||||
|
||||
await qc.prefetchQuery ({
|
||||
queryKey: tagsKeys.index (keys),
|
||||
|
||||
@@ -20,6 +20,7 @@ const baseParams: FetchTagsParams = {
|
||||
createdTo: '',
|
||||
updatedFrom: '',
|
||||
updatedTo: '',
|
||||
deprecated: null,
|
||||
page: 1,
|
||||
limit: 30,
|
||||
order: 'updated_at:desc',
|
||||
@@ -57,6 +58,20 @@ describe ('tags API functions', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it.each ([
|
||||
[true, '1'],
|
||||
[false, '0'],
|
||||
] as const) ('maps deprecated=%s to %s', async (deprecated, expected) => {
|
||||
api.apiGet.mockResolvedValueOnce ({ tags: [], count: 0 })
|
||||
|
||||
await fetchTags ({ ...baseParams, deprecated })
|
||||
|
||||
expect (api.apiGet).toHaveBeenCalledWith (
|
||||
'/tags',
|
||||
{ params: expect.objectContaining ({ deprecated: expected }) },
|
||||
)
|
||||
})
|
||||
|
||||
it ('returns null when tag fetches fail', async () => {
|
||||
api.apiGet.mockRejectedValueOnce (new Error ('missing'))
|
||||
api.apiGet.mockRejectedValueOnce (new Error ('missing'))
|
||||
|
||||
@@ -10,7 +10,8 @@ import type { Deerjikist,
|
||||
|
||||
export const fetchTags = async (
|
||||
{ post, name, category, postCountGTE, postCountLTE, createdFrom, createdTo,
|
||||
updatedFrom, updatedTo, page, limit, order }: FetchTagsParams,
|
||||
updatedFrom, updatedTo, deprecated,
|
||||
page, limit, order }: FetchTagsParams,
|
||||
): Promise<{ tags: Tag[]
|
||||
count: number }> =>
|
||||
await apiGet ('/tags', { params: {
|
||||
@@ -23,6 +24,7 @@ export const fetchTags = async (
|
||||
...(createdTo && { created_to: createdTo }),
|
||||
...(updatedFrom && { updated_from: updatedFrom }),
|
||||
...(updatedTo && { updated_to: updatedTo }),
|
||||
...(deprecated != null && { deprecated: deprecated ? '1' : '0' }),
|
||||
...(page && { page }),
|
||||
...(limit && { limit }),
|
||||
...(order && { order }) } })
|
||||
@@ -64,7 +66,6 @@ export const fetchTagByName = async (name: string): Promise<Tag | null> => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const fetchTagChanges = async (
|
||||
{ id, page, limit }: {
|
||||
id?: string
|
||||
|
||||
@@ -19,7 +19,12 @@ import type { FC, FormEvent } from 'react'
|
||||
|
||||
import type { Category, Tag } from '@/types'
|
||||
|
||||
type TagFormField = 'name' | 'category' | 'aliases' | 'parentTags'
|
||||
type TagFormField =
|
||||
| 'name'
|
||||
| 'category'
|
||||
| 'aliases'
|
||||
| 'parentTags'
|
||||
| 'deprecated'
|
||||
|
||||
|
||||
const TagDetailPage: FC = () => {
|
||||
@@ -35,6 +40,7 @@ const TagDetailPage: FC = () => {
|
||||
const [category, setCategory] = useState<Category> ('general')
|
||||
const [aliases, setAliases] = useState ('')
|
||||
const [parentTags, setParentTags] = useState ('')
|
||||
const [deprecated, setDeprecated] = useState (false)
|
||||
const [disabled, setDisabled] = useState (true)
|
||||
const { baseErrors, fieldErrors, clearValidationErrors, applyValidationError } =
|
||||
useValidationErrors<TagFormField> ()
|
||||
@@ -50,6 +56,7 @@ const TagDetailPage: FC = () => {
|
||||
formData.append ('category', category)
|
||||
formData.append ('aliases', aliases)
|
||||
formData.append ('parent_tags', parentTags)
|
||||
formData.append ('deprecated', deprecated ? '1' : '0')
|
||||
|
||||
try
|
||||
{
|
||||
@@ -59,6 +66,7 @@ const TagDetailPage: FC = () => {
|
||||
setCategory (data.category as Category)
|
||||
setAliases (data.aliases.join (' '))
|
||||
setParentTags (data.parents.map (t => t.name).join (' '))
|
||||
setDeprecated (Boolean (data.deprecatedAt))
|
||||
|
||||
qc.invalidateQueries ({ queryKey: postsKeys.root })
|
||||
qc.invalidateQueries ({ queryKey: tagsKeys.root })
|
||||
@@ -82,6 +90,7 @@ const TagDetailPage: FC = () => {
|
||||
setCategory (tag.category as Category)
|
||||
setAliases (tag.aliases.join (' '))
|
||||
setParentTags (tag.parents.map (t => t.name).join (' '))
|
||||
setDeprecated (Boolean (tag.deprecatedAt))
|
||||
setDisabled (tag.category === 'nico')
|
||||
}, [tag])
|
||||
|
||||
@@ -165,6 +174,17 @@ const TagDetailPage: FC = () => {
|
||||
</>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="廃止済" messages={fieldErrors.deprecated}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={disabled}
|
||||
checked={deprecated}
|
||||
onChange={e => setDeprecated (e.target.checked)}
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}/>)}
|
||||
</FormField>
|
||||
|
||||
<div className="py-3">
|
||||
<button
|
||||
type="submit"
|
||||
|
||||
@@ -20,17 +20,28 @@ import type { FC } from 'react'
|
||||
|
||||
const renderDiff = (diff: { current: string | null; prev: string | null }) => (
|
||||
<>
|
||||
{(diff.prev && diff.prev !== diff.current) && (
|
||||
{diff.prev !== diff.current
|
||||
? (
|
||||
<>
|
||||
<del className="text-red-600 dark:text-red-400">
|
||||
{diff.prev}
|
||||
{diff.prev && <>{diff.prev}<br/></>}
|
||||
</del>
|
||||
{diff.current && <br/>}
|
||||
</>)}
|
||||
{diff.current}
|
||||
<ins className="text-green-600 dark:text-green-400">
|
||||
{diff.current}
|
||||
</ins>
|
||||
</>)
|
||||
: diff.current}
|
||||
</>)
|
||||
|
||||
|
||||
const tagStateLabel = (deprecatedAt: string | null) => deprecatedAt ? '廃止' : ''
|
||||
|
||||
|
||||
const renderStateDiff = (diff: { current: string | null; prev: string | null }) =>
|
||||
renderDiff ({ current: tagStateLabel (diff.current),
|
||||
prev: tagStateLabel (diff.prev) })
|
||||
|
||||
|
||||
const TagHistoryPage: FC = () => {
|
||||
const location = useLocation ()
|
||||
const query = new URLSearchParams (location.search)
|
||||
@@ -72,6 +83,8 @@ const TagHistoryPage: FC = () => {
|
||||
<col className="w-96"/>
|
||||
{/* カテゴリ */}
|
||||
<col className="w-96"/>
|
||||
{/* 状態 */}
|
||||
<col className="w-32"/>
|
||||
{/* 別名 */}
|
||||
<col className="w-[48rem]"/>
|
||||
{/* 上位タグ */}
|
||||
@@ -87,6 +100,7 @@ const TagHistoryPage: FC = () => {
|
||||
<th className="p-2 text-left">版</th>
|
||||
<th className="p-2 text-left">名称</th>
|
||||
<th className="p-2 text-left">カテゴリ</th>
|
||||
<th className="p-2 text-left">状態</th>
|
||||
<th className="p-2 text-left">別名</th>
|
||||
<th className="p-2 text-left">上位タグ</th>
|
||||
<th className="p-2 text-left">更新日時</th>
|
||||
@@ -106,6 +120,9 @@ const TagHistoryPage: FC = () => {
|
||||
prev: (change.category.prev
|
||||
&& CATEGORY_NAMES[change.category.prev]) })}
|
||||
</td>
|
||||
<td className="p-2 break-all">
|
||||
{renderStateDiff (change.deprecatedAt)}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
{change.aliases.map ((tag, i) => (
|
||||
tag.type === 'added'
|
||||
@@ -178,6 +195,7 @@ const TagHistoryPage: FC = () => {
|
||||
`/tags/${ change.tagId }`,
|
||||
{ name: change.name.current,
|
||||
category: change.category.current,
|
||||
deprecated: change.deprecatedAt.current ? '1' : '0',
|
||||
aliases:
|
||||
change.aliases
|
||||
.filter (t => t.type !== 'removed')
|
||||
@@ -211,4 +229,5 @@ const TagHistoryPage: FC = () => {
|
||||
</MainArea>)
|
||||
}
|
||||
|
||||
export default TagHistoryPage
|
||||
|
||||
export default TagHistoryPage
|
||||
|
||||
@@ -14,13 +14,22 @@ vi.mock ('@/lib/tags', () => tagsApi)
|
||||
describe ('TagListPage', () => {
|
||||
it ('loads tags from URL filters and renders the results table', async () => {
|
||||
tagsApi.fetchTags.mockResolvedValueOnce ({
|
||||
tags: [buildTag ({ id: 7, name: '虹夏', category: 'character', postCount: 99 })],
|
||||
tags: [buildTag ({
|
||||
id: 7,
|
||||
name: '虹夏',
|
||||
category: 'character',
|
||||
postCount: 99,
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
})],
|
||||
count: 1,
|
||||
})
|
||||
|
||||
renderWithProviders (
|
||||
<TagListPage/>,
|
||||
{ route: '/tags?name=%E8%99%B9&category=character&page=3&post_count_gte=5' },
|
||||
{
|
||||
route:
|
||||
'/tags?name=%E8%99%B9&category=character&page=3&post_count_gte=5&deprecated=1',
|
||||
},
|
||||
)
|
||||
|
||||
await waitFor (() => {
|
||||
@@ -30,6 +39,7 @@ describe ('TagListPage', () => {
|
||||
category: 'character',
|
||||
page: 3,
|
||||
postCountGTE: 5,
|
||||
deprecated: true,
|
||||
}),
|
||||
)
|
||||
})
|
||||
@@ -38,6 +48,8 @@ describe ('TagListPage', () => {
|
||||
'/tags/7',
|
||||
)
|
||||
expect (screen.getAllByText ('キャラクター').length).toBeGreaterThan (0)
|
||||
expect (screen.getAllByRole ('combobox')[1]).toHaveValue ('1')
|
||||
expect (screen.getAllByText ('廃止')).toHaveLength (2)
|
||||
})
|
||||
|
||||
it ('navigates to a normalized search URL on submit', async () => {
|
||||
@@ -46,7 +58,9 @@ describe ('TagListPage', () => {
|
||||
renderWithProviders (<TagListPage/>, { route: '/tags' })
|
||||
|
||||
fireEvent.change (screen.getByRole ('textbox'), { target: { value: '虹夏' } })
|
||||
fireEvent.change (screen.getByRole ('combobox'), { target: { value: 'character' } })
|
||||
fireEvent.change (screen.getAllByRole ('combobox')[0], {
|
||||
target: { value: 'character' },
|
||||
})
|
||||
fireEvent.submit (screen.getByRole ('button', { name: '検索' }).closest ('form')!)
|
||||
|
||||
await waitFor (() => {
|
||||
|
||||
@@ -29,6 +29,13 @@ const setIf = (qs: URLSearchParams, k: string, v: string | null) => {
|
||||
}
|
||||
|
||||
|
||||
const boolFromQuery = (value: string | null): boolean =>
|
||||
['1', 'true', 'on', 'yes', ''].includes ((value ?? '').toLowerCase ())
|
||||
|
||||
|
||||
const tagStateLabel = (deprecatedAt: string | null) => deprecatedAt ? '廃止' : ''
|
||||
|
||||
|
||||
const TagListPage: FC = () => {
|
||||
const location = useLocation ()
|
||||
|
||||
@@ -48,6 +55,9 @@ const TagListPage: FC = () => {
|
||||
const qCreatedTo = query.get ('created_to') ?? ''
|
||||
const qUpdatedFrom = query.get ('updated_from') ?? ''
|
||||
const qUpdatedTo = query.get ('updated_to') ?? ''
|
||||
const qDeprecated = query.has ('deprecated')
|
||||
? boolFromQuery (query.get ('deprecated'))
|
||||
: null
|
||||
const order = (query.get ('order') || 'post_count:desc') as FetchTagsOrder
|
||||
|
||||
const [name, setName] = useState ('')
|
||||
@@ -58,6 +68,7 @@ const TagListPage: FC = () => {
|
||||
const [createdTo, setCreatedTo] = useState<string | null> (null)
|
||||
const [updatedFrom, setUpdatedFrom] = useState<string | null> (null)
|
||||
const [updatedTo, setUpdatedTo] = useState<string | null> (null)
|
||||
const [deprecated, setDeprecated] = useState<boolean | null> (null)
|
||||
|
||||
const keys = {
|
||||
page, limit, order,
|
||||
@@ -69,7 +80,8 @@ const TagListPage: FC = () => {
|
||||
createdFrom: qCreatedFrom,
|
||||
createdTo: qCreatedTo,
|
||||
updatedFrom: qUpdatedFrom,
|
||||
updatedTo: qUpdatedTo }
|
||||
updatedTo: qUpdatedTo,
|
||||
deprecated: qDeprecated }
|
||||
const { data, isLoading: loading } = useQuery ({
|
||||
queryKey: tagsKeys.index (keys),
|
||||
queryFn: () => fetchTags (keys) })
|
||||
@@ -85,10 +97,11 @@ const TagListPage: FC = () => {
|
||||
setCreatedTo (qCreatedTo)
|
||||
setUpdatedFrom (qUpdatedFrom)
|
||||
setUpdatedTo (qUpdatedTo)
|
||||
setDeprecated (qDeprecated)
|
||||
|
||||
document.querySelector ('table')?.scrollIntoView ({ behavior: 'smooth' })
|
||||
}, [location.search, qCategory, qCreatedFrom, qCreatedTo, qName, qPostCountGTE,
|
||||
qPostCountLTE, qUpdatedFrom, qUpdatedTo])
|
||||
qPostCountLTE, qUpdatedFrom, qUpdatedTo, qDeprecated])
|
||||
|
||||
const handleSearch = (e: FormEvent) => {
|
||||
e.preventDefault ()
|
||||
@@ -104,6 +117,8 @@ const TagListPage: FC = () => {
|
||||
setIf (qs, 'created_to', createdTo)
|
||||
setIf (qs, 'updated_from', updatedFrom)
|
||||
setIf (qs, 'updated_to', updatedTo)
|
||||
if (deprecated != null)
|
||||
qs.set ('deprecated', deprecated ? '1' : '0')
|
||||
qs.set ('page', '1')
|
||||
qs.set ('order', order)
|
||||
|
||||
@@ -201,6 +216,21 @@ const TagListPage: FC = () => {
|
||||
</>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="状態">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={deprecated == null ? '' : (deprecated ? '1' : '0')}
|
||||
onChange={e => setDeprecated (
|
||||
e.target.value === ''
|
||||
? null
|
||||
: e.target.value === '1')}
|
||||
className={inputClass (invalid)}>
|
||||
<option value=""> </option>
|
||||
<option value="0">有効</option>
|
||||
<option value="1">廃止</option>
|
||||
</select>)}
|
||||
</FormField>
|
||||
|
||||
<div className="py-3">
|
||||
<button
|
||||
type="submit"
|
||||
@@ -219,6 +249,7 @@ const TagListPage: FC = () => {
|
||||
<col className="w-72"/>
|
||||
<col className="w-16"/>
|
||||
<col className="w-48"/>
|
||||
<col className="w-32"/>
|
||||
<col className="w-72"/>
|
||||
<col className="w-48"/>
|
||||
<col className="w-56"/>
|
||||
@@ -249,6 +280,7 @@ const TagListPage: FC = () => {
|
||||
currentOrder={order}
|
||||
defaultDirection={defaultDirection}/>
|
||||
</th>
|
||||
<th className="p-2 text-left whitespace-nowrap">状態</th>
|
||||
<th className="p-2 text-left whitespace-nowrap">別名</th>
|
||||
<th className="p-2 text-left whitespace-nowrap">上位タグ</th>
|
||||
<th className="p-2 text-left whitespace-nowrap">
|
||||
@@ -280,6 +312,7 @@ const TagListPage: FC = () => {
|
||||
</td>
|
||||
<td className="p-2 text-right">{row.postCount}</td>
|
||||
<td className="p-2">{CATEGORY_NAMES[row.category]}</td>
|
||||
<td className="p-2">{tagStateLabel (row.deprecatedAt)}</td>
|
||||
<td className="p-2">{row.aliases.join (' ')}</td>
|
||||
<td className="p-2">
|
||||
{row.parents.map (t => (
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { screen } from '@testing-library/react'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import WikiDetailPage from '@/pages/wiki/WikiDetailPage'
|
||||
import { buildTag, buildWikiPage } from '@/test/factories'
|
||||
import { renderWithProviders } from '@/test/render'
|
||||
|
||||
const wikiApi = vi.hoisted (() => ({
|
||||
fetchWikiPage: vi.fn (),
|
||||
fetchWikiPageByTitle: vi.fn (),
|
||||
}))
|
||||
|
||||
const tagsApi = vi.hoisted (() => ({
|
||||
fetchTagByName: vi.fn (),
|
||||
}))
|
||||
|
||||
const postsApi = vi.hoisted (() => ({
|
||||
fetchPosts: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/lib/wiki', () => wikiApi)
|
||||
vi.mock ('@/lib/tags', () => tagsApi)
|
||||
vi.mock ('@/lib/posts', () => postsApi)
|
||||
|
||||
describe ('WikiDetailPage', () => {
|
||||
it ('renders deprecated state outside the wiki title link', async () => {
|
||||
wikiApi.fetchWikiPageByTitle.mockResolvedValueOnce (buildWikiPage ({
|
||||
title: '旧タグ',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
}))
|
||||
tagsApi.fetchTagByName.mockResolvedValueOnce (buildTag ({
|
||||
name: '旧タグ',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
}))
|
||||
postsApi.fetchPosts.mockResolvedValueOnce ({ posts: [], count: 0 })
|
||||
|
||||
renderWithProviders (
|
||||
<Routes>
|
||||
<Route path="/wiki/:title" element={<WikiDetailPage/>}/>
|
||||
</Routes>,
|
||||
{ route: '/wiki/%E6%97%A7%E3%82%BF%E3%82%B0' },
|
||||
)
|
||||
|
||||
const marker = await screen.findByText ('(廃止)')
|
||||
const heading = marker.closest ('h1')
|
||||
const link = screen.getByRole ('link', { name: '旧タグ' })
|
||||
|
||||
expect (heading).not.toBeNull ()
|
||||
expect (heading!).toHaveTextContent ('旧タグ(廃止)')
|
||||
expect (link).toBeInTheDocument ()
|
||||
expect (marker.closest ('a')).toBeNull ()
|
||||
})
|
||||
})
|
||||
@@ -39,6 +39,7 @@ const WikiDetailPage: FC = () => {
|
||||
queryFn: () => fetchWikiPageByTitle (title, { version }) })
|
||||
|
||||
const effectiveTitle = wikiPage?.title ?? title
|
||||
const deprecated = wikiPage?.deprecatedAt != null
|
||||
|
||||
const { data: tag } = useQuery ({
|
||||
enabled: Boolean (effectiveTitle),
|
||||
@@ -88,7 +89,7 @@ const WikiDetailPage: FC = () => {
|
||||
return (
|
||||
<MainArea>
|
||||
<Helmet>
|
||||
<title>{`${ title } Wiki | ${ SITE_TITLE }`}</title>
|
||||
<title>{`${ effectiveTitle }${ deprecated ? '(廃止)' : '' } Wiki | ${ SITE_TITLE }`}</title>
|
||||
{!(wikiPage?.body) && <meta name="robots" content="noindex"/>}
|
||||
</Helmet>
|
||||
|
||||
@@ -110,10 +111,13 @@ const WikiDetailPage: FC = () => {
|
||||
|
||||
<article className="prose dark:prose-invert mx-auto p-4">
|
||||
<h1 className="prose-a:no-underline">
|
||||
<TagLink tag={tag ?? defaultTag}
|
||||
<TagLink tag={tag ?? { ...defaultTag,
|
||||
name: effectiveTitle,
|
||||
deprecatedAt: wikiPage?.deprecatedAt ?? null }}
|
||||
withWiki={false}
|
||||
withCount={false}
|
||||
{...(version && { to: `/wiki/${ encodeURIComponent (title) }` })}/>
|
||||
{deprecated && <span>(廃止)</span>}
|
||||
</h1>
|
||||
{loading ? <div>Loading...</div> : <WikiBody title={title} body={wikiPage?.body}/>}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ describe ('WikiDiffPage', () => {
|
||||
api.apiGet.mockResolvedValueOnce ({
|
||||
wikiPageId: 3,
|
||||
title: '差分対象',
|
||||
deprecatedAt: null,
|
||||
olderRevisionId: 1,
|
||||
newerRevisionId: 2,
|
||||
diff: [
|
||||
@@ -43,4 +44,26 @@ describe ('WikiDiffPage', () => {
|
||||
expect (screen.getByText ('added line')).toBeInTheDocument ()
|
||||
expect (screen.getByText ('removed line')).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('appends deprecated state to the wiki title', async () => {
|
||||
api.apiGet.mockResolvedValueOnce ({
|
||||
wikiPageId: 3,
|
||||
title: '廃止 Wiki',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
olderRevisionId: 1,
|
||||
newerRevisionId: 2,
|
||||
diff: [],
|
||||
})
|
||||
|
||||
renderWithProviders (
|
||||
<Routes>
|
||||
<Route path="/wiki/:id/diff" element={<WikiDiffPage/>}/>
|
||||
</Routes>,
|
||||
{ route: '/wiki/3/diff?from=1&to=2' },
|
||||
)
|
||||
|
||||
expect (await screen.findByRole ('heading', {
|
||||
name: '廃止 Wiki(廃止)',
|
||||
})).toBeInTheDocument ()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,6 +23,9 @@ const WikiDiffPage: FC = () => {
|
||||
const query = new URLSearchParams (location.search)
|
||||
const from = query.get ('from')
|
||||
const to = query.get ('to')
|
||||
const displayTitle = diff
|
||||
? `${ diff.title }${ diff.deprecatedAt != null ? '(廃止)' : '' }`
|
||||
: ''
|
||||
|
||||
useEffect (() => {
|
||||
void (async () => {
|
||||
@@ -33,9 +36,9 @@ const WikiDiffPage: FC = () => {
|
||||
return (
|
||||
<MainArea>
|
||||
<Helmet>
|
||||
<title>{`Wiki 差分: ${ diff?.title } | ${ SITE_TITLE }`}</title>
|
||||
<title>{`Wiki 差分: ${ displayTitle } | ${ SITE_TITLE }`}</title>
|
||||
</Helmet>
|
||||
<PageTitle>{diff?.title}</PageTitle>
|
||||
<PageTitle>{displayTitle}</PageTitle>
|
||||
<div className="prose mx-auto p-4">
|
||||
{diff
|
||||
? (
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { screen } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import WikiHistoryPage from '@/pages/wiki/WikiHistoryPage'
|
||||
import { renderWithProviders } from '@/test/render'
|
||||
|
||||
const api = vi.hoisted (() => ({
|
||||
apiGet: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/lib/api', () => api)
|
||||
|
||||
describe ('WikiHistoryPage', () => {
|
||||
it ('renders deprecated state outside the wiki title link', async () => {
|
||||
api.apiGet.mockResolvedValueOnce ([{
|
||||
revisionId: 2,
|
||||
pred: 1,
|
||||
succ: null,
|
||||
wikiPage: {
|
||||
id: 3,
|
||||
title: '旧タグ',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
},
|
||||
user: { id: 4, name: 'tester' },
|
||||
kind: 'content',
|
||||
message: 'updated',
|
||||
timestamp: '2026-06-02T00:00:00.000Z',
|
||||
}])
|
||||
|
||||
renderWithProviders (<WikiHistoryPage/>)
|
||||
|
||||
const link = await screen.findByRole ('link', { name: '旧タグ' })
|
||||
const marker = screen.getByText ('(廃止)')
|
||||
|
||||
expect (link).toHaveAttribute ('href', '/wiki/%E6%97%A7%E3%82%BF%E3%82%B0?version=2')
|
||||
expect (marker.closest ('a')).toBeNull ()
|
||||
})
|
||||
})
|
||||
@@ -59,6 +59,7 @@ const WikiHistoryPage: FC = () => {
|
||||
to={`/wiki/${ encodeURIComponent (change.wikiPage.title) }?version=${ change.revisionId }`}>
|
||||
{change.wikiPage.title}
|
||||
</PrefetchLink>
|
||||
{change.wikiPage.deprecatedAt != null && <span>(廃止)</span>}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
{change.pred == null ? '新規' : '更新'}
|
||||
|
||||
@@ -42,4 +42,21 @@ describe ('WikiSearchPage', () => {
|
||||
})
|
||||
expect (await screen.findByRole ('link', { name: '検索結果' })).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('marks deprecated wiki tags in the result title', async () => {
|
||||
api.apiGet.mockResolvedValueOnce ([
|
||||
buildWikiPage ({
|
||||
title: '旧タグ',
|
||||
deprecatedAt: '2026-06-01T00:00:00.000Z',
|
||||
}),
|
||||
])
|
||||
|
||||
renderWithProviders (<WikiSearchPage/>)
|
||||
|
||||
const link = await screen.findByRole ('link', { name: '旧タグ' })
|
||||
const marker = screen.getByText ('(廃止)')
|
||||
|
||||
expect (link).toBeInTheDocument ()
|
||||
expect (marker.closest ('a')).toBeNull ()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -86,6 +86,7 @@ const WikiSearchPage: FC = () => {
|
||||
<PrefetchLink to={`/wiki/${ encodeURIComponent (page.title) }`}>
|
||||
{page.title}
|
||||
</PrefetchLink>
|
||||
{page.deprecatedAt != null && <span>(廃止)</span>}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
{dateString (page.updatedAt)}
|
||||
|
||||
@@ -13,6 +13,7 @@ export const buildTag = (overrides: Partial<Tag> = {}): Tag => ({
|
||||
id: 1,
|
||||
name: 'テストタグ',
|
||||
category: 'general',
|
||||
deprecatedAt: null,
|
||||
aliases: [],
|
||||
parents: [],
|
||||
postCount: 12,
|
||||
@@ -57,6 +58,7 @@ export const buildUser = (overrides: Partial<User> = {}): User => ({
|
||||
export const buildWikiPage = (overrides: Partial<WikiPage> = {}): WikiPage => ({
|
||||
id: 1,
|
||||
title: 'テストWiki',
|
||||
deprecatedAt: null,
|
||||
createdUserId: 1,
|
||||
updatedUserId: 1,
|
||||
createdAt: '2026-01-02T03:04:05.000Z',
|
||||
|
||||
+18
-13
@@ -39,18 +39,19 @@ export type FetchTagsOrderField =
|
||||
| 'updated_at'
|
||||
|
||||
export type FetchTagsParams = {
|
||||
post: number | null
|
||||
name: string
|
||||
category: Category | null
|
||||
postCountGTE: number
|
||||
postCountLTE: number | null
|
||||
createdFrom: string
|
||||
createdTo: string
|
||||
updatedFrom: string
|
||||
updatedTo: string
|
||||
page: number
|
||||
limit: number
|
||||
order: FetchTagsOrder }
|
||||
post: number | null
|
||||
name: string
|
||||
category: Category | null
|
||||
postCountGTE: number
|
||||
postCountLTE: number | null
|
||||
createdFrom: string
|
||||
createdTo: string
|
||||
updatedFrom: string
|
||||
updatedTo: string
|
||||
deprecated: boolean | null
|
||||
page: number
|
||||
limit: number
|
||||
order: FetchTagsOrder }
|
||||
|
||||
export type FetchNicoTagsParams = {
|
||||
name: string
|
||||
@@ -196,6 +197,7 @@ export type Tag = {
|
||||
id: number
|
||||
name: string
|
||||
category: Category
|
||||
deprecatedAt: string | null
|
||||
aliases: string[]
|
||||
parents: Tag[]
|
||||
postCount: number
|
||||
@@ -213,6 +215,7 @@ export type TagVersion = {
|
||||
eventType: 'create' | 'update' | 'discard' | 'restore'
|
||||
name: { current: string; prev: string | null }
|
||||
category: { current: Category; prev: Category | null }
|
||||
deprecatedAt: { current: string | null; prev: string | null }
|
||||
aliases: { name: string; type: 'context' | 'added' | 'removed' }[]
|
||||
parentTags: { tag: Tag; type: 'context' | 'added' | 'removed' }[]
|
||||
createdAt: string
|
||||
@@ -296,6 +299,7 @@ export type ViewFlagBehavior = typeof ViewFlagBehavior[keyof typeof ViewFlagBeha
|
||||
export type WikiPage = {
|
||||
id: number
|
||||
title: string
|
||||
deprecatedAt: string | null
|
||||
createdUserId: number
|
||||
updatedUserId: number
|
||||
createdAt: string
|
||||
@@ -309,7 +313,7 @@ export type WikiPageChange = {
|
||||
revisionId: number
|
||||
pred: number | null
|
||||
succ: null
|
||||
wikiPage: Pick<WikiPage, 'id' | 'title'>
|
||||
wikiPage: Pick<WikiPage, 'id' | 'title' | 'deprecatedAt'>
|
||||
user: Pick<User, 'id' | 'name'>
|
||||
kind: 'content' | 'redirect'
|
||||
message: string | null
|
||||
@@ -318,6 +322,7 @@ export type WikiPageChange = {
|
||||
export type WikiPageDiff = {
|
||||
wikiPageId: number
|
||||
title: string
|
||||
deprecatedAt: string | null
|
||||
olderRevisionId: number | null
|
||||
newerRevisionId: number
|
||||
diff: WikiPageDiffDiff[] }
|
||||
|
||||
@@ -27,5 +27,6 @@
|
||||
"@/*": ["*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src"],
|
||||
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/test"]
|
||||
}
|
||||
|
||||
新しい課題から参照
ユーザをブロックする