Skip to content

Commit a4b35d6

Browse files
thetpetschki
authored andcommitted
maint(pat-select2): Add test for predefined value for a select widget.
1 parent 063bc09 commit a4b35d6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/pat/select2/select2.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ describe("Select2", function () {
123123
expect($(el).parent().find(".select2-chosen").text()).toEqual("Europe/Vienna");
124124
});
125125

126+
it("renders the preset value of a single-select select widget", async function () {
127+
document.body.innerHTML = `
128+
<select class="pat-select2">
129+
<option value="Europe/Paris">Europe/Paris</option>
130+
<option value="Europe/Vienna" selected>Europe/Vienna</option>
131+
</select>
132+
`;
133+
134+
registry.scan(document.body);
135+
await utils.timeout(1);
136+
137+
const el = document.querySelector("select.pat-select2");
138+
// For a native <select>, select2 v3 attaches extra metadata to the
139+
// data object (element, disabled, locked, ...), so match a subset.
140+
expect($(el).select2("data")).toMatchObject({
141+
id: "Europe/Vienna",
142+
text: "Europe/Vienna",
143+
});
144+
expect($(el).parent().find(".select2-chosen").text()).toEqual("Europe/Vienna");
145+
});
146+
126147
it("displays the vocabulary when clicking an empty checkbox", async function () {
127148
document.body.innerHTML = `
128149
<input type="hidden"

0 commit comments

Comments
 (0)