2017-05-06 13:02:06 -04:00
|
|
|
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
|
2016-11-24 06:28:48 -05:00
|
|
|
|
|
|
|
(() => {
|
2017-01-13 11:04:41 -05:00
|
|
|
// TODO: remove this hack!
|
|
|
|
// PhantomJS causes spyOn to panic because replaceState isn't "writable"
|
2017-01-27 20:33:58 -05:00
|
|
|
let phantomjs;
|
|
|
|
try {
|
|
|
|
phantomjs = !Object.getOwnPropertyDescriptor(window.history, 'replaceState').writable;
|
|
|
|
} catch (err) {
|
|
|
|
phantomjs = false;
|
|
|
|
}
|
2017-01-13 11:04:41 -05:00
|
|
|
|
2016-11-24 06:28:48 -05:00
|
|
|
describe('Linked Tabs', () => {
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures('static/linked_tabs.html.raw');
|
2016-11-24 06:28:48 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures('static/linked_tabs.html.raw');
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when is initialized', () => {
|
2016-12-05 05:00:19 -05:00
|
|
|
beforeEach(() => {
|
2017-01-13 11:04:41 -05:00
|
|
|
if (!phantomjs) {
|
|
|
|
spyOn(window.history, 'replaceState').and.callFake(function () {});
|
|
|
|
}
|
2016-12-05 05:00:19 -05:00
|
|
|
});
|
|
|
|
|
2016-11-24 06:28:48 -05:00
|
|
|
it('should activate the tab correspondent to the given action', () => {
|
2017-05-06 13:02:06 -04:00
|
|
|
const linkedTabs = new LinkedTabs({ // eslint-disable-line
|
2016-11-24 06:28:48 -05:00
|
|
|
action: 'tab1',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(document.querySelector('#tab1').classList).toContain('active');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should active the default tab action when the action is show', () => {
|
2017-05-06 13:02:06 -04:00
|
|
|
const linkedTabs = new LinkedTabs({ // eslint-disable-line
|
2016-11-24 06:28:48 -05:00
|
|
|
action: 'show',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(document.querySelector('#tab1').classList).toContain('active');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on click', () => {
|
|
|
|
it('should change the url according to the clicked tab', () => {
|
2017-01-13 11:04:41 -05:00
|
|
|
const historySpy = !phantomjs && spyOn(history, 'replaceState').and.callFake(() => {});
|
2016-11-24 06:28:48 -05:00
|
|
|
|
2017-05-06 13:02:06 -04:00
|
|
|
const linkedTabs = new LinkedTabs({
|
2016-11-24 06:28:48 -05:00
|
|
|
action: 'show',
|
|
|
|
defaultAction: 'tab1',
|
|
|
|
parentEl: '.linked-tabs',
|
|
|
|
});
|
|
|
|
|
|
|
|
const secondTab = document.querySelector('.linked-tabs li:nth-child(2) a');
|
|
|
|
const newState = secondTab.getAttribute('href') + linkedTabs.currentLocation.search + linkedTabs.currentLocation.hash;
|
|
|
|
|
|
|
|
secondTab.click();
|
|
|
|
|
2017-01-13 11:04:41 -05:00
|
|
|
if (historySpy) {
|
|
|
|
expect(historySpy).toHaveBeenCalledWith({
|
|
|
|
url: newState,
|
|
|
|
}, document.title, newState);
|
|
|
|
}
|
2016-11-24 06:28:48 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|