Skip to content

Commit cc1f9b8

Browse files
committed
Add test for datalist children updating
1 parent 6f6156c commit cc1f9b8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/controls/test/src/widget_string_test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,31 @@ describe('ComboboxView', function () {
8989
expect(el.getAttribute('value')).to.equal(input[i]);
9090
}
9191
});
92+
93+
it('updates datalist children when options are updated', function () {
94+
this.model.set({
95+
value: 'ABC',
96+
options: ['option1', 'option2', 'option3'],
97+
ensure_option: true,
98+
});
99+
const options = { model: this.model };
100+
const view = new widgets.ComboboxView(options);
101+
view.render();
102+
expect(view.datalist!.children.length).to.equal(3);
103+
for (let i = 0; i < view.datalist!.children.length; ++i) {
104+
const el = view.datalist!.children[i];
105+
expect(el.tagName.toLowerCase()).to.equal('option');
106+
expect(el.getAttributeNames()).to.eqls(['value']);
107+
expect(el.getAttribute('value')).to.equal(`option${i + 1}`);
108+
}
109+
110+
this.model.set({ options: ['option4', 'option5'] });
111+
expect(view.datalist!.children.length).to.equal(2);
112+
for (let i = 0; i < view.datalist!.children.length; ++i) {
113+
const el = view.datalist!.children[i];
114+
expect(el.tagName.toLowerCase()).to.equal('option');
115+
expect(el.getAttributeNames()).to.eqls(['value']);
116+
expect(el.getAttribute('value')).to.equal(`option${i + 4}`);
117+
}
118+
});
92119
});

0 commit comments

Comments
 (0)