mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Initial re-vamp of the History tab.
This commit is contained in:
83
web/regression/javascript/history/history_collection_spec.js
Normal file
83
web/regression/javascript/history/history_collection_spec.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import HistoryCollection from '../../../pgadmin/static/js/history/history_collection';
|
||||
|
||||
describe('historyCollection', function () {
|
||||
let historyCollection, historyModel, onChangeSpy;
|
||||
beforeEach(() => {
|
||||
historyModel = [{some: 'thing', someOther: ['array element']}];
|
||||
historyCollection = new HistoryCollection(historyModel);
|
||||
onChangeSpy = jasmine.createSpy('onChangeHandler');
|
||||
|
||||
historyCollection.onChange(onChangeSpy);
|
||||
});
|
||||
|
||||
describe('length', function () {
|
||||
it('returns 0 when underlying history model has no elements', function () {
|
||||
historyCollection = new HistoryCollection([]);
|
||||
|
||||
expect(historyCollection.length()).toBe(0);
|
||||
});
|
||||
|
||||
it('returns the length of the underlying history model', function () {
|
||||
expect(historyCollection.length()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('add', function () {
|
||||
let expectedHistory;
|
||||
beforeEach(() => {
|
||||
historyCollection.add({some: 'new thing', someOther: ['value1', 'value2']});
|
||||
|
||||
expectedHistory = [
|
||||
{some: 'thing', someOther: ['array element']},
|
||||
{some: 'new thing', someOther: ['value1', 'value2']},
|
||||
];
|
||||
});
|
||||
|
||||
it('adds a passed entry', function () {
|
||||
expect(historyCollection.historyList).toEqual(expectedHistory);
|
||||
});
|
||||
|
||||
it('calls the onChange function', function () {
|
||||
expect(onChangeSpy).toHaveBeenCalledWith(expectedHistory);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', function () {
|
||||
beforeEach(() => {
|
||||
historyCollection.reset();
|
||||
});
|
||||
|
||||
it('drops the history', function () {
|
||||
expect(historyCollection.historyList).toEqual([]);
|
||||
expect(historyCollection.length()).toBe(0);
|
||||
});
|
||||
|
||||
it('calls the onChange function', function () {
|
||||
expect(onChangeSpy).toHaveBeenCalledWith([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sort', function () {
|
||||
it('doesn\'t sort');
|
||||
});
|
||||
|
||||
describe('when instantiated', function () {
|
||||
describe('from a history model', function () {
|
||||
it('has the historyModel', () => {
|
||||
let content = historyCollection.historyList;
|
||||
|
||||
expect(content).toEqual(historyModel);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import QueryHistoryEntry from '../../../pgadmin/static/jsx/history/query_history_entry';
|
||||
|
||||
import {mount} from 'enzyme';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
describe('QueryHistoryEntry', () => {
|
||||
let historyWrapper;
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
});
|
||||
|
||||
describe('for a failed query', () => {
|
||||
beforeEach(() => {
|
||||
const historyEntry = {
|
||||
query: 'second sql statement',
|
||||
start_time: new Date(2016, 11, 11, 1, 33, 5, 99),
|
||||
status: false,
|
||||
};
|
||||
historyWrapper = mount(<QueryHistoryEntry historyEntry={historyEntry}/>);
|
||||
});
|
||||
it('displays a pink background color', () => {
|
||||
expect(historyWrapper.find('div').first()).toHaveStyle('backgroundColor', '#F7D0D5');
|
||||
});
|
||||
});
|
||||
|
||||
describe('for a successful query', () => {
|
||||
beforeEach(() => {
|
||||
const historyEntry = {
|
||||
query: 'second sql statement',
|
||||
start_time: new Date(2016, 11, 11, 1, 33, 5, 99),
|
||||
status: true,
|
||||
};
|
||||
historyWrapper = mount(<QueryHistoryEntry historyEntry={historyEntry}/>);
|
||||
});
|
||||
it('does not display a pink background color', () => {
|
||||
expect(historyWrapper.find('div').first()).toHaveStyle('backgroundColor', '#FFF');
|
||||
});
|
||||
});
|
||||
});
|
||||
103
web/regression/javascript/history/query_history_spec.jsx
Normal file
103
web/regression/javascript/history/query_history_spec.jsx
Normal file
@@ -0,0 +1,103 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import QueryHistory from '../../../pgadmin/static/jsx/history/query_history';
|
||||
import QueryHistoryEntry from '../../../pgadmin/static/jsx/history/query_history_entry';
|
||||
import HistoryCollection from '../../../pgadmin/static/js/history/history_collection';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import {mount, shallow} from 'enzyme';
|
||||
|
||||
describe('QueryHistory', () => {
|
||||
let historyWrapper;
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
const historyCollection = new HistoryCollection([]);
|
||||
historyWrapper = shallow(<QueryHistory historyCollection={historyCollection}/>);
|
||||
});
|
||||
|
||||
describe('on construction', () => {
|
||||
it('has no entries', (done) => {
|
||||
let foundChildren = historyWrapper.find(QueryHistoryEntry);
|
||||
expect(foundChildren.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when it has history', () => {
|
||||
describe('when two SQL queries were executed', () => {
|
||||
let foundChildren;
|
||||
|
||||
beforeEach(() => {
|
||||
const historyObjects = [
|
||||
{
|
||||
query: 'second sql statement',
|
||||
start_time: new Date(2016, 11, 11, 1, 33, 5, 99),
|
||||
status: false,
|
||||
row_affected: 1,
|
||||
total_time: '234 msec',
|
||||
message: 'some other message',
|
||||
},
|
||||
{
|
||||
query: 'first sql statement',
|
||||
start_time: new Date(2017, 5, 3, 14, 3, 15, 150),
|
||||
status: true,
|
||||
row_affected: 2,
|
||||
total_time: '14 msec',
|
||||
message: 'a very important message',
|
||||
},
|
||||
];
|
||||
const historyCollection = new HistoryCollection(historyObjects);
|
||||
|
||||
historyWrapper = mount(<QueryHistory historyCollection={historyCollection}/>);
|
||||
|
||||
foundChildren = historyWrapper.find(QueryHistoryEntry);
|
||||
});
|
||||
|
||||
it('has two query history entries', () => {
|
||||
expect(foundChildren.length).toBe(2);
|
||||
});
|
||||
|
||||
it('displays the SQL of the queries in order', () => {
|
||||
expect(foundChildren.at(0).text()).toContain('first sql statement');
|
||||
expect(foundChildren.at(1).text()).toContain('second sql statement');
|
||||
});
|
||||
|
||||
it('displays the formatted timestamp of the queries in chronological order by most recent first', () => {
|
||||
expect(foundChildren.at(0).text()).toContain('Jun 3 2017 – 14:03:15');
|
||||
expect(foundChildren.at(1).text()).toContain('Dec 11 2016 – 01:33:05');
|
||||
});
|
||||
|
||||
it('displays the number of rows affected', () => {
|
||||
expect(foundChildren.at(1).text()).toContain('1 rows affected');
|
||||
expect(foundChildren.at(0).text()).toContain('2 rows affected');
|
||||
});
|
||||
|
||||
it('displays the total time', () => {
|
||||
expect(foundChildren.at(0).text()).toContain('total time: 14 msec');
|
||||
expect(foundChildren.at(1).text()).toContain('total time: 234 msec');
|
||||
});
|
||||
|
||||
it('displays the truncated message', () => {
|
||||
expect(foundChildren.at(0).text()).toContain('a very important message');
|
||||
expect(foundChildren.at(1).text()).toContain('some other message');
|
||||
});
|
||||
|
||||
describe('when there are one failing and one successful query each', () => {
|
||||
it('adds a white background color for the successful query', () => {
|
||||
expect(foundChildren.at(0).find('div').first()).toHaveStyle('backgroundColor', '#FFF');
|
||||
});
|
||||
it('adds a red background color for the failed query', () => {
|
||||
expect(foundChildren.at(1).find('div').first()).toHaveStyle('backgroundColor', '#F7D0D5');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user