刘光辉
5 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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();
  });
});