mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ML] Wrap controller initialization in assertions. (#26265)
- The controller tests introduced in #25382 had a flaw: If a controller initialization would fail and throw an error, that test suite wouldn't be able to clean up any stubs. So tests using the same stubs would report and error because the stubs couldn't be wrapped again. - This PR wraps every controller initialization inside an assertion and catches those errors properly as part of the test.
This commit is contained in:
parent
e93b1fba1e
commit
6c1fd91875
20 changed files with 134 additions and 75 deletions
|
@ -19,11 +19,14 @@ describe('ML - Confirm Modal Controller', () => {
|
|||
it('Initialize Confirm Modal Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlConfirmModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlConfirmModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.okLabel).to.be('OK');
|
||||
done();
|
||||
|
|
|
@ -17,7 +17,10 @@ describe('ML - Message Bar Controller', () => {
|
|||
it('Initialize Message Bar Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlMessageBarController', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlMessageBarController', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.messages).to.eql([]);
|
||||
done();
|
||||
|
|
|
@ -36,7 +36,10 @@ describe('ML - Data Visualizer View Fields Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlDataVisualizerViewFields', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlDataVisualizerViewFields', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.metricCards).to.eql([]);
|
||||
stub.restore();
|
||||
|
|
|
@ -24,7 +24,10 @@ describe('ML - Advanced Job Wizard - New Job Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlNewJob', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlNewJob', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
// This is just about initializing the controller and making sure
|
||||
// all angularjs based dependencies get loaded without error.
|
||||
|
|
|
@ -19,11 +19,14 @@ describe('ML - Detector Filter Modal Controller', () => {
|
|||
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(() => {
|
||||
$controller('MlDetectorFilterModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: { detector: {} }
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.title).to.eql('Add new filter');
|
||||
done();
|
||||
|
|
|
@ -19,11 +19,14 @@ describe('ML - Detector Modal Controller', () => {
|
|||
it('Initialize Detector Modal Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlDetectorModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlDetectorModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.title).to.eql('Add new detector');
|
||||
done();
|
||||
|
|
|
@ -19,11 +19,14 @@ describe('ML - Save Status Modal Controller', () => {
|
|||
it('Initialize Save Status Modal Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlSaveStatusModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlSaveStatusModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.ui.showTimepicker).to.eql(false);
|
||||
done();
|
||||
|
|
|
@ -32,7 +32,10 @@ describe('ML - Multi Metric Wizard - Create Job Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCreateMultiMetricJob', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCreateMultiMetricJob', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(typeof scope.ui).to.eql('object');
|
||||
stub1.restore();
|
||||
|
|
|
@ -32,7 +32,10 @@ describe('ML - Population Wizard - Create Job Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCreatePopulationJob', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCreatePopulationJob', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(typeof scope.ui).to.eql('object');
|
||||
stub1.restore();
|
||||
|
|
|
@ -26,14 +26,17 @@ describe('ML - Recognize Wizard - Create Job Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCreateRecognizerJobs', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCreateRecognizerJobs', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.ui.formValid).to.eql(true);
|
||||
done();
|
||||
|
|
|
@ -30,14 +30,17 @@ describe('ML - Single Metric Wizard - Create Job Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCreateSingleMetricJob', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCreateSingleMetricJob', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.ui.showJobInput).to.eql(false);
|
||||
stub.restore();
|
||||
|
|
|
@ -17,14 +17,17 @@ describe('ML - Index Or Search Controller', () => {
|
|||
it('Initialize Index Or Search Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlNewJobStepIndexOrSearch', {
|
||||
$route: {
|
||||
current: {
|
||||
locals: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlNewJobStepIndexOrSearch', {
|
||||
$route: {
|
||||
current: {
|
||||
locals: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.indexPatterns).to.eql([]);
|
||||
done();
|
||||
|
|
|
@ -33,7 +33,10 @@ describe('ML - Job Type Controller', () => {
|
|||
};
|
||||
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlNewJobStepJobType', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlNewJobStepJobType', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.indexWarningTitle).to.eql('Index pattern test_pattern is not time based');
|
||||
stub.restore();
|
||||
|
|
|
@ -20,10 +20,12 @@ describe('ML - Angular Bootstrap Patch - Dropdown Controller', () => {
|
|||
|
||||
expect(scope.$$watchersCount).to.eql(0);
|
||||
|
||||
$controller('DropdownController', {
|
||||
$attrs: [],
|
||||
$scope: scope
|
||||
});
|
||||
expect(() => {
|
||||
$controller('DropdownController', {
|
||||
$attrs: [],
|
||||
$scope: scope
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.$$watchersCount).to.eql(1);
|
||||
done();
|
||||
|
|
|
@ -17,7 +17,10 @@ describe('ML - Settings Controller', () => {
|
|||
it('Initialize Settings Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlSettings', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlSettings', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.canCreateFilter).to.eql(false);
|
||||
done();
|
||||
|
|
|
@ -17,7 +17,10 @@ describe('ML - Calendars List Controller', () => {
|
|||
it('Initialize Calendars List Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCalendarsList', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCalendarsList', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.permissions.canCreateCalendar).to.eql(false);
|
||||
done();
|
||||
|
|
|
@ -19,11 +19,14 @@ describe('ML - Import Events Modal Controller', () => {
|
|||
it('Initialize Import Events Modal Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlImportEventsModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlImportEventsModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.loadingLock).to.be(false);
|
||||
done();
|
||||
|
|
|
@ -19,11 +19,14 @@ describe('ML - New Event Modal Controller', () => {
|
|||
it('Initialize New Event Modal Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlNewEventModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlNewEventModal', {
|
||||
$scope: scope,
|
||||
$modalInstance: mockModalInstance,
|
||||
params: {}
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.event.description).to.be('');
|
||||
done();
|
||||
|
|
|
@ -17,14 +17,17 @@ describe('ML - Create Calendar Controller', () => {
|
|||
it('Initialize Create Calendar Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlCreateCalendar', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
$controller('MlCreateCalendar', {
|
||||
$route: {
|
||||
current: {
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
$scope: scope
|
||||
});
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.isNewCalendar).to.eql(true);
|
||||
done();
|
||||
|
|
|
@ -17,7 +17,10 @@ describe('ML - Time Series Explorer Controller', () => {
|
|||
it('Initialize Time Series Explorer Controller', (done) => {
|
||||
ngMock.inject(function ($rootScope, $controller) {
|
||||
const scope = $rootScope.$new();
|
||||
$controller('MlTimeSeriesExplorerController', { $scope: scope });
|
||||
|
||||
expect(() => {
|
||||
$controller('MlTimeSeriesExplorerController', { $scope: scope });
|
||||
}).to.not.throwError();
|
||||
|
||||
expect(scope.timeFieldName).to.eql('timestamp');
|
||||
done();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue