import { mount } from '@vue/test-utils';
|
|
import { describe, expect, it } from 'vitest';
|
|
import TrendTablePopup from '../TrendTablePopup.vue';
|
|
const options = [
|
{ code: 'W-1', label: 'W-1', location: '制水间使用点', value: 'point-1' },
|
{ code: 'W-2', label: 'W-2', location: '灌装间回水口', value: 'point-2' },
|
];
|
|
const columns = [
|
{ dataIndex: 'code', key: 'code', title: '取样点编号', width: 180 },
|
{ dataIndex: 'location', key: 'location', title: '取样地点' },
|
];
|
|
function mountPopup() {
|
return mount(TrendTablePopup, {
|
global: {
|
stubs: {
|
AModal: {
|
name: 'AModal',
|
props: ['bodyStyle', 'destroyOnClose', 'open', 'width'],
|
template: '<div><slot /></div>',
|
},
|
'a-button': true,
|
'a-input': {
|
template: '<div class="input-stub" @click="$emit(\'click\')"><slot name="suffix" /></div>',
|
},
|
'a-table': {
|
name: 'ATable',
|
props: ['columns', 'customRow', 'dataSource', 'pagination', 'rowKey', 'rowSelection', 'scroll'],
|
template: '<div />',
|
},
|
},
|
},
|
props: {
|
columns,
|
options,
|
placeholder: '全部取样点',
|
popupTitle: '选择取样点',
|
value: ['point-1'],
|
width: 760,
|
},
|
});
|
}
|
|
describe('trend table popup', () => {
|
it('configures a paginated table with consistent modal spacing', async () => {
|
const wrapper = mountPopup();
|
await wrapper.find('.input-stub').trigger('click');
|
const modal = wrapper.findComponent({ name: 'AModal' });
|
const table = wrapper.findComponent({ name: 'ATable' });
|
|
expect(modal.props('bodyStyle')).toEqual({ padding: '16px' });
|
expect(modal.props('destroyOnClose')).toBe(true);
|
expect(modal.props('width')).toBe(760);
|
expect(table.props('columns')).toEqual(columns);
|
expect(table.props('pagination')).toMatchObject({ pageSize: 25, showSizeChanger: true });
|
expect(table.props('rowKey')).toBe('value');
|
expect(table.props('rowSelection')).toMatchObject({ preserveSelectedRowKeys: true, selectedRowKeys: ['point-1'] });
|
expect(wrapper.find('.fixed-height-table').exists()).toBe(true);
|
expect(wrapper.find('.dropdown-icon').exists()).toBe(true);
|
expect(wrapper.find('[aria-label="清空"]').exists()).toBe(false);
|
expect(wrapper.find('a-button-stub').exists()).toBe(false);
|
});
|
|
it('emits only selected ids when the modal is confirmed', async () => {
|
const wrapper = mountPopup();
|
const table = wrapper.findComponent({ name: 'ATable' });
|
|
table.props('rowSelection').onChange(['point-1', 'point-2']);
|
await wrapper.findComponent({ name: 'AModal' }).vm.$emit('ok');
|
|
expect(wrapper.emitted('update:value')?.at(-1)).toEqual([['point-1', 'point-2']]);
|
expect(wrapper.emitted('change')?.at(-1)).toEqual([['point-1', 'point-2']]);
|
});
|
|
it('toggles selection when a table row is clicked', async () => {
|
const wrapper = mountPopup();
|
await wrapper.find('.input-stub').trigger('click');
|
const table = wrapper.findComponent({ name: 'ATable' });
|
|
table
|
.props('customRow')(options[1])
|
.onClick({ target: { closest: () => null } });
|
await wrapper.findComponent({ name: 'AModal' }).vm.$emit('ok');
|
|
expect(wrapper.emitted('update:value')?.at(-1)).toEqual([['point-1', 'point-2']]);
|
});
|
});
|