Skip to content

Commit 1a411f0

Browse files
committed
test(toggle): add ionBlur tests
1 parent 1d26570 commit 1a411f0

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

core/src/components/toggle/test/basic/toggle.e2e.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,73 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, c
215215
expect(ionFocus).not.toHaveReceivedEvent();
216216
});
217217
});
218+
219+
test.describe(title('toggle: ionBlur'), () => {
220+
test('should fire ionBlur when toggle is blurred', async ({ page, pageUtils }) => {
221+
await page.setContent(
222+
`
223+
<ion-toggle aria-label="toggle" value="my-toggle"></ion-toggle>
224+
`,
225+
config
226+
);
227+
228+
const ionBlur = await page.spyOnEvent('ionBlur');
229+
230+
// Test blur with keyboard navigation.
231+
// Focus the toggle.
232+
await pageUtils.pressKeys('Tab');
233+
// Blur the toggle.
234+
await pageUtils.pressKeys('Tab');
235+
236+
expect(ionBlur).toHaveReceivedEventTimes(1);
237+
238+
// Test blur with click.
239+
const toggle = page.locator('ion-toggle');
240+
// Focus the toggle.
241+
await toggle.click();
242+
// Blur the toggle by clicking outside of it.
243+
const toggleBoundingBox = (await toggle.boundingBox())!;
244+
await page.mouse.click(0, toggleBoundingBox.height + 1);
245+
246+
expect(ionBlur).toHaveReceivedEventTimes(2);
247+
});
248+
249+
test('should fire ionBlur after interacting with toggle in item', async ({ page, pageUtils }) => {
250+
await page.setContent(
251+
`
252+
<ion-item>
253+
<ion-toggle aria-label="toggle" value="my-toggle"></ion-toggle>
254+
</ion-item>
255+
`,
256+
config
257+
);
258+
259+
const ionBlur = await page.spyOnEvent('ionBlur');
260+
261+
// Test blur with keyboard navigation.
262+
// Focus the toggle.
263+
await pageUtils.pressKeys('Tab');
264+
// Blur the toggle.
265+
await pageUtils.pressKeys('Tab');
266+
267+
expect(ionBlur).toHaveReceivedEventTimes(1);
268+
269+
// Verify that the event target is the toggle and not the item.
270+
const event = ionBlur.events[0];
271+
expect((event.target as HTMLElement).tagName.toLowerCase()).toBe('ion-toggle');
272+
273+
// Test blur with click.
274+
const item = page.locator('ion-item');
275+
await item.click();
276+
// Blur the toggle by clicking outside of it.
277+
const itemBoundingBox = (await item.boundingBox())!;
278+
await page.mouse.click(0, itemBoundingBox.height + 1);
279+
280+
expect(ionBlur).toHaveReceivedEventTimes(2);
281+
282+
// Verify that the event target is the toggle and not the item.
283+
const eventByClick = ionBlur.events[0];
284+
expect((eventByClick.target as HTMLElement).tagName.toLowerCase()).toBe('ion-toggle');
285+
});
286+
});
218287
});

0 commit comments

Comments
 (0)