feat: refine task and countdown interactions
This commit is contained in:
@@ -195,7 +195,28 @@ describe('countdown modal accessibility', () => {
|
||||
newPin.resolve(json({})); await flush()
|
||||
})
|
||||
|
||||
it('keeps the normal current-detail pin flow working', async () => {
|
||||
it('pins and unpins from detail without duplicate requests', async () => {
|
||||
const mutation = deferred<Response>()
|
||||
const pinned = { ...countdown, pinned: true }
|
||||
const fetchMock = vi.fn((url: string, options?: RequestInit) => {
|
||||
if (url.endsWith('/countdowns/c1/pin') && options?.method === 'DELETE') return mutation.promise
|
||||
if (url.endsWith('/countdowns')) return Promise.resolve(json([pinned]))
|
||||
if (url.includes('archived=true')) return Promise.resolve(json([]))
|
||||
throw new Error(`unexpected ${url}`)
|
||||
})
|
||||
const { host, notices } = await mountWithFetch(fetchMock)
|
||||
clickCountdown(host, '发布日'); await nextTick()
|
||||
const button = detailButton('取消置顶')
|
||||
button.click(); button.click()
|
||||
await nextTick()
|
||||
expect(fetchMock.mock.calls.filter(([url]) => String(url).endsWith('/countdowns/c1/pin'))).toHaveLength(1)
|
||||
expect(button.disabled).toBe(true)
|
||||
mutation.resolve(json({ ...pinned, pinned: false })); await flush()
|
||||
expect(notices).toEqual(['已取消置顶'])
|
||||
expect(document.querySelector('.countdown-detail-sheet')).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps normal current-detail pin flow working', async () => {
|
||||
const pin = deferred<Response>()
|
||||
const fetchMock = vi.fn((url: string) => {
|
||||
if (url.endsWith('/countdowns/c1/pin')) return pin.promise
|
||||
|
||||
Reference in New Issue
Block a user