Skip to content

Commit

Permalink
[Tests] Wrote some simple tests around the loading indicator and time…
Browse files Browse the repository at this point in the history
…picker directives
  • Loading branch information
panda01 committed Mar 17, 2016
1 parent 5a048cd commit e7e710c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/ui/public/chrome/__tests__/kbn_loading_indicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import ngMock from 'ngMock';
import expect from 'expect.js';
import uiModules from 'ui/modules';

import '../directives/kbn_loading_indicator';


describe('kbnLoadingIndicator', function () {
let compile;

beforeEach(() => {
ngMock.module('kibana');
ngMock.inject(function ($compile, $rootScope) {
compile = function (hasActiveConnections) {
$rootScope.chrome = {
httpActive: (hasActiveConnections ? [1] : [])
};
const $el = $('<div kbn-loading-indicator><div id="other-content"></div></div>');
$rootScope.$apply();
$compile($el)($rootScope);
return $el;
};
});

});

it('injects a loading .spinner into the element', function () {
const $el = compile();
expect($el.find('.spinner')).to.have.length(1);
});
// Doesn't work...
xit('applies the ng-hide class when there are no connections', function () {
const $el = compile(false);
expect($el.find('.spinner.ng-hide')).to.have.length(1);
});
it('applies removes ng-hide class when there are connections', function () {
const $el = compile(true);
expect($el.find('.spinner.ng-hide')).to.have.length(0);
});

it('doesn\'t modify the contents of what the elment already has', function () {
const $el = compile();
expect($el.find('#other-content')).to.have.length(1);
});

});
2 changes: 1 addition & 1 deletion src/ui/public/chrome/directives/kbn_loading_indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const spinnerTemplate = '<div class="spinner" ng-show="chrome.httpActive.length"

UiModules
.get('ui/kibana')
.directive('kbnLoadingIndicator', function($rootScope, $compile) {
.directive('kbnLoadingIndicator', function($compile) {
return {
restrict: 'AC',
link: function(scope, $el) {
Expand Down
22 changes: 22 additions & 0 deletions src/ui/public/timepicker/__tests__/toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ngMock from 'ngMock';
import expect from 'expect.js';
import uiModules from 'ui/modules';

describe('kbnGlobalTimepicker', function () {
let compile;
beforeEach(() => {
ngMock.module('kibana');
ngMock.inject(($compile, $rootScope) => {
compile = () => {
const $el = $('<kbn-global-timepicker></kbn-global-timepicker>');
$rootScope.$apply();
$compile($el)($rootScope);
return $el;
}
});
});
it('injects the timepicker into the DOM', () => {
const $el = compile();
expect($el.find('ul.navbar-timepicker')).to.have.length(1);
});
});

0 comments on commit e7e710c

Please sign in to comment.