mirror of
https://github.com/Choices-js/Choices.git
synced 2026-03-14 14:45:47 +01:00
test: add unit tests for wide CJK character handling in setWidth()
Three new cases under 'setWidth > wide (CJK / fullwidth) characters': - Japanese placeholder 'エリアを選択してください' (122ch) minWidth 25ch - Japanese value 'テスト' (32ch) width 7ch - Mixed ASCII + CJK value 'abcテ' (31 + 12 = 5ch) width 6ch All 356 unit tests pass.
This commit is contained in:
parent
2d5bfd31f2
commit
8ddbe35d9f
1 changed files with 26 additions and 0 deletions
|
|
@ -270,6 +270,32 @@ describe('components/input', () => {
|
|||
expect(instance.element.style.width).to.equal('16ch');
|
||||
expect(instance.element.style.minWidth).to.equal('22ch');
|
||||
});
|
||||
|
||||
describe('wide (CJK / fullwidth) characters', () => {
|
||||
it('counts each Japanese character as 2ch for placeholder min-width', () => {
|
||||
// 'エリアを選択してください' = 12 wide chars → 12×2 = 24ch → minWidth 25ch
|
||||
instance.placeholder = 'エリアを選択してください';
|
||||
instance.element.value = '';
|
||||
instance.setWidth();
|
||||
expect(instance.element.style.minWidth).to.equal('25ch');
|
||||
});
|
||||
|
||||
it('counts each Japanese character as 2ch for value width', () => {
|
||||
// 'テスト' = 3 wide chars → 3×2 = 6ch → width 7ch
|
||||
instance.placeholder = '';
|
||||
instance.element.value = 'テスト';
|
||||
instance.setWidth();
|
||||
expect(instance.element.style.width).to.equal('7ch');
|
||||
});
|
||||
|
||||
it('mixes ASCII and CJK characters correctly', () => {
|
||||
// 'abc' (3×1) + 'テ' (1×2) = 5ch → width 6ch
|
||||
instance.placeholder = '';
|
||||
instance.element.value = 'abcテ';
|
||||
instance.setWidth();
|
||||
expect(instance.element.style.width).to.equal('6ch');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('placeholder setter', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue