debian-mirror-gitlab/spec/javascripts/bootstrap_linked_tabs_spec.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
2018-12-13 13:39:08 +05:30
describe('Linked Tabs', () => {
2019-07-07 11:18:12 +05:30
preloadFixtures('static/linked_tabs.html');
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
beforeEach(() => {
2019-07-07 11:18:12 +05:30
loadFixtures('static/linked_tabs.html');
2018-12-13 13:39:08 +05:30
});
describe('when is initialized', () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2018-12-13 13:39:08 +05:30
spyOn(window.history, 'replaceState').and.callFake(function() {});
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('should activate the tab correspondent to the given action', () => {
// eslint-disable-next-line no-new
new LinkedTabs({
action: 'tab1',
defaultAction: 'tab1',
parentEl: '.linked-tabs',
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
expect(document.querySelector('#tab1').classList).toContain('active');
});
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
it('should active the default tab action when the action is show', () => {
// eslint-disable-next-line no-new
new LinkedTabs({
action: 'show',
defaultAction: 'tab1',
parentEl: '.linked-tabs',
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
expect(document.querySelector('#tab1').classList).toContain('active');
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
});
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
describe('on click', () => {
it('should change the url according to the clicked tab', () => {
const historySpy = spyOn(window.history, 'replaceState').and.callFake(() => {});
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
const linkedTabs = new LinkedTabs({
action: 'show',
defaultAction: 'tab1',
parentEl: '.linked-tabs',
});
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
const secondTab = document.querySelector('.linked-tabs li:nth-child(2) a');
const newState =
secondTab.getAttribute('href') +
linkedTabs.currentLocation.search +
linkedTabs.currentLocation.hash;
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
secondTab.click();
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
if (historySpy) {
expect(historySpy).toHaveBeenCalledWith(
{
2017-08-17 22:00:37 +05:30
url: newState,
2018-12-13 13:39:08 +05:30
},
document.title,
newState,
);
}
2017-08-17 22:00:37 +05:30
});
});
2018-12-13 13:39:08 +05:30
});