fixin some tests

This commit is contained in:
Spencer Alger 2015-04-30 13:32:10 -07:00
parent eed15bb31b
commit 12b72a6930
4 changed files with 33 additions and 28 deletions

View file

@ -1,18 +1,22 @@
define(function (require) {
var angular = require('angular');
var _ = require('lodash');
var longString = Array(200).join('_');
return function (id, mapping) {
var fake = {
$$_formatted: _.mapValues(mapping, function (f, c) { return c + '_formatted_' + id + longString; }),
$$_flattened: _.mapValues(mapping, function (f, c) { return c + '_flattened_' + id + longString; }),
_source: _.mapValues(mapping, function (f, c) { return c + '_original_' + id + longString; }),
function fakeVals(type) {
return _.mapValues(mapping, function (f, c) {
return c + '_' + type + '_' + id + longString;
});
}
return {
_id: id,
_index: 'test',
sort: [id]
_source: fakeVals('original'),
sort: [id],
$$_formatted: fakeVals('formatted'),
$$_partialFormatted: fakeVals('formatted'),
$$_flattened: fakeVals('_flattened')
};
return fake;
};
});
});

View file

@ -16,17 +16,18 @@ define(function (require) {
// Stub out a minimal mapping of 4 fields
var mapping;
beforeEach(module('kibana', 'apps/discover'));
beforeEach(inject(function (_config_, $rootScope, Private) {
config = _config_;
$parentScope = $rootScope;
$parentScope.indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
mapping = $parentScope.indexPattern.fields.byName;
}));
// Sets up the directive, take an element, and a list of properties to attach to the parent scope.
var init = function ($elem, props) {
module('kibana');
inject(function ($rootScope, $compile, _config_, Private) {
config = _config_;
$parentScope = $rootScope;
inject(function ($compile) {
_.assign($parentScope, props);
$parentScope.indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
mapping = $parentScope.indexPattern.fields.byName;
$compile($elem)($parentScope);
$elem.scope().$digest();
$scope = $elem.isolateScope();
@ -314,7 +315,6 @@ define(function (require) {
var $root;
var $before;
beforeEach(module('kibana', 'apps/discover'));
beforeEach(inject(function ($rootScope, $compile, Private) {
$root = $rootScope;
$root.row = getFakeRow(0, mapping);
@ -342,7 +342,6 @@ define(function (require) {
expect($before).to.have.length(3);
expect($before.eq(0).text().trim()).to.be('');
expect($before.eq(1).text().trim()).to.match(/^time_formatted/);
expect($before.eq(2).find('dl dt').length).to.be(_.keys($scope.row.$$_flattened).length);
}));
afterEach(function () {
@ -444,7 +443,7 @@ define(function (require) {
});
it('handles two columns with the same content', function () {
$root.row.$$_formatted.request_body = $root.row.$$_formatted.bytes;
$root.row.$$_partialFormatted.request_body = $root.row.$$_partialFormatted.bytes;
$root.columns.length = 0;
$root.columns.push('bytes');
$root.columns.push('request_body');

View file

@ -2,10 +2,6 @@ define(function (require) {
var $ = require('jquery');
describe('fancy forms', function () {
var $baseEl = $('<form>').append(
$('<input ng-model="val" required>')
);
var $el;
var $scope;
var $compile;
@ -13,13 +9,19 @@ define(function (require) {
var ngForm;
var ngModel;
function generateEl() {
return $('<form>').html(
$('<input ng-model="val" required>')
);
}
beforeEach(module('kibana'));
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');
$scope = $rootScope.$new();
$el = $baseEl.clone();
$el = generateEl();
$compile($el)($scope);
$scope.$apply();
@ -71,7 +73,7 @@ define(function (require) {
it('sets the model dirty when it moves from valid to invalid', function () {
// clear out the old scope/el
$scope.$destroy();
$el = $baseEl.clone();
$el = generateEl();
$scope = $rootScope.$new();
// start with a valid value

View file

@ -199,9 +199,9 @@ define(function (require) {
convertHtml = format.getConverterFor('html');
}));
it('uses the hit source, indexPattern, and the hit itself to create a <dl>', function () {
it('uses the _source, field, and hit to create a <dl>', function () {
var hit = _.first(hits);
var $dl = $(convertHtml(hit._source, indexPattern, hit));
var $dl = $(convertHtml(hit._source, indexPattern.fields.byName._source, hit));
expect($dl.is('dl')).to.be.ok();
expect($dl.find('dt')).to.have.length(_.keys(indexPattern.flattenHit(hit)).length);
});