From d5167b0106fdeb064814a8e014e70b3953a20812 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 12 Oct 2017 12:43:53 +0100 Subject: [PATCH] Add further container tests --- src/scripts/src/components/container.test.js | 93 ++++++++++++++++---- 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/src/scripts/src/components/container.test.js b/src/scripts/src/components/container.test.js index 106a539..a57821c 100644 --- a/src/scripts/src/components/container.test.js +++ b/src/scripts/src/components/container.test.js @@ -31,7 +31,6 @@ describe('Container', () => { expect(instance.classNames).to.eql(DEFAULT_CLASSNAMES); }); - describe('addEventListeners', () => { let addEventListenerStub; @@ -86,23 +85,7 @@ describe('Container', () => { }); }); - describe('focus', () => { - let focusStub; - - beforeEach(() => { - focusStub = sinon.stub(instance.element, 'focus'); - }); - - afterEach(() => { - focusStub.restore(); - }); - - it('focuses element if isFocussed flag is set to false', () => { - instance.isFocussed = false; - instance.focus(); - expect(focusStub.callCount).to.equal(1); - }); - }); + // describe('shouldFlip', () => { }); describe('setActiveDescendant', () => { it('sets element\'s aria-activedescendant attribute with passed descendant ID', () => { @@ -122,4 +105,78 @@ describe('Container', () => { expect(instance.element.getAttribute('aria-activedescendant')).to.equal(null); }); }); + + // describe('open', () => { }); + // describe('close', () => { }); + + describe('focus', () => { + let focusStub; + + beforeEach(() => { + focusStub = sinon.stub(instance.element, 'focus'); + }); + + afterEach(() => { + focusStub.restore(); + }); + + it('focuses element if isFocussed flag is set to false', () => { + instance.isFocussed = false; + instance.focus(); + expect(focusStub.callCount).to.equal(1); + }); + }); + + // describe('addFocusState', () => { }); + // describe('removeFocusState', () => { }); + // describe('enable', () => {}); + // describe('disable', () => {}); + + describe('addLoadingState', () => { + beforeEach(() => { + instance.removeLoadingState(); + }); + + it('adds loading state class', () => { + expect(instance.element.classList.contains(DEFAULT_CLASSNAMES.loadingState)).to.equal(false); + instance.addLoadingState(); + expect(instance.element.classList.contains(DEFAULT_CLASSNAMES.loadingState)).to.equal(true); + }); + + it('sets aria-busy attribute to true', () => { + expect(instance.element.getAttribute('aria-busy')).to.equal(null); + instance.addLoadingState(); + expect(instance.element.getAttribute('aria-busy')).to.equal('true'); + }); + + it('sets isLoading flag to false', () => { + expect(instance.isLoading).to.equal(false); + instance.addLoadingState(); + expect(instance.isLoading).to.equal(true); + }); + }); + + describe('removeLoadingState', () => { + beforeEach(() => { + instance.addLoadingState(); + }); + + it('removes loading state class', () => { + expect(instance.element.classList.contains(DEFAULT_CLASSNAMES.loadingState)).to.equal(true); + instance.removeLoadingState(); + expect(instance.element.classList.contains(DEFAULT_CLASSNAMES.loadingState)).to.equal(false); + }); + + it('removes aria-busy attribute', () => { + expect(instance.element.getAttribute('aria-busy')).to.equal('true'); + instance.removeLoadingState(); + expect(instance.element.getAttribute('aria-busy')).to.equal(null); + }); + + it('sets isLoading flag to true', () => { + expect(instance.isLoading).to.equal(true); + instance.removeLoadingState(); + expect(instance.isLoading).to.equal(false); + }); + }); });