刘光辉
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
import { mount } from '@vue/test-utils';
import { defineComponent, h } from 'vue';
 
import { Radio } from 'ant-design-vue';
import { describe, expect, it } from 'vitest';
 
import FileViewModeSwitch from '../FileViewModeSwitch.vue';
 
const TooltipStub = defineComponent({
  setup(_, { slots }) {
    return () => h('span', slots.default?.());
  },
});
 
describe('file view mode switch', () => {
  it('updates the selected view through the radio group', async () => {
    const wrapper = mount(FileViewModeSwitch, {
      props: { value: 'details' },
      global: {
        components: { 'a-radio-button': Radio.Button, 'a-radio-group': Radio.Group },
        stubs: { 'a-tooltip': TooltipStub },
      },
    });
 
    const radios = wrapper.findAll('input[type="radio"]');
    expect(radios).toHaveLength(2);
    expect((radios[0]!.element as HTMLInputElement).checked).toBe(true);
 
    await radios[1]!.setValue();
    expect(wrapper.emitted('update:value')?.at(-1)).toEqual(['tiles']);
 
    await wrapper.setProps({ value: 'tiles' });
    expect((radios[1]!.element as HTMLInputElement).checked).toBe(true);
  });
});