This commit is contained in:
@@ -54,4 +54,29 @@ describe('BackendExplainContentProvider hall stop paging', () => {
|
||||
await expect(provider.listGuideStopsPageByHall('hall-1', 1, 20)).resolves.toMatchObject({ items: [], total: 0, hasMore: false })
|
||||
expect(attempts).toBe(2)
|
||||
})
|
||||
|
||||
it('reuses the short-lived persistent catalog cache across provider instances', async () => {
|
||||
const values = new Map<string, string>()
|
||||
vi.stubGlobal('window', {
|
||||
localStorage: {
|
||||
getItem: (key: string) => values.get(key) || null,
|
||||
setItem: (key: string, value: string) => values.set(key, value),
|
||||
removeItem: (key: string) => values.delete(key)
|
||||
}
|
||||
})
|
||||
const requests: string[] = []
|
||||
installRequest((url) => {
|
||||
requests.push(url)
|
||||
if (url.includes('/catalog/halls?')) return { code: 0, data: [{ id: 'hall-1', name: '恐龙厅' }] }
|
||||
return { code: 0, data: { list: [{ stopId: 'stop-1', name: '对象一' }], total: 1 } }
|
||||
})
|
||||
|
||||
const firstProvider = new BackendExplainContentProvider()
|
||||
const secondProvider = new BackendExplainContentProvider()
|
||||
await firstProvider.listGuideStopsPageByHall('hall-1', 1, 20)
|
||||
await secondProvider.listGuideStopsPageByHall('hall-1', 1, 20)
|
||||
|
||||
expect(requests.filter((url) => url.includes('/catalog/halls?'))).toHaveLength(1)
|
||||
expect(requests.filter((url) => url.includes('/stops/page'))).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user