优化
This commit is contained in:
@@ -71,3 +71,25 @@ it.each(['warehouse', 'page', 'version'])('rejects a mismatched %s response inst
|
||||
await state.load({ warehouseId: '321' })
|
||||
expect(state.candidates.value).toEqual([]); expect(state.error.value).not.toBeNull()
|
||||
})
|
||||
|
||||
it.each(['success', 'failure'])('keeps rows stable during a refresh but rejects their use until %s is resolved', async outcome => {
|
||||
const state = setup(), refresh = deferred()
|
||||
vi.mocked(listDispatchCandidates).mockResolvedValueOnce(response()).mockReturnValueOnce(refresh.promise)
|
||||
await state.load({ warehouseId: '321' })
|
||||
const previous = state.candidates.value
|
||||
const request = state.load({ warehouseId: '321' })
|
||||
expect(state.candidates.value).toBe(previous)
|
||||
expect(state.total.value).toBe(41)
|
||||
expect(() => state.assertCurrent(previous)).toThrow('尚未读取完成')
|
||||
if (outcome === 'success') refresh.resolve(response({ total: 1 }))
|
||||
else refresh.reject(new Error('refresh failed'))
|
||||
await request
|
||||
if (outcome === 'success') {
|
||||
expect(state.total.value).toBe(1)
|
||||
expect(() => state.assertCurrent(state.candidates.value)).not.toThrow()
|
||||
} else {
|
||||
expect(state.candidates.value).toEqual([])
|
||||
expect(state.error.value?.message).toBeTruthy()
|
||||
expect(() => state.assertCurrent(previous)).toThrow('尚未读取完成')
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user