Commit 8af62a64 authored by Stan Hu's avatar Stan Hu

Fall back to the first sign-in tab if the local storage value is bad

If `current_signin_tab` is `#crowd`, then no tab will be active. Fix
this by using the first available tab.

Relates to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20049#note_82996324
parent a88a9e22
...@@ -37,6 +37,11 @@ export default class SigninTabsMemoizer { ...@@ -37,6 +37,11 @@ export default class SigninTabsMemoizer {
const tab = document.querySelector(`${this.tabSelector} a[href="${anchorName}"]`); const tab = document.querySelector(`${this.tabSelector} a[href="${anchorName}"]`);
if (tab) { if (tab) {
tab.click(); tab.click();
} else {
const firstTab = document.querySelector(`${this.tabSelector} a`);
if (firstTab) {
firstTab.click();
}
} }
} }
} }
......
...@@ -45,6 +45,21 @@ import SigninTabsMemoizer from '~/pages/sessions/new/signin_tabs_memoizer'; ...@@ -45,6 +45,21 @@ import SigninTabsMemoizer from '~/pages/sessions/new/signin_tabs_memoizer';
expect(fakeTab.click).toHaveBeenCalled(); 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', () => { it('saves last selected tab on change', () => {
createMemoizer(); createMemoizer();
......
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