2017-05-06 13:02:06 -04:00
|
|
|
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
describe('Linked Tabs', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
preloadFixtures('static/linked_tabs.html');
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('static/linked_tabs.html');
|
2018-10-17 03:16:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when is initialized', () => {
|
2016-11-24 06:28:48 -05:00
|
|
|
beforeEach(() => {
|
2020-05-11 11:09:37 -04:00
|
|
|
jest.spyOn(window.history, 'replaceState').mockImplementation(() => {});
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
it('should activate the tab correspondent to the given action', () => {
|
2018-10-17 03:21:28 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new LinkedTabs({
|
2018-10-17 03:16:21 -04:00
|
|
|
action: 'tab1',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
2016-12-05 05:00:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
expect(document.querySelector('#tab1').classList).toContain('active');
|
|
|
|
});
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
it('should active the default tab action when the action is show', () => {
|
2018-10-17 03:21:28 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new LinkedTabs({
|
2018-10-17 03:16:21 -04:00
|
|
|
action: 'show',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
expect(document.querySelector('#tab1').classList).toContain('active');
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
2018-10-17 03:16:21 -04:00
|
|
|
});
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
describe('on click', () => {
|
|
|
|
it('should change the url according to the clicked tab', () => {
|
2020-05-11 11:09:37 -04:00
|
|
|
const historySpy = jest.spyOn(window.history, 'replaceState').mockImplementation(() => {});
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
const linkedTabs = new LinkedTabs({
|
|
|
|
action: 'show',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
|
|
|
});
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
const secondTab = document.querySelector('.linked-tabs li:nth-child(2) a');
|
|
|
|
const newState =
|
|
|
|
secondTab.getAttribute('href') +
|
|
|
|
linkedTabs.currentLocation.search +
|
|
|
|
linkedTabs.currentLocation.hash;
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
secondTab.click();
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
if (historySpy) {
|
|
|
|
expect(historySpy).toHaveBeenCalledWith(
|
|
|
|
{
|
|
|
|
url: newState,
|
|
|
|
},
|
|
|
|
document.title,
|
|
|
|
newState,
|
|
|
|
);
|
|
|
|
}
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 03:16:21 -04:00
|
|
|
});
|