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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| import { mount } from '@vue/test-utils';
|
| import { afterEach, describe, expect, it } from 'vitest';
|
| import TrendOptionPopup from '../TrendOptionPopup.vue';
|
| describe('trend option popup', () => {
| afterEach(() => {
| document.body.innerHTML = '';
| });
|
| it('does not render popup options into the page while the modal is closed', () => {
| const wrapper = mount(TrendOptionPopup, {
| attachTo: document.body,
| global: {
| stubs: {
| AEmpty: true,
| 'a-button': true,
| 'a-checkbox': true,
| 'a-input': true,
| 'a-radio': true,
| },
| },
| props: {
| options: [{ label: '纯化水', value: 'pw' }],
| popupTitle: '选择样品类型',
| },
| });
|
| expect(document.body.textContent).not.toContain('纯化水');
| wrapper.unmount();
| });
|
| it.each([
| ['single-select', false],
| ['multi-select', true],
| ])('applies the same modal body padding to %s popups', (_, multiple) => {
| const wrapper = mount(TrendOptionPopup, {
| global: {
| stubs: {
| AEmpty: true,
| AModal: {
| name: 'AModal',
| props: ['bodyStyle', 'destroyOnClose'],
| template: '<div><slot /></div>',
| },
| 'a-button': true,
| 'a-checkbox': true,
| 'a-input': true,
| 'a-radio': true,
| },
| },
| props: {
| multiple,
| options: [{ label: '纯化水', value: 'pw' }],
| popupTitle: '选择样品类型',
| },
| });
|
| const modal = wrapper.findComponent({ name: 'AModal' });
| expect(modal.props('bodyStyle')).toEqual({ padding: '16px' });
| expect(modal.props('destroyOnClose')).toBe(true);
| expect(wrapper.find('.popup-content').exists()).toBe(true);
| expect(wrapper.find('.popup-content > .popup-toolbar').classes('is-multiple')).toBe(multiple);
| expect(wrapper.find('.popup-content > .option-list').exists()).toBe(true);
| });
|
| it('uses a dropdown arrow for the trigger suffix', () => {
| const wrapper = mount(TrendOptionPopup, {
| global: {
| stubs: {
| AEmpty: true,
| AModal: true,
| 'a-button': true,
| 'a-checkbox': true,
| 'a-input': {
| template: '<div><slot name="suffix" /></div>',
| },
| 'a-radio': true,
| },
| },
| props: {
| options: [{ label: '纯化水', value: 'pw' }],
| popupTitle: '选择样品类型',
| value: 'pw',
| },
| });
|
| expect(wrapper.find('.dropdown-icon').exists()).toBe(true);
| expect(wrapper.find('[aria-label="清空"]').exists()).toBe(false);
| });
|
| it('confirms and returns a single option on double click', async () => {
| const wrapper = mount(TrendOptionPopup, {
| global: {
| stubs: {
| AEmpty: true,
| AModal: {
| template: '<div><slot /></div>',
| },
| 'a-button': true,
| 'a-checkbox': true,
| 'a-input': true,
| 'a-radio': true,
| },
| },
| props: {
| options: [{ label: '纯化水', value: 'pw' }],
| popupTitle: '选择样品类型',
| },
| });
|
| await wrapper.find('.option-row').trigger('dblclick');
|
| expect(wrapper.emitted('update:value')?.at(-1)).toEqual(['pw']);
| expect(wrapper.emitted('change')?.at(-1)).toEqual(['pw']);
| });
| });
|
|