Files
pgadmin4/web/regression/javascript/restore/restore_dialog_spec.js

232 lines
7.5 KiB
JavaScript
Raw Normal View History

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2019-01-02 15:54:12 +05:30
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import {TreeFake} from '../tree/tree_fake';
import {RestoreDialog} from '../../../pgadmin/tools/restore/static/js/restore_dialog';
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios/index';
const context = describe;
describe('RestoreDialog', () => {
let restoreDialog;
let pgBrowser;
let jquerySpy;
let alertifySpy;
let restoreModelSpy;
beforeEach(() => {
pgBrowser = {
treeMenu: new TreeFake(),
Nodes: {
server: jasmine.createSpyObj('Node[server]', ['getTreeNodeHierarchy']),
database: jasmine.createSpyObj('Node[database]', ['getTreeNodeHierarchy']),
},
Fixed following: - Base font size changed from 0.815rem to 0.875rem, for navbar from 0.875rem to 0.925rem. - Dialog sizes made consistent throughout the application. Now there are 3 size options for width and height each - sm, md, lg. Combination of any of these to be used hereafter - Alignment fix for controls of Node properties dialogs which includes showing text and label in one line without dialog size change, checkbox alignment, switch control alignment at places and other minor improvements in other dialogs - Error message design change in dialogs validation - SQL Editor data grid editor popup design changes which were missed - Design change for dashboard server activity grid - Login page language dropdown color fix - Properties accordion collapse design fix - Help, Info icon fixed across all dialogs which were not working if clicked exactly on the text - Added missing icon with buttons at few places - Shadow behind the dialogs is increased to make it look clearly separated and depth. - Control Alignment fix in maintenance dialog - Min height of alertify dialogs set for better UX - File dialog design fix when no files found - Grant wizard fixes - Scroll bar visibility on first page, use full space for SQL generated on the last page - Browser toolbar buttons changed to sync with SQL editor toolbar buttons - Rounded corners for docker floating dialog (no properties) - Renaming file in file dialog should show original file name - SQL data grid text edit popup buttons behaviour was swapped. This is fixed. - Import/Export dialog changes as per new design.
2019-01-02 15:05:15 +05:30
stdW: {
sm: 500,
md: 700,
lg: 900,
default: 500,
},
stdH: {
sm: 200,
md: 400,
lg: 550,
default: 550,
},
};
pgBrowser.Nodes.server.hasId = true;
pgBrowser.Nodes.database.hasId = true;
jquerySpy = jasmine.createSpy('jquerySpy');
restoreModelSpy = jasmine.createSpy('restoreModelSpy');
const hierarchy = {
children: [
{
id: 'root',
children: [
{
id: 'serverTreeNode',
data: {
_id: 10,
_type: 'server',
label: 'some-tree-label',
},
children: [
{
id: 'some_database',
data: {
_type: 'database',
_id: 11,
label: 'some_database',
_label: 'some_database_label',
},
}, {
id: 'database_with_equal_in_name',
data: {
_type: 'database',
label: 'some_database',
_label: '=some_database_label',
},
},
],
},
{
id: 'ppasServer',
data: {
_type: 'server',
server_type: 'ppas',
children: [
{id: 'someNodeUnderneathPPASServer'},
],
},
},
],
},
],
};
pgBrowser.treeMenu = TreeFake.build(hierarchy);
});
describe('#draw', () => {
let networkMock;
beforeEach(() => {
networkMock = new MockAdapter(axios);
alertifySpy = jasmine.createSpyObj('alertify', ['alert', 'dialog']);
alertifySpy['pg_restore'] = jasmine.createSpy('pg_restore');
restoreDialog = new RestoreDialog(
pgBrowser,
jquerySpy,
alertifySpy,
restoreModelSpy
);
pgBrowser.get_preference = jasmine.createSpy('get_preferences');
});
afterEach(() => {
networkMock.restore();
});
context('there are no ancestors of the type server', () => {
it('does not create a dialog', () => {
pgBrowser.treeMenu.selectNode([{id: 'root'}]);
restoreDialog.draw(null, null, null);
expect(alertifySpy['pg_restore']).not.toHaveBeenCalled();
});
it('display an alert with a Restore Error', () => {
restoreDialog.draw(null, [{id: 'root'}], null);
expect(alertifySpy.alert).toHaveBeenCalledWith(
'Restore Error',
'Please select server or child node from the browser tree.'
);
});
});
context('there is an ancestor of the type server', () => {
context('no preference can be found', () => {
beforeEach(() => {
pgBrowser.get_preference.and.returnValue(undefined);
});
context('server is a ppas server', () => {
it('display an alert with "Restore Error"', () => {
restoreDialog.draw(null, [{id: 'serverTreeNode'}], null);
expect(alertifySpy.alert).toHaveBeenCalledWith(
'Restore Error',
'Failed to load preference pg_bin_dir of module paths'
);
});
});
context('server is not a ppas server', () => {
it('display an alert with "Restore Error"', () => {
restoreDialog.draw(null, [{id: 'ppasServer'}], null);
expect(alertifySpy.alert).toHaveBeenCalledWith(
'Restore Error',
'Failed to load preference ppas_bin_dir of module paths'
);
});
});
});
context('preference can be found', () => {
context('binary folder is not configured', () => {
beforeEach(() => {
pgBrowser.get_preference.and.returnValue({});
});
context('server is a ppas server', () => {
it('display an alert with "Configuration required"', () => {
restoreDialog.draw(null, [{id: 'serverTreeNode'}], null);
expect(alertifySpy.alert).toHaveBeenCalledWith(
'Configuration required',
'Please configure the PostgreSQL Binary Path in the Preferences dialog.'
);
});
});
context('server is not a ppas server', () => {
it('display an alert with "Configuration required"', () => {
restoreDialog.draw(null, [{id: 'ppasServer'}], null);
expect(alertifySpy.alert).toHaveBeenCalledWith(
'Configuration required',
'Please configure the EDB Advanced Server Binary Path in the Preferences dialog.'
);
});
});
});
context('binary folder is configured', () => {
let spy;
beforeEach(() => {
spy = jasmine.createSpyObj('globals', ['resizeTo']);
alertifySpy['pg_restore'].and
.returnValue(spy);
pgBrowser.get_preference.and.returnValue({value: '/some/path'});
pgBrowser.Nodes.server.label = 'some-server-label';
spyOn(restoreDialog, 'url_for_utility_exists').and.returnValue('/restore/utility_exists/10/objects');
networkMock.onGet('/restore/utility_exists/10/objects').reply(200, {'success': 1});
});
it('displays the dialog', (done) => {
Fixed following: - Base font size changed from 0.815rem to 0.875rem, for navbar from 0.875rem to 0.925rem. - Dialog sizes made consistent throughout the application. Now there are 3 size options for width and height each - sm, md, lg. Combination of any of these to be used hereafter - Alignment fix for controls of Node properties dialogs which includes showing text and label in one line without dialog size change, checkbox alignment, switch control alignment at places and other minor improvements in other dialogs - Error message design change in dialogs validation - SQL Editor data grid editor popup design changes which were missed - Design change for dashboard server activity grid - Login page language dropdown color fix - Properties accordion collapse design fix - Help, Info icon fixed across all dialogs which were not working if clicked exactly on the text - Added missing icon with buttons at few places - Shadow behind the dialogs is increased to make it look clearly separated and depth. - Control Alignment fix in maintenance dialog - Min height of alertify dialogs set for better UX - File dialog design fix when no files found - Grant wizard fixes - Scroll bar visibility on first page, use full space for SQL generated on the last page - Browser toolbar buttons changed to sync with SQL editor toolbar buttons - Rounded corners for docker floating dialog (no properties) - Renaming file in file dialog should show original file name - SQL data grid text edit popup buttons behaviour was swapped. This is fixed. - Import/Export dialog changes as per new design.
2019-01-02 15:05:15 +05:30
restoreDialog.draw(null, [{id: 'serverTreeNode'}], pgBrowser.stdW.md, pgBrowser.stdH.md);
setTimeout(() => {
expect(alertifySpy['pg_restore']).toHaveBeenCalledWith(
'Restore (some-server-label: some-tree-label)',
[{id: 'serverTreeNode'}],
{
_id: 10,
_type: 'server',
label: 'some-tree-label',
},
pgBrowser.Nodes.server
);
Fixed following: - Base font size changed from 0.815rem to 0.875rem, for navbar from 0.875rem to 0.925rem. - Dialog sizes made consistent throughout the application. Now there are 3 size options for width and height each - sm, md, lg. Combination of any of these to be used hereafter - Alignment fix for controls of Node properties dialogs which includes showing text and label in one line without dialog size change, checkbox alignment, switch control alignment at places and other minor improvements in other dialogs - Error message design change in dialogs validation - SQL Editor data grid editor popup design changes which were missed - Design change for dashboard server activity grid - Login page language dropdown color fix - Properties accordion collapse design fix - Help, Info icon fixed across all dialogs which were not working if clicked exactly on the text - Added missing icon with buttons at few places - Shadow behind the dialogs is increased to make it look clearly separated and depth. - Control Alignment fix in maintenance dialog - Min height of alertify dialogs set for better UX - File dialog design fix when no files found - Grant wizard fixes - Scroll bar visibility on first page, use full space for SQL generated on the last page - Browser toolbar buttons changed to sync with SQL editor toolbar buttons - Rounded corners for docker floating dialog (no properties) - Renaming file in file dialog should show original file name - SQL data grid text edit popup buttons behaviour was swapped. This is fixed. - Import/Export dialog changes as per new design.
2019-01-02 15:05:15 +05:30
expect(spy.resizeTo).toHaveBeenCalledWith(pgBrowser.stdW.md, pgBrowser.stdH.md);
done();
}, 0);
});
context('database label contain "="', () => {
it('should create alert dialog with restore error', (done) => {
restoreDialog.draw(null, [{id: 'database_with_equal_in_name'}], null);
setTimeout(() => {
expect(alertifySpy.alert).toHaveBeenCalledWith('Restore Error',
'Databases with = symbols in the name cannot be backed up or restored using this utility.');
done();
}, 0);
});
});
});
});
});
});
});