From 8b0a51337f8983a04cb8da8f53c03439ef155bc3 Mon Sep 17 00:00:00 2001 From: Chris Haynes Date: Mon, 24 Aug 2020 21:55:14 +0100 Subject: [PATCH] Add e2e tests for slButton --- test/e2e/button.e2e.ts | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/e2e/button.e2e.ts diff --git a/test/e2e/button.e2e.ts b/test/e2e/button.e2e.ts new file mode 100644 index 000000000..5fadce92b --- /dev/null +++ b/test/e2e/button.e2e.ts @@ -0,0 +1,67 @@ +import { newE2EPage } from '@stencil/core/testing'; + +const testContent = ` +Button + +`; + +describe('button', () => { + it('should emit slFocus when gaining focus', async () => { + const page = await newE2EPage(); + await page.setContent(testContent); + + const button = await page.find('sl-button'); + + const slFocus = await button.spyOnEvent('slFocus'); + + // give focus + await button.click(); + + expect(slFocus).toHaveReceivedEventTimes(1); + }); + + it('should emit slBlur when losing focus', async () => { + const page = await newE2EPage(); + await page.setContent(testContent); + + const button = await page.find('sl-button'); + const otherElement = await page.find('button'); + + const slFocus = await button.spyOnEvent('slBlur'); + + //give focus + await button.click(); + + // remove focus by clicking on other element + await otherElement.click(); + + expect(slFocus).toHaveReceivedEventTimes(1); + }); + + it('should emit slFocus on setFocus', async () => { + const page = await newE2EPage(); + await page.setContent(testContent); + + const button = await page.find('sl-button'); + + const slFocus = await button.spyOnEvent('slFocus'); + + await button.callMethod('setFocus'); + + expect(slFocus).toHaveReceivedEventTimes(1); + }); + + it('should emit slBlur on removeFocus', async () => { + const page = await newE2EPage(); + await page.setContent(testContent); + + const button = await page.find('sl-button'); + + const slBlur = await button.spyOnEvent('slBlur'); + + await button.callMethod('setFocus'); + await button.callMethod('removeFocus'); + + expect(slBlur).toHaveReceivedEventTimes(1); + }); +});