Reviewed-on: #433 Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #433 でマージされました。
このコミットが含まれているのは:
@@ -21,6 +21,9 @@ const wikiApi = vi.hoisted (() => ({
|
||||
fetchWikiPage: vi.fn (),
|
||||
fetchWikiPageByTitle: vi.fn (),
|
||||
fetchWikiPages: vi.fn (),
|
||||
fetchWikiPageByReference: vi.fn (),
|
||||
fetchWikiAutolinkCandidates: vi.fn (),
|
||||
fetchWikiTag: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/lib/posts', () => postsApi)
|
||||
@@ -45,12 +48,15 @@ describe ('prefetchForURL', () => {
|
||||
wikiApi.fetchWikiPages.mockResolvedValue ([])
|
||||
wikiApi.fetchWikiPage.mockResolvedValue ({ id: 1 })
|
||||
wikiApi.fetchWikiPageByTitle.mockResolvedValue (null)
|
||||
wikiApi.fetchWikiPageByReference.mockResolvedValue (null)
|
||||
wikiApi.fetchWikiAutolinkCandidates.mockResolvedValue ([])
|
||||
wikiApi.fetchWikiTag.mockResolvedValue (null)
|
||||
})
|
||||
|
||||
it ('prefetches post indexes from query parameters', async () => {
|
||||
await prefetchForURL (
|
||||
qc (),
|
||||
'http://localhost/posts?tags=a+b&match=any&page=2&limit=5&order=title%3Aasc',
|
||||
'/ja/posts?tags=a+b&match=any&page=2&limit=5&order=title%3Aasc',
|
||||
)
|
||||
|
||||
expect (postsApi.fetchPosts).toHaveBeenCalledWith (
|
||||
@@ -60,20 +66,20 @@ describe ('prefetchForURL', () => {
|
||||
page: 2,
|
||||
limit: 5,
|
||||
order: 'title:asc',
|
||||
}),
|
||||
}), 'ja',
|
||||
)
|
||||
})
|
||||
|
||||
it ('prefetches post detail pages', async () => {
|
||||
await prefetchForURL (qc (), 'http://localhost/posts/12')
|
||||
await prefetchForURL (qc (), '/ja/posts/12')
|
||||
|
||||
expect (postsApi.fetchPost).toHaveBeenCalledWith ('12')
|
||||
expect (postsApi.fetchPost).toHaveBeenCalledWith ('12', 'ja')
|
||||
})
|
||||
|
||||
it ('prefetches tag indexes from query parameters', async () => {
|
||||
await prefetchForURL (
|
||||
qc (),
|
||||
'http://localhost/tags?post=9&name=x&category=general&page=4&post_count_lte=10',
|
||||
'/ja/tags?post=9&name=x&category=general&page=4&post_count_lte=10',
|
||||
)
|
||||
|
||||
expect (tagsApi.fetchTags).toHaveBeenCalledWith (
|
||||
@@ -83,17 +89,17 @@ describe ('prefetchForURL', () => {
|
||||
category: 'general',
|
||||
page: 4,
|
||||
postCountLTE: 10,
|
||||
}),
|
||||
}), 'ja',
|
||||
)
|
||||
})
|
||||
|
||||
it ('prefetches nico tag indexes and their alias from query parameters', async () => {
|
||||
await prefetchForURL (
|
||||
qc (),
|
||||
'http://localhost/tags/nico?name=source&linked_tag=destination'
|
||||
'/ja/tags/nico?name=source&linked_tag=destination'
|
||||
+ '&link_status=linked&page=3&limit=10',
|
||||
)
|
||||
await prefetchForURL (qc (), 'http://localhost/nico/tags?page=2')
|
||||
await prefetchForURL (qc (), '/ja/nico/tags?page=2')
|
||||
|
||||
expect (tagsApi.fetchNicoTags).toHaveBeenNthCalledWith (1, {
|
||||
name: 'source',
|
||||
@@ -102,7 +108,7 @@ describe ('prefetchForURL', () => {
|
||||
page: 3,
|
||||
limit: 10,
|
||||
order: 'updated_at:desc',
|
||||
})
|
||||
}, 'ja')
|
||||
expect (tagsApi.fetchNicoTags).toHaveBeenNthCalledWith (2, {
|
||||
name: '',
|
||||
linkedTag: '',
|
||||
@@ -110,28 +116,29 @@ describe ('prefetchForURL', () => {
|
||||
page: 2,
|
||||
limit: 20,
|
||||
order: 'updated_at:desc',
|
||||
})
|
||||
}, 'ja')
|
||||
})
|
||||
|
||||
it ('prefetches wiki show pages and related tag/post data', async () => {
|
||||
wikiApi.fetchWikiPageByTitle.mockResolvedValueOnce ({
|
||||
wikiApi.fetchWikiPageByReference.mockResolvedValueOnce ({
|
||||
id: 3,
|
||||
title: 'Actual',
|
||||
body: 'body',
|
||||
})
|
||||
|
||||
await prefetchForURL (qc (), 'http://localhost/wiki/Alias')
|
||||
await prefetchForURL (qc (), '/ja/wiki/Alias')
|
||||
|
||||
expect (wikiApi.fetchWikiPageByTitle).toHaveBeenCalledWith ('Alias', { version: undefined })
|
||||
expect (wikiApi.fetchWikiPage).toHaveBeenCalledWith ('3', {})
|
||||
expect (tagsApi.fetchTagByName).toHaveBeenCalledWith ('Actual')
|
||||
expect (wikiApi.fetchWikiPageByReference).toHaveBeenCalledWith (
|
||||
'Alias', { version: undefined }, 'ja')
|
||||
expect (wikiApi.fetchWikiPage).not.toHaveBeenCalled ()
|
||||
expect (wikiApi.fetchWikiTag).toHaveBeenCalledWith ({ name: 'Actual' }, 'ja')
|
||||
expect (postsApi.fetchPosts).toHaveBeenCalledWith (
|
||||
expect.objectContaining ({ tags: 'Actual', limit: 8 }),
|
||||
expect.objectContaining ({ tags: 'Actual', limit: 8 }), 'ja',
|
||||
)
|
||||
})
|
||||
|
||||
it ('ignores routes without a prefetcher', async () => {
|
||||
await prefetchForURL (qc (), 'http://localhost/unknown')
|
||||
await prefetchForURL (qc (), '/ja/unknown')
|
||||
|
||||
expect (postsApi.fetchPosts).not.toHaveBeenCalled ()
|
||||
expect (tagsApi.fetchTags).not.toHaveBeenCalled ()
|
||||
@@ -141,14 +148,14 @@ describe ('prefetchForURL', () => {
|
||||
it ('prefetches external tag post history without treating it as an internal tag', async () => {
|
||||
await prefetchForURL (
|
||||
qc (),
|
||||
'http://localhost/posts/changes?external_tag=12&page=2&limit=50',
|
||||
'/ja/posts/changes?external_tag=12&page=2&limit=50',
|
||||
)
|
||||
|
||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledWith ({
|
||||
externalTag: '12',
|
||||
page: 2,
|
||||
limit: 50,
|
||||
})
|
||||
}, 'ja')
|
||||
|
||||
expect (tagsApi.fetchTag).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする