#419 フロントのテスト追加
このコミットが含まれているのは:
@@ -0,0 +1,44 @@
|
||||
import { waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import PostHistoryPage from '@/pages/posts/PostHistoryPage'
|
||||
import { renderWithProviders } from '@/test/render'
|
||||
|
||||
const postsApi = vi.hoisted (() => ({
|
||||
fetchPostChanges: vi.fn (),
|
||||
updatePost: vi.fn (),
|
||||
}))
|
||||
|
||||
const tagsApi = vi.hoisted (() => ({
|
||||
fetchTag: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/lib/posts', () => postsApi)
|
||||
vi.mock ('@/lib/tags', () => tagsApi)
|
||||
|
||||
describe ('PostHistoryPage', () => {
|
||||
beforeEach (() => {
|
||||
vi.clearAllMocks ()
|
||||
postsApi.fetchPostChanges.mockResolvedValue ({
|
||||
versions: [],
|
||||
count: 0,
|
||||
})
|
||||
})
|
||||
|
||||
it ('filters by external_tag without resolving the id as an internal tag', async () => {
|
||||
renderWithProviders (
|
||||
<PostHistoryPage/>,
|
||||
{ route: '/posts/changes?external_tag=7' },
|
||||
)
|
||||
|
||||
await waitFor (() => {
|
||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledWith ({
|
||||
externalTag: '7',
|
||||
page: 1,
|
||||
limit: 20,
|
||||
})
|
||||
})
|
||||
|
||||
expect (tagsApi.fetchTag).not.toHaveBeenCalled ()
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import TagListPage from '@/pages/tags/TagListPage'
|
||||
@@ -127,4 +127,49 @@ describe ('TagListPage', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it ('keeps colliding internal and external tags on their own routes', async () => {
|
||||
const internal = buildTag ({
|
||||
id: 7,
|
||||
name: 'internal_collision',
|
||||
category: 'general',
|
||||
})
|
||||
const external = buildTag ({
|
||||
id: 7,
|
||||
name: 'nico:external_collision',
|
||||
category: 'nico',
|
||||
})
|
||||
|
||||
tagsApi.fetchTags.mockResolvedValueOnce ({
|
||||
tags: [internal, external],
|
||||
count: 2,
|
||||
})
|
||||
|
||||
renderWithProviders (<TagListPage/>, { route: '/tags' })
|
||||
|
||||
const internalLink =
|
||||
await screen.findByRole ('link', { name: 'internal_collision' })
|
||||
const externalLink =
|
||||
screen.getByRole ('link', { name: 'nico:external_collision' })
|
||||
|
||||
expect (internalLink).toHaveAttribute ('href', '/tags/7')
|
||||
expect (externalLink).toHaveAttribute (
|
||||
'href',
|
||||
'/tags/nico?name=nico%3Aexternal_collision',
|
||||
)
|
||||
|
||||
const internalRow = internalLink.closest ('tr')
|
||||
const externalRow = externalLink.closest ('tr')
|
||||
|
||||
expect (internalRow).not.toBeNull ()
|
||||
expect (externalRow).not.toBeNull ()
|
||||
|
||||
expect (
|
||||
within (internalRow!).getByRole ('link', { name: '耕作履歴' }),
|
||||
).toHaveAttribute ('href', '/posts/changes?tag=7')
|
||||
|
||||
expect (
|
||||
within (externalRow!).getByRole ('link', { name: '耕作履歴' }),
|
||||
).toHaveAttribute ('href', '/posts/changes?external_tag=7')
|
||||
})
|
||||
})
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする