import { describe, expect, it, vi } from 'vitest';
|
|
import { createListScopedOnlineUtils } from './listOnlineUtils';
|
|
describe('createListScopedOnlineUtils', () => {
|
it('delegates non-list loading calls to the inherited online utils', () => {
|
const showLoading = vi.fn();
|
const hideLoading = vi.fn();
|
const setLoading = vi.fn();
|
const { onlineUtils } = createListScopedOnlineUtils({ hideLoading, showLoading }, setLoading);
|
const options = { scope: 'form' };
|
|
onlineUtils.showLoading('加载中', options);
|
onlineUtils.hideLoading(options);
|
|
expect(showLoading).toHaveBeenCalledWith('加载中', options);
|
expect(hideLoading).toHaveBeenCalledWith(options);
|
expect(setLoading).not.toHaveBeenCalled();
|
});
|
|
it('keeps the list mask visible until all scoped loading calls finish', () => {
|
const showLoading = vi.fn();
|
const hideLoading = vi.fn();
|
const setLoading = vi.fn();
|
const { onlineUtils } = createListScopedOnlineUtils({ hideLoading, showLoading }, setLoading);
|
const options = { scope: 'list' };
|
|
onlineUtils.showLoading('第一次', options);
|
onlineUtils.showLoading('第二次', options);
|
onlineUtils.hideLoading(options);
|
|
expect(setLoading).toHaveBeenNthCalledWith(1, true, '第一次');
|
expect(setLoading).toHaveBeenNthCalledWith(2, true, '第二次');
|
expect(setLoading).toHaveBeenCalledTimes(2);
|
|
onlineUtils.hideLoading(options);
|
|
expect(setLoading).toHaveBeenLastCalledWith(false);
|
expect(showLoading).not.toHaveBeenCalled();
|
expect(hideLoading).not.toHaveBeenCalled();
|
});
|
});
|