[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:
Walter Rafelsberger 2018-11-27 17:03:04 +01:00 committed by GitHub
parent e93b1fba1e
commit 6c1fd91875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 134 additions and 75 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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.

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();