pgadmin4/web/regression/javascript/history/history_collection_spec.js

83 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-06-13 03:50:41 -05:00
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2018-01-05 04:42:49 -06:00
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
2017-06-13 03:50:41 -05:00
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import HistoryCollection from '../../../pgadmin/static/js/history/history_collection';
import '../helper/enzyme.helper';
2017-06-13 03:50:41 -05:00
describe('historyCollection', function () {
2017-07-07 09:50:56 -05:00
let historyCollection, historyModel, onChangeSpy, onResetSpy;
2017-06-13 03:50:41 -05:00
beforeEach(() => {
historyModel = [{some: 'thing', someOther: ['array element']}];
historyCollection = new HistoryCollection(historyModel);
onChangeSpy = jasmine.createSpy('onChangeHandler');
2017-07-07 09:50:56 -05:00
onResetSpy = jasmine.createSpy('onResetHandler');
2017-06-13 03:50:41 -05:00
historyCollection.onChange(onChangeSpy);
2017-07-07 09:50:56 -05:00
historyCollection.onReset(onResetSpy);
2017-06-13 03:50:41 -05:00
});
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);
});
2017-07-07 09:50:56 -05:00
it('calls the onReset function', function () {
expect(onResetSpy).toHaveBeenCalledWith([]);
2017-06-13 03:50:41 -05:00
});
});
describe('when instantiated', function () {
describe('from a history model', function () {
it('has the historyModel', () => {
let content = historyCollection.historyList;
expect(content).toEqual(historyModel);
});
});
});
2018-01-05 04:42:49 -06:00
});