Skip to content

Commit bba3762

Browse files
committed
chore: add e2e for clear and filter
1 parent e113bb0 commit bba3762

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

packages/pluggableWidgets/combobox-web/e2e/Combobox.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test.describe("combobox-web", () => {
1010
await page.goto("/p/combobox");
1111
await page.waitForLoadState("networkidle");
1212
await page.click(".mx-name-actionButton1");
13+
await page.waitForLoadState("networkidle");
1314
});
1415

1516
test.describe("data source types", () => {
@@ -125,4 +126,70 @@ test.describe("combobox-web", () => {
125126
});
126127
});
127128
});
129+
130+
test.describe("searching and selecting", () => {
131+
test("clears with backspace", async ({ page }) => {
132+
const comboBox = page.locator(".mx-name-comboBox2");
133+
await expect(comboBox).toBeVisible({ timeout: 10000 });
134+
135+
// check nothing is selected
136+
await expect(getSelectedText(comboBox)).toContainClass("widget-combobox-placeholder-empty");
137+
138+
// open the dropdown
139+
await page.click(".mx-name-comboBox2");
140+
141+
// select europe
142+
await getOptionItem(comboBox, "Europe").click({ delay: 10 });
143+
await expect(getSelectedText(comboBox)).toContainText("Europe");
144+
145+
// check input stays focused
146+
await expect(getFilterInput(comboBox)).toBeFocused();
147+
148+
// press Backspace to clear
149+
await page.keyboard.press("Backspace");
150+
151+
// check if cleared
152+
await expect(getSelectedText(comboBox)).toContainClass("widget-combobox-placeholder-empty");
153+
});
154+
155+
test("types filter when selected", async ({ page }) => {
156+
const comboBox = page.locator(".mx-name-comboBox2");
157+
await expect(comboBox).toBeVisible({ timeout: 10000 });
158+
159+
// check nothing is selected
160+
await expect(getSelectedText(comboBox)).toContainClass("widget-combobox-placeholder-empty");
161+
162+
// open the dropdown
163+
await page.click(".mx-name-comboBox2");
164+
165+
// select europe
166+
await getOptionItem(comboBox, "Europe").click({ delay: 10 });
167+
await expect(getSelectedText(comboBox)).toContainText("Europe");
168+
169+
// check input stays focused
170+
await expect(getFilterInput(comboBox)).toBeFocused();
171+
172+
// type filter text
173+
await page.keyboard.type("aaa");
174+
175+
// check if filtered
176+
await expect(getOptions(comboBox)).toHaveText(["Antartica", "Australia"]);
177+
});
178+
});
128179
});
180+
181+
function getOptions(combobox) {
182+
return combobox.locator(`[role=listbox] [role=option]`);
183+
}
184+
185+
function getOptionItem(combobox, text) {
186+
return combobox.locator(`[role=listbox] [role=option]:has-text("${text}")`);
187+
}
188+
189+
function getSelectedText(combobox) {
190+
return combobox.locator(".widget-combobox-placeholder-text");
191+
}
192+
193+
function getFilterInput(combobox) {
194+
return combobox.locator("input");
195+
}

0 commit comments

Comments
 (0)