Skip to content

Commit

Permalink
[ML] angularjs controller initialization tests. (elastic#25382)
Browse files Browse the repository at this point in the history
* [ML] Confirm Modal Controller Test.

* [ML] Message Bar Controller test.

* [ML] Data Visualizer Controller test.

* [ML] Detector Filter Modal Controller test.

* [ML] Detector Modal Controller test.

* [ML] Save Status Modal Controller test.

* [ML] Multi Metric Create Job Controller test.

* [ML] Population Create Job Controller test.

* [ML] Recognize Create Job Controller test.

* [ML] Single Metric Create Job Controller test.

* [ML] Index Or Search Controller test.

* [ML] Job Type Controller test.

* [ML] Angular Bootstrap Patch Dropdown Controller test.

* [ML] Settings Controller test.

* [ML] Calenders List Controller test.

* [ML] New Event Modal Controller test.

* [ML] New Event Modal Controller test.

* [ML] Create Calendar Controller test.

* [ML] Time Series Explorer Controller test.

* [ML] Fixes typo, clearer test name.

* [ML] Fixes tests by restoring stubs.
  • Loading branch information
walterra committed Nov 8, 2018
1 parent 8ed79eb commit 70983cb
Show file tree
Hide file tree
Showing 20 changed files with 648 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';

const mockModalInstance = { close: function () {}, dismiss: function () {} };

describe('ML - Confirm Modal Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Confirm Modal Controller', (done) => {
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlConfirmModal', {
$scope: scope,
$modalInstance: mockModalInstance,
params: {}
});

expect(scope.okLabel).to.be('OK');
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';

describe('ML - Message Bar Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Message Bar Controller', (done) => {
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlMessageBarController', { $scope: scope });

expect(scope.messages).to.eql([]);
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';

// Import this way to be able to stub/mock functions later on in the tests using sinon.
import * as newJobUtils from 'plugins/ml/jobs/new_job/utils/new_job_utils';
import * as indexUtils from 'plugins/ml/util/index_utils';

describe('ML - Data Visualizer View Fields Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Data Visualizer View Fields Controller', (done) => {
const stub1 = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));
const stub2 = sinon.stub(indexUtils, 'timeBasedIndexCheck').callsFake(() => false);
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlDataVisualizerViewFields', { $scope: scope });

expect(scope.metricCards).to.eql([]);
stub1.restore();
stub2.restore();
done();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ describe('ML - Advanced Job Wizard - New Job Controller', () => {
});

it('Initialize New Job Controller', (done) => {
sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
const stub = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));

ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlNewJob', { $scope: scope });
Expand All @@ -31,6 +32,7 @@ describe('ML - Advanced Job Wizard - New Job Controller', () => {
// all angularjs based dependencies get loaded without error.
// This simple scope test is just a final sanity check.
expect(scope.ui.pageTitle).to.be('Create a new job');
stub.restore();
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';

const mockModalInstance = { close: function () {}, dismiss: function () {} };

describe('ML - Detector Filter Modal Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Detector Filter Modal Controller', (done) => {
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlDetectorFilterModal', {
$scope: scope,
$modalInstance: mockModalInstance,
params: { detector: {} }
});

expect(scope.title).to.eql('Add new filter');
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';

const mockModalInstance = { close: function () {}, dismiss: function () {} };

describe('ML - Detector Modal Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Detector Modal Controller', (done) => {
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlDetectorModal', {
$scope: scope,
$modalInstance: mockModalInstance,
params: {}
});

expect(scope.title).to.eql('Add new detector');
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';

const mockModalInstance = { close: function () { }, dismiss: function () { } };

describe('ML - Save Status Modal Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Save Status Modal Controller', (done) => {
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlSaveStatusModal', {
$scope: scope,
$modalInstance: mockModalInstance,
params: {}
});

expect(scope.ui.showTimepicker).to.eql(false);
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';

// Import this way to be able to stub/mock functions later on in the tests using sinon.
import * as newJobUtils from 'plugins/ml/jobs/new_job/utils/new_job_utils';
import * as indexUtils from 'plugins/ml/util/index_utils';
import * as utils from 'plugins/ml/jobs/new_job/simple/components/utils/create_fields';

describe('ML - Multi Metric Wizard - Create Job Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Create Job Controller', (done) => {
const stub1 = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));
const stub2 = sinon.stub(indexUtils, 'timeBasedIndexCheck').callsFake(() => false);
const stub3 = sinon.stub(utils, 'createFields').callsFake(() => false);
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlCreateMultiMetricJob', { $scope: scope });

expect(typeof scope.ui).to.eql('object');
stub1.restore();
stub2.restore();
stub3.restore();
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';

// Import this way to be able to stub/mock functions later on in the tests using sinon.
import * as newJobUtils from 'plugins/ml/jobs/new_job/utils/new_job_utils';
import * as indexUtils from 'plugins/ml/util/index_utils';
import * as utils from 'plugins/ml/jobs/new_job/simple/components/utils/create_fields';

describe('ML - Population Wizard - Create Job Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Create Job Controller', (done) => {
const stub1 = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));
const stub2 = sinon.stub(indexUtils, 'timeBasedIndexCheck').callsFake(() => false);
const stub3 = sinon.stub(utils, 'createFields').callsFake(() => false);
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlCreatePopulationJob', { $scope: scope });

expect(typeof scope.ui).to.eql('object');
stub1.restore();
stub2.restore();
stub3.restore();
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';

// Import this way to be able to stub/mock functions later on in the tests using sinon.
import * as newJobUtils from 'plugins/ml/jobs/new_job/utils/new_job_utils';

describe('ML - Recognize Wizard - Create Job Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Create Job Controller', (done) => {
const stub = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlCreateRecognizerJobs', {
$route: {
current: {
params: {}
}
},
$scope: scope
});

expect(scope.ui.formValid).to.eql(true);
stub.restore();
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/



import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';

// Import this way to be able to stub/mock functions later on in the tests using sinon.
import * as newJobUtils from 'plugins/ml/jobs/new_job/utils/new_job_utils';
import * as indexUtils from 'plugins/ml/util/index_utils';

describe('ML - Single Metric Wizard - Create Job Controller', () => {
beforeEach(() => {
ngMock.module('kibana');
});

it('Initialize Create Job Controller', (done) => {
const stub1 = sinon.stub(newJobUtils, 'createSearchItems').callsFake(() => ({
indexPattern: {},
savedSearch: {},
combinedQuery: {}
}));
const stub2 = sinon.stub(indexUtils, 'timeBasedIndexCheck').callsFake(() => false);
ngMock.inject(function ($rootScope, $controller) {
const scope = $rootScope.$new();
$controller('MlCreateSingleMetricJob', {
$route: {
current: {
params: {}
}
},
$scope: scope
});

expect(scope.ui.showJobInput).to.eql(false);
stub1.restore();
stub2.restore();
done();
});
});
});
Loading

0 comments on commit 70983cb

Please sign in to comment.