gitlab-org--gitlab-foss/spec/javascripts/signin_tabs_memoizer_spec.js.es6
Jacopo 8235f83015 Fixed Wrong Tab Selected When Loggin Fails And Multiple Login Tabs Exists
When ldap is enabled and use "Standard" authentication method, if authentication fails
the correct tab remain selected.
This is done by saving into localStorage when the active tab changes and by always selecting that tab when
the page is loaded.
2016-12-02 10:19:31 +01:00

53 lines
1.4 KiB
JavaScript

/*= require signin_tabs_memoizer */
((global) => {
describe('SigninTabsMemoizer', () => {
const fixtureTemplate = 'signin_tabs.html';
const tabSelector = 'ul.nav-tabs';
const currentTabKey = 'current_signin_tab';
let memo;
function createMemoizer() {
memo = new global.ActiveTabMemoizer({
currentTabKey,
tabSelector,
});
return memo;
}
fixture.preload(fixtureTemplate);
beforeEach(() => {
fixture.load(fixtureTemplate);
});
it('does nothing if no tab was previously selected', () => {
createMemoizer();
expect(document.querySelector('li a.active').getAttribute('id')).toEqual('standard');
});
it('shows last selected tab on boot', () => {
createMemoizer().saveData('#ldap');
const fakeTab = {
click: () => {},
};
spyOn(document, 'querySelector').and.returnValue(fakeTab);
spyOn(fakeTab, 'click');
memo.bootstrap();
// verify that triggers click on the last selected tab
expect(document.querySelector).toHaveBeenCalledWith(`${tabSelector} a[href="#ldap"]`);
expect(fakeTab.click).toHaveBeenCalled();
});
it('saves last selected tab on change', () => {
createMemoizer();
document.getElementById('standard').click();
expect(memo.readData()).toEqual('#standard');
});
});
})(window);