mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
rename base object test, reorg state test, add test for fetch clobbering state when missing from URL
This commit is contained in:
parent
699e729fee
commit
dddadb8757
2 changed files with 79 additions and 59 deletions
|
@ -7,42 +7,40 @@ define(function (require) {
|
|||
// Load kibana
|
||||
require('index');
|
||||
|
||||
describe('State Management', function () {
|
||||
describe('BaseObject', function () {
|
||||
var $rootScope;
|
||||
var BaseObject;
|
||||
describe('Base Object', function () {
|
||||
var $rootScope;
|
||||
var BaseObject;
|
||||
|
||||
beforeEach(function () {
|
||||
module('kibana');
|
||||
beforeEach(function () {
|
||||
module('kibana');
|
||||
|
||||
inject(function (_$rootScope_, Private) {
|
||||
$rootScope = _$rootScope_;
|
||||
BaseObject = Private(require('factories/base_object'));
|
||||
});
|
||||
inject(function (_$rootScope_, Private) {
|
||||
$rootScope = _$rootScope_;
|
||||
BaseObject = Private(require('factories/base_object'));
|
||||
});
|
||||
|
||||
it('should take an inital set of values', function () {
|
||||
var baseObject = new BaseObject({ message: 'test' });
|
||||
expect(baseObject).to.have.property('message', 'test');
|
||||
});
|
||||
|
||||
it('should serialize _attributes to RISON', function () {
|
||||
var baseObject = new BaseObject();
|
||||
baseObject.message = 'Testing... 1234';
|
||||
var rison = baseObject.toRISON();
|
||||
expect(rison).to.equal('(message:\'Testing... 1234\')');
|
||||
});
|
||||
|
||||
it('should serialize _attributes for JSON', function () {
|
||||
var baseObject = new BaseObject();
|
||||
baseObject.message = 'Testing... 1234';
|
||||
baseObject._private = 'foo';
|
||||
baseObject.$private = 'stuff';
|
||||
var json = JSON.stringify(baseObject);
|
||||
expect(json).to.equal('{"message":"Testing... 1234"}');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should take an inital set of values', function () {
|
||||
var baseObject = new BaseObject({ message: 'test' });
|
||||
expect(baseObject).to.have.property('message', 'test');
|
||||
});
|
||||
|
||||
it('should serialize _attributes to RISON', function () {
|
||||
var baseObject = new BaseObject();
|
||||
baseObject.message = 'Testing... 1234';
|
||||
var rison = baseObject.toRISON();
|
||||
expect(rison).to.equal('(message:\'Testing... 1234\')');
|
||||
});
|
||||
|
||||
it('should serialize _attributes for JSON', function () {
|
||||
var baseObject = new BaseObject();
|
||||
baseObject.message = 'Testing... 1234';
|
||||
baseObject._private = 'foo';
|
||||
baseObject.$private = 'stuff';
|
||||
var json = JSON.stringify(baseObject);
|
||||
expect(json).to.equal('{"message":"Testing... 1234"}');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
var sinon = require('sinon/sinon');
|
||||
require('services/private');
|
||||
|
@ -8,26 +7,41 @@ define(function (require) {
|
|||
require('index');
|
||||
|
||||
describe('State Management', function () {
|
||||
describe('State', function () {
|
||||
var $rootScope, $location, State, Events;
|
||||
|
||||
var $rootScope, $location, State, Events;
|
||||
beforeEach(function () {
|
||||
module('kibana');
|
||||
|
||||
beforeEach(function () {
|
||||
module('kibana');
|
||||
inject(function (_$rootScope_, _$location_, Private) {
|
||||
$location = _$location_;
|
||||
$rootScope = _$rootScope_;
|
||||
State = Private(require('components/state_management/state'));
|
||||
Events = Private(require('factories/events'));
|
||||
});
|
||||
});
|
||||
|
||||
inject(function (_$rootScope_, _$location_, Private) {
|
||||
$location = _$location_;
|
||||
$rootScope = _$rootScope_;
|
||||
State = Private(require('components/state_management/state'));
|
||||
Events = Private(require('factories/events'));
|
||||
});
|
||||
describe('Provider', function () {
|
||||
it('should reset the state to the defaults', function () {
|
||||
var state = new State('_s', { message: ['test'] });
|
||||
state.reset();
|
||||
var search = $location.search();
|
||||
expect(search).to.have.property('_s');
|
||||
expect(search._s).to.equal('(message:!(test))');
|
||||
expect(state.message).to.eql(['test']);
|
||||
});
|
||||
|
||||
it('should apply the defaults upon initialization', function () {
|
||||
var state = new State('_s', { message: 'test' });
|
||||
expect(state).to.have.property('message', 'test');
|
||||
});
|
||||
|
||||
it('should inherit from Events', function () {
|
||||
var state = new State();
|
||||
expect(state).to.be.an(Events);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Search', function () {
|
||||
it('should save to $location.search()', function () {
|
||||
var state = new State('_s', { test: 'foo' });
|
||||
state.save();
|
||||
|
@ -47,8 +61,9 @@ define(function (require) {
|
|||
var search = $location.search();
|
||||
$rootScope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Fetch', function () {
|
||||
it('should emit an event if changes are fetched', function (done) {
|
||||
var state = new State();
|
||||
state.on('fetch_with_changes', function (keys) {
|
||||
|
@ -91,20 +106,6 @@ define(function (require) {
|
|||
expect(state).to.have.property('message', 'test');
|
||||
});
|
||||
|
||||
it('should reset the state to the defaults', function () {
|
||||
var state = new State('_s', { message: ['test'] });
|
||||
state.reset();
|
||||
var search = $location.search();
|
||||
expect(search).to.have.property('_s');
|
||||
expect(search._s).to.equal('(message:!(test))');
|
||||
expect(state.message).to.eql(['test']);
|
||||
});
|
||||
|
||||
it('should apply the defaults upon initialization', function () {
|
||||
var state = new State('_s', { message: 'test' });
|
||||
expect(state).to.have.property('message', 'test');
|
||||
});
|
||||
|
||||
it('should call fetch when $routeUpdate is fired on $rootScope', function () {
|
||||
var state = new State();
|
||||
var spy = sinon.spy(state, 'fetch');
|
||||
|
@ -112,7 +113,28 @@ define(function (require) {
|
|||
sinon.assert.calledOnce(spy);
|
||||
});
|
||||
|
||||
it('should clear state when missing form URL', function () {
|
||||
var stateObj;
|
||||
var state = new State();
|
||||
|
||||
// set satte via URL
|
||||
$location.search({ _s: '(foo:(bar:baz))' });
|
||||
state.fetch();
|
||||
stateObj = state.toObject();
|
||||
expect(stateObj).to.eql({ foo: { bar: 'baz' } });
|
||||
|
||||
// ensure changing URL changes state
|
||||
$location.search({ _s: '(one:two)' });
|
||||
state.fetch();
|
||||
stateObj = state.toObject();
|
||||
expect(stateObj).to.eql({ one: 'two' });
|
||||
|
||||
// remove search, state should be empty
|
||||
$location.search({});
|
||||
state.fetch();
|
||||
stateObj = state.toObject();
|
||||
expect(stateObj).to.eql({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue