import { describe, expect, it, vi } from 'vitest';
|
|
import { createFormScopedOnlineUtils } from './formOnlineUtils';
|
|
describe('createFormScopedOnlineUtils', () => {
|
it('delegates global loading calls to the inherited online utils', () => {
|
const showLoading = vi.fn();
|
const hideLoading = vi.fn();
|
const setLoading = vi.fn();
|
const { onlineUtils } = createFormScopedOnlineUtils({ hideLoading, showLoading }, setLoading);
|
|
onlineUtils.showLoading('加载中');
|
onlineUtils.hideLoading();
|
|
expect(showLoading).toHaveBeenCalledWith('加载中', undefined);
|
expect(hideLoading).toHaveBeenCalledWith(undefined);
|
expect(setLoading).not.toHaveBeenCalled();
|
});
|
|
it('keeps the form mask visible until all scoped loading calls finish', () => {
|
const showLoading = vi.fn();
|
const hideLoading = vi.fn();
|
const setLoading = vi.fn();
|
const { onlineUtils } = createFormScopedOnlineUtils({ hideLoading, showLoading }, setLoading);
|
const options = { scope: 'form' };
|
|
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();
|
});
|
});
|