Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(select): add test cases for select component #4956

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/select/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Select, OptionGroup, Option } from '@/src/select/index.ts';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue-next';

const options = [
{ label: '全选', checkAll: true }, // 添加 checkAll 选项
{ label: '架构云', value: '1' },
{ label: '大数据', value: '2' },
{ label: '区块链', value: '3' },
Expand All @@ -28,7 +29,7 @@ describe('Select', () => {
await wrapper.setProps({ popupProps: { visible: true } });

const panelNode = document.querySelector('.t-select__list');
expect(document.querySelectorAll('.t-select-option').length).toBe(6);
expect(document.querySelectorAll('.t-select-option').length).toBe(7);
expect(document.querySelectorAll('.t-is-disabled').length).toBe(1);
expect(document.querySelectorAll('p').length).toBe(1);
panelNode.parentNode.removeChild(panelNode);
Expand All @@ -43,7 +44,7 @@ describe('Select', () => {
await wrapper.setProps({ popupProps: { visible: true } });

const panelNode = document.querySelector('.t-select__list');
expect(document.querySelectorAll('.t-checkbox').length).toBe(6);
expect(document.querySelectorAll('.t-checkbox').length).toBe(7);
panelNode.parentNode.removeChild(panelNode);
});
});
Expand Down Expand Up @@ -312,3 +313,47 @@ describe('Select OptionGroup', () => {
});
});
});
describe('Select CheckAll with Disabled Option', () => {
const setupTest = async (initialValue) => {
const value = ref(initialValue);
const wrapper = mount({
setup() {
return { value };
},
render() {
return <Select v-model={value.value} options={options} multiple />;
},
});

await wrapper.setProps({ popupProps: { visible: true } });
const checkAllCheckbox = document.querySelector('li[title="全选"] .t-checkbox');

return {
value,
wrapper,
checkAllCheckbox,
cleanup: () => {
const panelNode = document.querySelector('.t-select__list');
panelNode.parentNode.removeChild(panelNode);
},
};
};

it('should keep disabled option state consistent regardless of checkAll', async () => {
// 测试 disabled 选项默认选中
let { value, checkAllCheckbox, cleanup } = await setupTest(['1', '4']);
await checkAllCheckbox.click();
expect(value.value).toContain('4');
await checkAllCheckbox.click();
expect(value.value).toContain('4');
cleanup();

// 测试 disabled 选项默认未选中
({ value, checkAllCheckbox, cleanup } = await setupTest([]));
await checkAllCheckbox.click();
expect(value.value).not.toContain('4');
await checkAllCheckbox.click();
expect(value.value).not.toContain('4');
cleanup();
});
});
Loading