Add e2e tests for slButton

This commit is contained in:
Chris Haynes
2020-08-24 21:55:14 +01:00
parent 2d6c220ae2
commit 8b0a51337f

67
test/e2e/button.e2e.ts Normal file
View File

@@ -0,0 +1,67 @@
import { newE2EPage } from '@stencil/core/testing';
const testContent = `
<sl-button>Button</sl-button>
<button>Other Element</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);
});
});