diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-10-17 10:16:21 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-10-17 19:18:17 +0300 |
commit | 024c31fe79b0e4026c9bff0802424efe6e127a4c (patch) | |
tree | 30c429f57324cecb928cdc775cb311f9996c740b /spec/javascripts/signin_tabs_memoizer_spec.js | |
parent | f666026d71ebefd70219d5078b1f0c83fa01f84d (diff) |
Remove superfluous IIFEs
Diffstat (limited to 'spec/javascripts/signin_tabs_memoizer_spec.js')
-rw-r--r-- | spec/javascripts/signin_tabs_memoizer_spec.js | 250 |
1 files changed, 124 insertions, 126 deletions
diff --git a/spec/javascripts/signin_tabs_memoizer_spec.js b/spec/javascripts/signin_tabs_memoizer_spec.js index 2968508efbb..b29dc08af37 100644 --- a/spec/javascripts/signin_tabs_memoizer_spec.js +++ b/spec/javascripts/signin_tabs_memoizer_spec.js @@ -1,171 +1,169 @@ import AccessorUtilities from '~/lib/utils/accessor'; import SigninTabsMemoizer from '~/pages/sessions/new/signin_tabs_memoizer'; -(() => { - describe('SigninTabsMemoizer', () => { - const fixtureTemplate = 'static/signin_tabs.html.raw'; - const tabSelector = 'ul.new-session-tabs'; - const currentTabKey = 'current_signin_tab'; - let memo; - - function createMemoizer() { - memo = new SigninTabsMemoizer({ - currentTabKey, - tabSelector, - }); - return memo; - } +describe('SigninTabsMemoizer', () => { + const fixtureTemplate = 'static/signin_tabs.html.raw'; + const tabSelector = 'ul.new-session-tabs'; + const currentTabKey = 'current_signin_tab'; + let memo; + + function createMemoizer() { + memo = new SigninTabsMemoizer({ + currentTabKey, + tabSelector, + }); + return memo; + } - preloadFixtures(fixtureTemplate); + preloadFixtures(fixtureTemplate); - beforeEach(() => { - loadFixtures(fixtureTemplate); + beforeEach(() => { + loadFixtures(fixtureTemplate); - spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(true); - }); + spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(true); + }); - it('does nothing if no tab was previously selected', () => { - createMemoizer(); + it('does nothing if no tab was previously selected', () => { + createMemoizer(); - expect(document.querySelector(`${tabSelector} > li.active a`).getAttribute('href')).toEqual( - '#ldap', - ); - }); + expect(document.querySelector(`${tabSelector} > li.active a`).getAttribute('href')).toEqual( + '#ldap', + ); + }); - it('shows last selected tab on boot', () => { - createMemoizer().saveData('#ldap'); - const fakeTab = { - click: () => {}, - }; - spyOn(document, 'querySelector').and.returnValue(fakeTab); - spyOn(fakeTab, 'click'); + it('shows last selected tab on boot', () => { + createMemoizer().saveData('#ldap'); + const fakeTab = { + click: () => {}, + }; + spyOn(document, 'querySelector').and.returnValue(fakeTab); + spyOn(fakeTab, 'click'); - memo.bootstrap(); + memo.bootstrap(); - // verify that triggers click on the last selected tab - expect(document.querySelector).toHaveBeenCalledWith(`${tabSelector} a[href="#ldap"]`); - expect(fakeTab.click).toHaveBeenCalled(); - }); + // verify that triggers click on the last selected tab + expect(document.querySelector).toHaveBeenCalledWith(`${tabSelector} a[href="#ldap"]`); + expect(fakeTab.click).toHaveBeenCalled(); + }); - it('clicks the first tab if value in local storage is bad', () => { - createMemoizer().saveData('#bogus'); - const fakeTab = { - click: () => {}, - }; - spyOn(document, 'querySelector').and.callFake( - selector => (selector === `${tabSelector} a[href="#bogus"]` ? null : fakeTab), - ); - spyOn(fakeTab, 'click'); - - memo.bootstrap(); - - // verify that triggers click on stored selector and fallback - expect(document.querySelector.calls.allArgs()).toEqual([ - ['ul.new-session-tabs a[href="#bogus"]'], - ['ul.new-session-tabs a'], - ]); - expect(fakeTab.click).toHaveBeenCalled(); - }); + it('clicks the first tab if value in local storage is bad', () => { + createMemoizer().saveData('#bogus'); + const fakeTab = { + click: () => {}, + }; + spyOn(document, 'querySelector').and.callFake( + selector => (selector === `${tabSelector} a[href="#bogus"]` ? null : fakeTab), + ); + spyOn(fakeTab, 'click'); + + memo.bootstrap(); + + // verify that triggers click on stored selector and fallback + expect(document.querySelector.calls.allArgs()).toEqual([ + ['ul.new-session-tabs a[href="#bogus"]'], + ['ul.new-session-tabs a'], + ]); + expect(fakeTab.click).toHaveBeenCalled(); + }); - it('saves last selected tab on change', () => { - createMemoizer(); + it('saves last selected tab on change', () => { + createMemoizer(); - document.querySelector('a[href="#login-pane"]').click(); + document.querySelector('a[href="#login-pane"]').click(); - expect(memo.readData()).toEqual('#login-pane'); - }); + expect(memo.readData()).toEqual('#login-pane'); + }); - it('overrides last selected tab with hash tag when given', () => { - window.location.hash = '#ldap'; - createMemoizer(); + it('overrides last selected tab with hash tag when given', () => { + window.location.hash = '#ldap'; + createMemoizer(); - expect(memo.readData()).toEqual('#ldap'); - }); + expect(memo.readData()).toEqual('#ldap'); + }); - describe('class constructor', () => { - beforeEach(() => { - memo = createMemoizer(); - }); + describe('class constructor', () => { + beforeEach(() => { + memo = createMemoizer(); + }); - it('should set .isLocalStorageAvailable', () => { - expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled(); - expect(memo.isLocalStorageAvailable).toBe(true); - }); + it('should set .isLocalStorageAvailable', () => { + expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled(); + expect(memo.isLocalStorageAvailable).toBe(true); }); + }); - describe('saveData', () => { - beforeEach(() => { - memo = { - currentTabKey, - }; + describe('saveData', () => { + beforeEach(() => { + memo = { + currentTabKey, + }; - spyOn(localStorage, 'setItem'); - }); + spyOn(localStorage, 'setItem'); + }); - describe('if .isLocalStorageAvailable is `false`', () => { - beforeEach(function() { - memo.isLocalStorageAvailable = false; + describe('if .isLocalStorageAvailable is `false`', () => { + beforeEach(function() { + memo.isLocalStorageAvailable = false; - SigninTabsMemoizer.prototype.saveData.call(memo); - }); + SigninTabsMemoizer.prototype.saveData.call(memo); + }); - it('should not call .setItem', () => { - expect(localStorage.setItem).not.toHaveBeenCalled(); - }); + it('should not call .setItem', () => { + expect(localStorage.setItem).not.toHaveBeenCalled(); }); + }); - describe('if .isLocalStorageAvailable is `true`', () => { - const value = 'value'; + describe('if .isLocalStorageAvailable is `true`', () => { + const value = 'value'; - beforeEach(function() { - memo.isLocalStorageAvailable = true; + beforeEach(function() { + memo.isLocalStorageAvailable = true; - SigninTabsMemoizer.prototype.saveData.call(memo, value); - }); + SigninTabsMemoizer.prototype.saveData.call(memo, value); + }); - it('should call .setItem', () => { - expect(localStorage.setItem).toHaveBeenCalledWith(currentTabKey, value); - }); + it('should call .setItem', () => { + expect(localStorage.setItem).toHaveBeenCalledWith(currentTabKey, value); }); }); + }); - describe('readData', () => { - const itemValue = 'itemValue'; - let readData; + describe('readData', () => { + const itemValue = 'itemValue'; + let readData; - beforeEach(() => { - memo = { - currentTabKey, - }; + beforeEach(() => { + memo = { + currentTabKey, + }; - spyOn(localStorage, 'getItem').and.returnValue(itemValue); - }); + spyOn(localStorage, 'getItem').and.returnValue(itemValue); + }); - describe('if .isLocalStorageAvailable is `false`', () => { - beforeEach(function() { - memo.isLocalStorageAvailable = false; + describe('if .isLocalStorageAvailable is `false`', () => { + beforeEach(function() { + memo.isLocalStorageAvailable = false; - readData = SigninTabsMemoizer.prototype.readData.call(memo); - }); + readData = SigninTabsMemoizer.prototype.readData.call(memo); + }); - it('should not call .getItem and should return `null`', () => { - expect(localStorage.getItem).not.toHaveBeenCalled(); - expect(readData).toBe(null); - }); + it('should not call .getItem and should return `null`', () => { + expect(localStorage.getItem).not.toHaveBeenCalled(); + expect(readData).toBe(null); }); + }); - describe('if .isLocalStorageAvailable is `true`', () => { - beforeEach(function() { - memo.isLocalStorageAvailable = true; + describe('if .isLocalStorageAvailable is `true`', () => { + beforeEach(function() { + memo.isLocalStorageAvailable = true; - readData = SigninTabsMemoizer.prototype.readData.call(memo); - }); + readData = SigninTabsMemoizer.prototype.readData.call(memo); + }); - it('should call .getItem and return the localStorage value', () => { - expect(window.localStorage.getItem).toHaveBeenCalledWith(currentTabKey); - expect(readData).toBe(itemValue); - }); + it('should call .getItem and return the localStorage value', () => { + expect(window.localStorage.getItem).toHaveBeenCalledWith(currentTabKey); + expect(readData).toBe(itemValue); }); }); }); -})(); +}); |