summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2018-10-17 02:16:21 -0500
committerMike Greiling <mike@pixelcog.com>2018-10-17 11:18:17 -0500
commit024c31fe79b0e4026c9bff0802424efe6e127a4c (patch)
tree30c429f57324cecb928cdc775cb311f9996c740b
parentf666026d71ebefd70219d5078b1f0c83fa01f84d (diff)
downloadgitlab-ce-024c31fe79b0e4026c9bff0802424efe6e127a4c.tar.gz
Remove superfluous IIFEs
-rw-r--r--spec/javascripts/bootstrap_linked_tabs_spec.js98
-rw-r--r--spec/javascripts/labels_issue_sidebar_spec.js158
-rw-r--r--spec/javascripts/signin_tabs_memoizer_spec.js250
3 files changed, 250 insertions, 256 deletions
diff --git a/spec/javascripts/bootstrap_linked_tabs_spec.js b/spec/javascripts/bootstrap_linked_tabs_spec.js
index 0bf6c9820fa..c52141dbf2d 100644
--- a/spec/javascripts/bootstrap_linked_tabs_spec.js
+++ b/spec/javascripts/bootstrap_linked_tabs_spec.js
@@ -1,69 +1,67 @@
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
-(() => {
- describe('Linked Tabs', () => {
- preloadFixtures('static/linked_tabs.html.raw');
+describe('Linked Tabs', () => {
+ preloadFixtures('static/linked_tabs.html.raw');
+ beforeEach(() => {
+ loadFixtures('static/linked_tabs.html.raw');
+ });
+
+ describe('when is initialized', () => {
beforeEach(() => {
- loadFixtures('static/linked_tabs.html.raw');
+ spyOn(window.history, 'replaceState').and.callFake(function() {});
});
- describe('when is initialized', () => {
- beforeEach(() => {
- spyOn(window.history, 'replaceState').and.callFake(function() {});
+ it('should activate the tab correspondent to the given action', () => {
+ const linkedTabs = new LinkedTabs({
+ // eslint-disable-line
+ action: 'tab1',
+ defaultAction: 'tab1',
+ parentEl: '.linked-tabs',
});
- it('should activate the tab correspondent to the given action', () => {
- const linkedTabs = new LinkedTabs({
- // eslint-disable-line
- action: 'tab1',
- defaultAction: 'tab1',
- parentEl: '.linked-tabs',
- });
+ expect(document.querySelector('#tab1').classList).toContain('active');
+ });
- expect(document.querySelector('#tab1').classList).toContain('active');
+ it('should active the default tab action when the action is show', () => {
+ const linkedTabs = new LinkedTabs({
+ // eslint-disable-line
+ action: 'show',
+ defaultAction: 'tab1',
+ parentEl: '.linked-tabs',
});
- it('should active the default tab action when the action is show', () => {
- const linkedTabs = new LinkedTabs({
- // eslint-disable-line
- action: 'show',
- defaultAction: 'tab1',
- parentEl: '.linked-tabs',
- });
-
- expect(document.querySelector('#tab1').classList).toContain('active');
- });
+ expect(document.querySelector('#tab1').classList).toContain('active');
});
+ });
- describe('on click', () => {
- it('should change the url according to the clicked tab', () => {
- const historySpy = spyOn(window.history, 'replaceState').and.callFake(() => {});
+ describe('on click', () => {
+ it('should change the url according to the clicked tab', () => {
+ const historySpy = spyOn(window.history, 'replaceState').and.callFake(() => {});
- const linkedTabs = new LinkedTabs({
- action: 'show',
- defaultAction: 'tab1',
- parentEl: '.linked-tabs',
- });
+ const linkedTabs = new LinkedTabs({
+ action: 'show',
+ defaultAction: 'tab1',
+ parentEl: '.linked-tabs',
+ });
- const secondTab = document.querySelector('.linked-tabs li:nth-child(2) a');
- const newState =
- secondTab.getAttribute('href') +
- linkedTabs.currentLocation.search +
- linkedTabs.currentLocation.hash;
+ const secondTab = document.querySelector('.linked-tabs li:nth-child(2) a');
+ const newState =
+ secondTab.getAttribute('href') +
+ linkedTabs.currentLocation.search +
+ linkedTabs.currentLocation.hash;
- secondTab.click();
+ secondTab.click();
- if (historySpy) {
- expect(historySpy).toHaveBeenCalledWith(
- {
- url: newState,
- },
- document.title,
- newState,
- );
- }
- });
+ if (historySpy) {
+ expect(historySpy).toHaveBeenCalledWith(
+ {
+ url: newState,
+ },
+ document.title,
+ newState,
+ );
+ }
});
});
-})();
+});
diff --git a/spec/javascripts/labels_issue_sidebar_spec.js b/spec/javascripts/labels_issue_sidebar_spec.js
index 519a55d8069..e5678ee5379 100644
--- a/spec/javascripts/labels_issue_sidebar_spec.js
+++ b/spec/javascripts/labels_issue_sidebar_spec.js
@@ -12,108 +12,106 @@ import '~/api';
import '~/create_label';
import '~/users_select';
-(() => {
- let saveLabelCount = 0;
- let mock;
+let saveLabelCount = 0;
+let mock;
- describe('Issue dropdown sidebar', () => {
- preloadFixtures('static/issue_sidebar_label.html.raw');
+describe('Issue dropdown sidebar', () => {
+ preloadFixtures('static/issue_sidebar_label.html.raw');
- beforeEach(() => {
- loadFixtures('static/issue_sidebar_label.html.raw');
+ beforeEach(() => {
+ loadFixtures('static/issue_sidebar_label.html.raw');
- mock = new MockAdapter(axios);
+ mock = new MockAdapter(axios);
- new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
- new LabelsSelect();
+ new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
+ new LabelsSelect();
- mock.onGet('/root/test/labels.json').reply(() => {
- const labels = Array(10)
- .fill()
- .map((_, i) => ({
- id: i,
- title: `test ${i}`,
- color: '#5CB85C',
- }));
+ mock.onGet('/root/test/labels.json').reply(() => {
+ const labels = Array(10)
+ .fill()
+ .map((_, i) => ({
+ id: i,
+ title: `test ${i}`,
+ color: '#5CB85C',
+ }));
- return [200, labels];
- });
+ return [200, labels];
+ });
- mock.onPut('/root/test/issues/2.json').reply(() => {
- const labels = Array(saveLabelCount)
- .fill()
- .map((_, i) => ({
- id: i,
- title: `test ${i}`,
- color: '#5CB85C',
- }));
+ mock.onPut('/root/test/issues/2.json').reply(() => {
+ const labels = Array(saveLabelCount)
+ .fill()
+ .map((_, i) => ({
+ id: i,
+ title: `test ${i}`,
+ color: '#5CB85C',
+ }));
- return [200, { labels }];
- });
+ return [200, { labels }];
});
+ });
- afterEach(() => {
- mock.restore();
- });
+ afterEach(() => {
+ mock.restore();
+ });
+
+ it('changes collapsed tooltip when changing labels when less than 5', done => {
+ saveLabelCount = 5;
+ $('.edit-link')
+ .get(0)
+ .click();
+
+ setTimeout(() => {
+ expect($('.dropdown-content a').length).toBe(10);
+
+ $('.dropdown-content a').each(function(i) {
+ if (i < saveLabelCount) {
+ $(this)
+ .get(0)
+ .click();
+ }
+ });
- it('changes collapsed tooltip when changing labels when less than 5', done => {
- saveLabelCount = 5;
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
- expect($('.dropdown-content a').length).toBe(10);
-
- $('.dropdown-content a').each(function(i) {
- if (i < saveLabelCount) {
- $(this)
- .get(0)
- .click();
- }
- });
-
- $('.edit-link')
- .get(0)
- .click();
-
- setTimeout(() => {
- expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
- 'test 0, test 1, test 2, test 3, test 4',
- );
- done();
- }, 0);
+ expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
+ 'test 0, test 1, test 2, test 3, test 4',
+ );
+ done();
}, 0);
- });
+ }, 0);
+ });
+
+ it('changes collapsed tooltip when changing labels when more than 5', done => {
+ saveLabelCount = 6;
+ $('.edit-link')
+ .get(0)
+ .click();
+
+ setTimeout(() => {
+ expect($('.dropdown-content a').length).toBe(10);
+
+ $('.dropdown-content a').each(function(i) {
+ if (i < saveLabelCount) {
+ $(this)
+ .get(0)
+ .click();
+ }
+ });
- it('changes collapsed tooltip when changing labels when more than 5', done => {
- saveLabelCount = 6;
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
- expect($('.dropdown-content a').length).toBe(10);
-
- $('.dropdown-content a').each(function(i) {
- if (i < saveLabelCount) {
- $(this)
- .get(0)
- .click();
- }
- });
-
- $('.edit-link')
- .get(0)
- .click();
-
- setTimeout(() => {
- expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
- 'test 0, test 1, test 2, test 3, test 4, and 1 more',
- );
- done();
- }, 0);
+ expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
+ 'test 0, test 1, test 2, test 3, test 4, and 1 more',
+ );
+ done();
}, 0);
- });
+ }, 0);
});
-})();
+});
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);
});
});
});
-})();
+});