diff --git a/.eslintignore b/.eslintignore index 54363834..74acbbb5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,3 +7,4 @@ examples node_modules src/react scripts + diff --git a/src/components/button-group/button-group.test.ts b/src/components/button-group/button-group.test.ts new file mode 100644 index 00000000..3f2e2567 --- /dev/null +++ b/src/components/button-group/button-group.test.ts @@ -0,0 +1,87 @@ +import { expect, fixture, html, elementUpdated } from '@open-wc/testing'; +import type SlButtonGroup from './button-group'; + +describe('', () => { + + describe('defaults ', () => { + it('passes accessibility test', async () => { + const group = await fixture(html` + Button 1 Label + Button 2 Label + Button 3 Label + `); + await expect(group).to.be.accessible(); + }); + + it('default label empty', async () => { + const group = await fixture(html` + Button 1 Label + Button 2 Label + Button 3 Label + `); + expect(group.label).to.equal(''); + }); + }); + + describe('slotted button classes', () => { + + it('slotted buttons have the right classes applied based on their order', async () => { + const group = await fixture(html` + Button 1 Label + Button 2 Label + Button 3 Label + `); + + const allButtons = group.querySelectorAll('sl-button'); + const hasGroupClass = Array.from(allButtons).every((button) => button.classList.contains('sl-button-group__button')); + expect(hasGroupClass).to.be.true; + + expect(allButtons[0]).to.have.class('sl-button-group__button--first'); + expect(allButtons[1]).to.have.class('sl-button-group__button--inner'); + expect(allButtons[2]).to.have.class('sl-button-group__button--last'); + + }); + }); + + describe('focus and blur events', () => { + it('toggles focus class to slotted buttons on focus/blur', async () => { + const group = await fixture(html` + Button 1 Label + Button 2 Label + Button 3 Label + `); + + + const allButtons = group.querySelectorAll('sl-button'); + allButtons[0].dispatchEvent(new FocusEvent('focusin', { bubbles: true })); + + await elementUpdated(allButtons[0]); + expect(allButtons[0].classList.contains('sl-button-group__button--focus')).to.be.true; + + allButtons[0].dispatchEvent(new FocusEvent('focusout', { bubbles: true })); + await elementUpdated(allButtons[0]); + expect(allButtons[0].classList.contains('sl-button-group__button--focus')).not.to.be.true; + }); + }); + + describe('mouseover and mouseout events', () => { + it('toggles hover class to slotted buttons on mouseover/mouseout', async () => { + const group = await fixture(html` + Button 1 Label + Button 2 Label + Button 3 Label + `); + + const allButtons = group.querySelectorAll('sl-button'); + + allButtons[0].dispatchEvent(new MouseEvent('mouseover', { bubbles: true })); + await elementUpdated(allButtons[0]); + expect(allButtons[0].classList.contains('sl-button-group__button--hover')).to.be.true; + + allButtons[0].dispatchEvent(new MouseEvent('mouseout', { bubbles: true })); + await elementUpdated(allButtons[0]); + expect(allButtons[0].classList.contains('sl-button-group__button--hover')).not.to.be.true; + }); + }); + +}); diff --git a/src/components/button/button.test.ts b/src/components/button/button.test.ts new file mode 100644 index 00000000..43677116 --- /dev/null +++ b/src/components/button/button.test.ts @@ -0,0 +1,109 @@ +import { expect, fixture, html } from '@open-wc/testing'; +import sinon from 'sinon'; +import type SlButton from './button'; + +describe('', () => { + + describe('when provided no parameters', () => { + + it('passes accessibility test', async () => { + const el = await fixture(html` Button Label `); + await expect(el).to.be.accessible(); + }); + + it('default values are set correctly', async () => { + const el = await fixture(html` Button Label `); + + expect(el.variant).to.equal('default'); + expect(el.size).to.equal('medium'); + expect(el.disabled).to.equal(false); + expect(el.caret).to.equal(false); + expect(el.loading).to.equal(false); + expect(el.outline).to.equal(false); + expect(el.pill).to.equal(false); + expect(el.circle).to.equal(false); + }); + + it('should render as a