Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] angularjs controller initialization tests. #25382

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5a0ba4e
[ML] Confirm Modal Controller Test.
walterra Nov 7, 2018
0b9afa1
[ML] Message Bar Controller test.
walterra Nov 7, 2018
d798544
[ML] Data Visualizer Controller test.
walterra Nov 7, 2018
a32b329
[ML] Detector Filter Modal Controller test.
walterra Nov 7, 2018
23010a7
[ML] Detector Modal Controller test.
walterra Nov 7, 2018
73b7b78
[ML] Save Status Modal Controller test.
walterra Nov 7, 2018
abf184c
[ML] Multi Metric Create Job Controller test.
walterra Nov 7, 2018
0165aa2
[ML] Population Create Job Controller test.
walterra Nov 7, 2018
67badf3
[ML] Recognize Create Job Controller test.
walterra Nov 8, 2018
6bf10ed
[ML] Single Metric Create Job Controller test.
walterra Nov 8, 2018
9377611
[ML] Index Or Search Controller test.
walterra Nov 8, 2018
5a86e75
[ML] Job Type Controller test.
walterra Nov 8, 2018
75e5a96
[ML] Angular Bootstrap Patch Dropdown Controller test.
walterra Nov 8, 2018
02a8ef7
[ML] Settings Controller test.
walterra Nov 8, 2018
516d700
[ML] Calenders List Controller test.
walterra Nov 8, 2018
808d829
[ML] New Event Modal Controller test.
walterra Nov 8, 2018
feeb053
[ML] New Event Modal Controller test.
walterra Nov 8, 2018
093f37b
[ML] Create Calendar Controller test.
walterra Nov 8, 2018
138a02e
[ML] Time Series Explorer Controller test.
walterra Nov 8, 2018
b375232
[ML] Fixes typo, clearer test name.
walterra Nov 8, 2018
930924c
[ML] Fixes tests by restoring stubs.
walterra Nov 8, 2018
b980524
Merge remote-tracking branch 'upstream/master' into ml-angularjs-cont…
walterra Nov 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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