12 lines
898 B
JavaScript
12 lines
898 B
JavaScript
|
|
import {it,expect,vi} from 'vitest'
|
||
|
|
import request from '@/utils/request'
|
||
|
|
import {amountDisplay,loadAmountDisplay,saveAmountDisplay} from '../../src/utils/amount-display'
|
||
|
|
vi.mock('@/utils/request',()=>({default:vi.fn()}))
|
||
|
|
it('shared display loads deduplicate and an old response cannot overwrite a newly saved global switch',async()=>{
|
||
|
|
let finish;request.mockImplementation(options=>options.method==='put'?Promise.resolve({data:{enabled:true}}):new Promise(resolve=>{finish=resolve}))
|
||
|
|
const first=loadAmountDisplay(),second=loadAmountDisplay();expect(first).toBe(second);expect(request).toHaveBeenCalledTimes(1)
|
||
|
|
await saveAmountDisplay(true);expect(amountDisplay.enabled).toBe(true)
|
||
|
|
finish({data:{enabled:false}});await first;expect(amountDisplay.enabled).toBe(true)
|
||
|
|
request.mockResolvedValue({data:{enabled:false}});await loadAmountDisplay();expect(amountDisplay.enabled).toBe(false)
|
||
|
|
})
|