刘光辉
15 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
43
44
45
46
47
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
 
import { vResizable } from '../resizable';
 
function mountResizable(el: HTMLElement) {
  if (typeof vResizable.mounted === 'function') {
    vResizable.mounted(el, undefined as never, undefined as never, undefined as never);
  }
}
 
function appendAntModal(modalClass = '') {
  const wrap = document.createElement('div');
  wrap.className = 'ant-modal-wrap';
  wrap.innerHTML = `
    <div class="ant-modal ${modalClass}">
      <div class="ant-modal-content"></div>
    </div>
  `;
  document.body.append(wrap);
  return wrap;
}
 
describe('modal resizable directive', () => {
  beforeEach(() => {
    document.body.innerHTML = '';
  });
 
  afterEach(() => {
    document.body.innerHTML = '';
  });
 
  it('should add resize handle to normal ant modal', () => {
    const wrap = appendAntModal();
 
    mountResizable(wrap);
 
    expect(wrap.querySelector('.modal-resize-handle')).not.toBeNull();
  });
 
  it('should not add resize handle to ant confirm modal', () => {
    const wrap = appendAntModal('ant-modal-confirm');
 
    mountResizable(wrap);
 
    expect(wrap.querySelector('.modal-resize-handle')).toBeNull();
  });
});