From 1a0a0858efa0e1e3c6bebd38058df8ad39ca27a5 Mon Sep 17 00:00:00 2001 From: Martijn Cuppens Date: Sat, 2 May 2020 11:11:24 +0200 Subject: Remove checkbox/radio toggle from button plugin in favor of a CSS only solution --- js/tests/unit/button.spec.js | 161 ------------------------------------------- 1 file changed, 161 deletions(-) (limited to 'js/tests/unit/button.spec.js') diff --git a/js/tests/unit/button.spec.js b/js/tests/unit/button.spec.js index f7caf23f6..ac32b4b89 100644 --- a/js/tests/unit/button.spec.js +++ b/js/tests/unit/button.spec.js @@ -1,11 +1,9 @@ import Button from '../../src/button' -import EventHandler from '../../src/dom/event-handler' /** Test helpers */ import { getFixture, clearFixture, - createEvent, jQueryMock } from '../helpers/fixture' @@ -51,144 +49,6 @@ describe('Button', () => { expect(btnTestParent.classList.contains('active')).toEqual(true) }) - - it('should trigger input change event when toggled button has input field', done => { - fixtureEl.innerHTML = [ - '
', - ' ', - '
' - ].join('') - - const input = fixtureEl.querySelector('input') - const label = fixtureEl.querySelector('label') - - input.addEventListener('change', () => { - expect().nothing() - done() - }) - - label.click() - }) - - it('should not trigger input change event when input already checked and button is active', () => { - fixtureEl.innerHTML = [ - '' - ].join('') - - const button = fixtureEl.querySelector('button') - - spyOn(EventHandler, 'trigger') - - button.click() - - expect(EventHandler.trigger).not.toHaveBeenCalled() - }) - - it('should remove active when an other radio button is clicked', () => { - fixtureEl.innerHTML = [ - '
', - ' ', - ' ', - ' ', - '
' - ].join('') - - const option1 = fixtureEl.querySelector('#option1') - const option2 = fixtureEl.querySelector('#option2') - - expect(option1.checked).toEqual(true) - expect(option1.parentElement.classList.contains('active')).toEqual(true) - - const clickEvent = createEvent('click') - - option2.dispatchEvent(clickEvent) - - expect(option1.checked).toEqual(false) - expect(option1.parentElement.classList.contains('active')).toEqual(false) - expect(option2.checked).toEqual(true) - expect(option2.parentElement.classList.contains('active')).toEqual(true) - }) - - it('should do nothing if the child is not an input', () => { - fixtureEl.innerHTML = [ - '
', - ' ', - ' ', - ' ', - '
' - ].join('') - - const option2 = fixtureEl.querySelector('#option2') - const clickEvent = createEvent('click') - - option2.dispatchEvent(clickEvent) - - expect().nothing() - }) - - it('should add focus class on focus event', () => { - fixtureEl.innerHTML = '' - - const btn = fixtureEl.querySelector('.btn') - const input = fixtureEl.querySelector('input') - - const focusEvent = createEvent('focus') - input.dispatchEvent(focusEvent) - - expect(btn.classList.contains('focus')).toEqual(true) - }) - - it('should not add focus class', () => { - fixtureEl.innerHTML = '' - - const btn = fixtureEl.querySelector('button') - const input = fixtureEl.querySelector('input') - - const focusEvent = createEvent('focus') - input.dispatchEvent(focusEvent) - - expect(btn.classList.contains('focus')).toEqual(false) - }) - - it('should remove focus class on blur event', () => { - fixtureEl.innerHTML = '' - - const btn = fixtureEl.querySelector('.btn') - const input = fixtureEl.querySelector('input') - - const focusEvent = createEvent('blur') - input.dispatchEvent(focusEvent) - - expect(btn.classList.contains('focus')).toEqual(false) - }) - - it('should not remove focus class on blur event', () => { - fixtureEl.innerHTML = '' - - const btn = fixtureEl.querySelector('button') - const input = fixtureEl.querySelector('input') - - const focusEvent = createEvent('blur') - input.dispatchEvent(focusEvent) - - expect(btn.classList.contains('focus')).toEqual(true) - }) }) describe('toggle', () => { @@ -206,27 +66,6 @@ describe('Button', () => { expect(btnEl.getAttribute('aria-pressed')).toEqual('true') expect(btnEl.classList.contains('active')).toEqual(true) }) - - it('should handle disabled attribute on non-button elements', () => { - fixtureEl.innerHTML = [ - '
', - ' ', - '
' - ].join('') - - const btnGroupEl = fixtureEl.querySelector('.btn-group') - const btnDanger = fixtureEl.querySelector('.btn-danger') - const input = fixtureEl.querySelector('input') - - const button = new Button(btnGroupEl) - - button.toggle() - - expect(btnDanger.hasAttribute('disabled')).toEqual(true) - expect(input.checked).toEqual(false) - }) }) describe('dispose', () => { -- cgit v1.2.3