mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Added tests for patternChecker directive
This commit is contained in:
parent
f83c4fdbff
commit
615560f0db
2 changed files with 95 additions and 1 deletions
95
src/ui/public/pattern_checker/__tests__/pattern_checker.js
Normal file
95
src/ui/public/pattern_checker/__tests__/pattern_checker.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import _ from 'lodash';
|
||||
import sinon from 'auto-release-sinon';
|
||||
|
||||
describe('pattern checker', function () {
|
||||
let $httpBackend;
|
||||
let $compile;
|
||||
let $rootScope;
|
||||
let apiResponse;
|
||||
let $timeout;
|
||||
const notifyFatalStub = sinon.stub();
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
|
||||
beforeEach(ngMock.module(function ($provide) {
|
||||
notifyFatalStub.reset();
|
||||
|
||||
$provide.value('Notifier', function () {
|
||||
this.fatal = notifyFatalStub;
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(ngMock.inject(function ($injector, Private) {
|
||||
$httpBackend = $injector.get('$httpBackend');
|
||||
$compile = $injector.get('$compile');
|
||||
$rootScope = $injector.get('$rootScope');
|
||||
$timeout = $injector.get('$timeout');
|
||||
|
||||
apiResponse = $httpBackend.when('POST', /\/api\/kibana\/.*\/_count/);
|
||||
}));
|
||||
|
||||
it('should display the number of documents in a given index pattern', function () {
|
||||
apiResponse.respond(200, {count: 1});
|
||||
|
||||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope);
|
||||
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
expect(_.contains(element.html(), `1 results`)).to.be.ok();
|
||||
});
|
||||
|
||||
it('should poll the api for changes to the document count and update the ui', function () {
|
||||
apiResponse.respond(200, {count: 1});
|
||||
|
||||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope);
|
||||
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
expect(_.contains(element.html(), `1 results`)).to.be.ok();
|
||||
|
||||
apiResponse.respond(200, {count: 2});
|
||||
$timeout.flush();
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
expect(_.contains(element.html(), `2 results`)).to.be.ok();
|
||||
});
|
||||
|
||||
it('should display 0 results when API responds with 404', function () {
|
||||
apiResponse.respond(404);
|
||||
|
||||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope);
|
||||
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
expect(_.contains(element.html(), `0 results`)).to.be.ok();
|
||||
});
|
||||
|
||||
it('should throw a fatal notificaiton for any error other than a 404', function () {
|
||||
apiResponse.respond(500, 'Bad things happened');
|
||||
|
||||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope);
|
||||
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(notifyFatalStub.called).to.be.ok();
|
||||
});
|
||||
|
||||
it('should stop polling when the scope is destroyed', function () {
|
||||
apiResponse.respond(200, {count: 1});
|
||||
|
||||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope);
|
||||
const scope = element.scope();
|
||||
|
||||
$httpBackend.flush();
|
||||
$rootScope.$digest();
|
||||
expect(_.contains(element.html(), `1 results`)).to.be.ok();
|
||||
|
||||
scope.$destroy();
|
||||
$timeout.flush();
|
||||
$httpBackend.verifyNoOutstandingRequest();
|
||||
});
|
||||
|
||||
});
|
|
@ -26,7 +26,6 @@ module.directive('patternChecker', function () {
|
|||
.then(
|
||||
(response) => {
|
||||
this.resultCount = response.data.count;
|
||||
this.isValidated = !!response.data.count;
|
||||
},
|
||||
(error) => {
|
||||
if (error.status === 404) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue