Commit 60a1118f authored by Mike Greiling's avatar Mike Greiling

refactor SigninTabsMemoizer class to ES module syntax

parent 5c52ca9a
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */ /* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
/* global ActiveTabMemoizer */
/* global ShortcutsNavigation */ /* global ShortcutsNavigation */
/* global IssuableIndex */ /* global IssuableIndex */
/* global ShortcutsIssuable */ /* global ShortcutsIssuable */
...@@ -50,6 +49,7 @@ import UsersSelect from './users_select'; ...@@ -50,6 +49,7 @@ import UsersSelect from './users_select';
import RefSelectDropdown from './ref_select_dropdown'; import RefSelectDropdown from './ref_select_dropdown';
import GfmAutoComplete from './gfm_auto_complete'; import GfmAutoComplete from './gfm_auto_complete';
import ShortcutsBlob from './shortcuts_blob'; import ShortcutsBlob from './shortcuts_blob';
import SigninTabsMemoizer from './signin_tabs_memoizer';
import Star from './star'; import Star from './star';
import Todos from './todos'; import Todos from './todos';
import TreeView from './tree'; import TreeView from './tree';
...@@ -131,7 +131,7 @@ import OAuthRememberMe from './oauth_remember_me'; ...@@ -131,7 +131,7 @@ import OAuthRememberMe from './oauth_remember_me';
break; break;
case 'sessions:new': case 'sessions:new':
new UsernameValidator(); new UsernameValidator();
new ActiveTabMemoizer(); new SigninTabsMemoizer();
new OAuthRememberMe({ container: $(".omniauth-container") }).bindEvents(); new OAuthRememberMe({ container: $(".omniauth-container") }).bindEvents();
break; break;
case 'projects:boards:show': case 'projects:boards:show':
......
...@@ -143,7 +143,6 @@ import './render_math'; ...@@ -143,7 +143,6 @@ import './render_math';
import './right_sidebar'; import './right_sidebar';
import './search'; import './search';
import './search_autocomplete'; import './search_autocomplete';
import './signin_tabs_memoizer';
import './smart_interval'; import './smart_interval';
import './snippets_list'; import './snippets_list';
import './star'; import './star';
......
...@@ -6,7 +6,7 @@ import AccessorUtilities from './lib/utils/accessor'; ...@@ -6,7 +6,7 @@ import AccessorUtilities from './lib/utils/accessor';
* Memorize the last selected tab after reloading a page. * Memorize the last selected tab after reloading a page.
* Does that setting the current selected tab in the localStorage * Does that setting the current selected tab in the localStorage
*/ */
class ActiveTabMemoizer { export default class SigninTabsMemoizer {
constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) { constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) {
this.currentTabKey = currentTabKey; this.currentTabKey = currentTabKey;
this.tabSelector = tabSelector; this.tabSelector = tabSelector;
...@@ -51,5 +51,3 @@ class ActiveTabMemoizer { ...@@ -51,5 +51,3 @@ class ActiveTabMemoizer {
return window.localStorage.getItem(this.currentTabKey); return window.localStorage.getItem(this.currentTabKey);
} }
} }
window.ActiveTabMemoizer = ActiveTabMemoizer;
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import SigninTabsMemoizer from '~/signin_tabs_memoizer';
import '~/signin_tabs_memoizer'; (() => {
((global) => {
describe('SigninTabsMemoizer', () => { describe('SigninTabsMemoizer', () => {
const fixtureTemplate = 'static/signin_tabs.html.raw'; const fixtureTemplate = 'static/signin_tabs.html.raw';
const tabSelector = 'ul.nav-tabs'; const tabSelector = 'ul.nav-tabs';
...@@ -10,7 +9,7 @@ import '~/signin_tabs_memoizer'; ...@@ -10,7 +9,7 @@ import '~/signin_tabs_memoizer';
let memo; let memo;
function createMemoizer() { function createMemoizer() {
memo = new global.ActiveTabMemoizer({ memo = new SigninTabsMemoizer({
currentTabKey, currentTabKey,
tabSelector, tabSelector,
}); });
...@@ -78,7 +77,7 @@ import '~/signin_tabs_memoizer'; ...@@ -78,7 +77,7 @@ import '~/signin_tabs_memoizer';
beforeEach(function () { beforeEach(function () {
memo.isLocalStorageAvailable = false; memo.isLocalStorageAvailable = false;
global.ActiveTabMemoizer.prototype.saveData.call(memo); SigninTabsMemoizer.prototype.saveData.call(memo);
}); });
it('should not call .setItem', () => { it('should not call .setItem', () => {
...@@ -92,7 +91,7 @@ import '~/signin_tabs_memoizer'; ...@@ -92,7 +91,7 @@ import '~/signin_tabs_memoizer';
beforeEach(function () { beforeEach(function () {
memo.isLocalStorageAvailable = true; memo.isLocalStorageAvailable = true;
global.ActiveTabMemoizer.prototype.saveData.call(memo, value); SigninTabsMemoizer.prototype.saveData.call(memo, value);
}); });
it('should call .setItem', () => { it('should call .setItem', () => {
...@@ -117,7 +116,7 @@ import '~/signin_tabs_memoizer'; ...@@ -117,7 +116,7 @@ import '~/signin_tabs_memoizer';
beforeEach(function () { beforeEach(function () {
memo.isLocalStorageAvailable = false; memo.isLocalStorageAvailable = false;
readData = global.ActiveTabMemoizer.prototype.readData.call(memo); readData = SigninTabsMemoizer.prototype.readData.call(memo);
}); });
it('should not call .getItem and should return `null`', () => { it('should not call .getItem and should return `null`', () => {
...@@ -130,7 +129,7 @@ import '~/signin_tabs_memoizer'; ...@@ -130,7 +129,7 @@ import '~/signin_tabs_memoizer';
beforeEach(function () { beforeEach(function () {
memo.isLocalStorageAvailable = true; memo.isLocalStorageAvailable = true;
readData = global.ActiveTabMemoizer.prototype.readData.call(memo); readData = SigninTabsMemoizer.prototype.readData.call(memo);
}); });
it('should call .getItem and return the localStorage value', () => { it('should call .getItem and return the localStorage value', () => {
...@@ -140,4 +139,4 @@ import '~/signin_tabs_memoizer'; ...@@ -140,4 +139,4 @@ import '~/signin_tabs_memoizer';
}); });
}); });
}); });
})(window); })();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment