//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2020, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////
import dialogTabNavigator from 'sources/dialog_tab_navigator';
import $ from 'jquery';
import 'bootstrap';
describe('dialogTabNavigator', function () {
let dialog, tabNavigator, backward_shortcut, forward_shortcut, fakeEvent;
beforeEach(() => {
dialog = $('
');
backward_shortcut = {
'alt': false,
'shift': true,
'control': true,
'key': {'key_code': 91, 'char': '['},
};
forward_shortcut = {
'alt': false,
'shift': true,
'control': true,
'key': {'key_code': 93, 'char': ']'},
};
tabNavigator = new dialogTabNavigator.dialogTabNavigator(
dialog, backward_shortcut, forward_shortcut);
fakeEvent = { stopPropagation: () => true };
});
describe('navigate', function () {
beforeEach(() => {
spyOn(tabNavigator, 'navigateBackward').and.callThrough();
spyOn(tabNavigator, 'navigateForward').and.callThrough();
});
it('navigate backward', function () {
tabNavigator.onKeyboardEvent(fakeEvent, 'shift+ctrl+[');
expect(tabNavigator.navigateBackward).toHaveBeenCalled();
expect(tabNavigator.navigateForward).not.toHaveBeenCalled();
});
it('navigate forward', function () {
tabNavigator.onKeyboardEvent(fakeEvent, 'shift+ctrl+]');
expect(tabNavigator.navigateForward).toHaveBeenCalled();
expect(tabNavigator.navigateBackward).not.toHaveBeenCalled();
});
it('should not navigate', function () {
tabNavigator.onKeyboardEvent(fakeEvent, 'shift+ctrl+a');
expect(tabNavigator.navigateForward).not.toHaveBeenCalled();
expect(tabNavigator.navigateBackward).not.toHaveBeenCalled();
});
});
describe('navigateForward from fist tab to second tab', function () {
var navigateForwardResult;
beforeEach(() => {
spyOn(tabNavigator, 'navigateForward').and.callThrough();
navigateForwardResult = tabNavigator.navigateForward(
dialog.find('ul.nav-tabs:first'),
dialog.find('div#1'),
fakeEvent
);
});
it('should return true', function () {
expect(navigateForwardResult).toEqual(true);
});
});
describe('navigateForward from last tab', function () {
var navigateForwardResult;
beforeEach(() => {
// set second tab active
dialog.find('ul.nav-tabs li a.active').removeClass('active');
dialog.find('ul.nav-tabs li a[href="#3"]').addClass('active');
spyOn(tabNavigator, 'navigateForward').and.callThrough();
navigateForwardResult = tabNavigator.navigateForward(
dialog.find('ul.nav-tabs:first'),
dialog.find('div#1'),
fakeEvent
);
});
it('should return false', function () {
expect(navigateForwardResult).toEqual(false);
});
});
describe('navigateBackward from second tab to first tab', function () {
var navigateBackwardResult;
beforeEach(() => {
// set second tab active
dialog.find('ul.nav-tabs li a.active').removeClass('active');
dialog.find('ul.nav-tabs li a[href="#2"]').addClass('active');
spyOn(tabNavigator, 'navigateBackward').and.callThrough();
navigateBackwardResult = tabNavigator.navigateBackward(
dialog.find('ul.nav-tabs:first'),
dialog.find('div#1'),
fakeEvent
);
});
it('should return true', function () {
expect(navigateBackwardResult).toEqual(true);
});
});
describe('navigateBackward from first tab', function () {
var navigateBackwardResult;
beforeEach(() => {
spyOn(tabNavigator, 'navigateBackward').and.callThrough();
navigateBackwardResult = tabNavigator.navigateBackward(
dialog.find('ul.nav-tabs:first'),
dialog.find('div#1'),
fakeEvent
);
});
it('should return false', function () {
expect(navigateBackwardResult).toEqual(false);
});
});
});