Fixed unit tests after labels changes

This commit is contained in:
Michael Abashian
2017-06-26 12:41:02 -04:00
parent 4c12c6d651
commit 7fd2cbe500

View File

@@ -10,14 +10,14 @@ describe('Controller: WorkflowAdd', () => {
GenerateForm, GenerateForm,
TemplatesService, TemplatesService,
q, q,
getLabelsDeferred,
createWorkflowJobTemplateDeferred, createWorkflowJobTemplateDeferred,
httpBackend, httpBackend,
ProcessErrors, ProcessErrors,
CreateSelect2, CreateSelect2,
Wait, Wait,
ParseTypeChange, ParseTypeChange,
ToJSON; ToJSON,
availableLabels;
beforeEach(angular.mock.module('Tower')); beforeEach(angular.mock.module('Tower'));
beforeEach(angular.mock.module('RestServices')); beforeEach(angular.mock.module('RestServices'));
@@ -45,6 +45,11 @@ describe('Controller: WorkflowAdd', () => {
} }
}; };
availableLabels = [{
name: "foo",
id: "1"
}];
ClearScope = jasmine.createSpy('ClearScope'); ClearScope = jasmine.createSpy('ClearScope');
Alert = jasmine.createSpy('Alert'); Alert = jasmine.createSpy('Alert');
ProcessErrors = jasmine.createSpy('ProcessErrors'); ProcessErrors = jasmine.createSpy('ProcessErrors');
@@ -62,9 +67,10 @@ describe('Controller: WorkflowAdd', () => {
$provide.value('Wait', Wait); $provide.value('Wait', Wait);
$provide.value('ParseTypeChange', ParseTypeChange); $provide.value('ParseTypeChange', ParseTypeChange);
$provide.value('ToJSON', ToJSON); $provide.value('ToJSON', ToJSON);
$provide.value('availableLabels', availableLabels);
})); }));
beforeEach(angular.mock.inject( ($rootScope, $controller, $q, $httpBackend, _state_, _ConfigService_, _ClearScope_, _GetChoices_, _Alert_, _GenerateForm_, _ProcessErrors_, _CreateSelect2_, _Wait_, _ParseTypeChange_, _ToJSON_) => { beforeEach(angular.mock.inject( ($rootScope, $controller, $q, $httpBackend, _state_, _ConfigService_, _ClearScope_, _GetChoices_, _Alert_, _GenerateForm_, _ProcessErrors_, _CreateSelect2_, _Wait_, _ParseTypeChange_, _ToJSON_, _availableLabels_) => {
scope = $rootScope.$new(); scope = $rootScope.$new();
state = _state_; state = _state_;
q = $q; q = $q;
@@ -75,10 +81,10 @@ describe('Controller: WorkflowAdd', () => {
ProcessErrors = _ProcessErrors_; ProcessErrors = _ProcessErrors_;
CreateSelect2 = _CreateSelect2_; CreateSelect2 = _CreateSelect2_;
Wait = _Wait_; Wait = _Wait_;
getLabelsDeferred = q.defer();
createWorkflowJobTemplateDeferred = q.defer(); createWorkflowJobTemplateDeferred = q.defer();
ParseTypeChange = _ParseTypeChange_; ParseTypeChange = _ParseTypeChange_;
ToJSON = _ToJSON_; ToJSON = _ToJSON_;
availableLabels = _availableLabels_;
$httpBackend $httpBackend
.whenGET(/^\/api\/?$/) .whenGET(/^\/api\/?$/)
@@ -88,7 +94,6 @@ describe('Controller: WorkflowAdd', () => {
.whenGET(/\/static\/*/) .whenGET(/\/static\/*/)
.respond(200, {}); .respond(200, {});
TemplatesService.getLabelOptions = jasmine.createSpy('getLabelOptions').and.returnValue(getLabelsDeferred.promise);
TemplatesService.createWorkflowJobTemplate = jasmine.createSpy('createWorkflowJobTemplate').and.returnValue(createWorkflowJobTemplateDeferred.promise); TemplatesService.createWorkflowJobTemplate = jasmine.createSpy('createWorkflowJobTemplate').and.returnValue(createWorkflowJobTemplateDeferred.promise);
WorkflowAdd = $controller('WorkflowAdd', { WorkflowAdd = $controller('WorkflowAdd', {
@@ -102,6 +107,7 @@ describe('Controller: WorkflowAdd', () => {
CreateSelect2: CreateSelect2, CreateSelect2: CreateSelect2,
Wait: Wait, Wait: Wait,
ParseTypeChange: ParseTypeChange, ParseTypeChange: ParseTypeChange,
availableLabels: availableLabels,
ToJSON ToJSON
}); });
})); }));
@@ -111,16 +117,13 @@ describe('Controller: WorkflowAdd', () => {
}); });
it('should get/set the label options and select2-ify the input', ()=>{ it('should get/set the label options and select2-ify the input', ()=>{
// Resolve TemplatesService.getLabelsForJobTemplate
getLabelsDeferred.resolve({
foo: "bar"
});
// We expect the digest cycle to fire off this call to /static/config.js so we go ahead and handle it // We expect the digest cycle to fire off this call to /static/config.js so we go ahead and handle it
httpBackend.expectGET('/static/config.js').respond(200); httpBackend.expectGET('/static/config.js').respond(200);
scope.$digest(); scope.$digest();
expect(scope.labelOptions).toEqual({ expect(scope.labelOptions).toEqual([{
foo: "bar" label: "foo",
}); value: "1"
}]);
expect(CreateSelect2).toHaveBeenCalledWith({ expect(CreateSelect2).toHaveBeenCalledWith({
element:'#workflow_job_template_labels', element:'#workflow_job_template_labels',
multiple: true, multiple: true,
@@ -128,18 +131,6 @@ describe('Controller: WorkflowAdd', () => {
}); });
}); });
it('should call ProcessErrors when getLabelsForJobTemplate returns a rejected promise', ()=>{
// Reject TemplatesService.getLabelsForJobTemplate
getLabelsDeferred.reject({
data: "mockedData",
status: 400
});
// We expect the digest cycle to fire off this call to /static/config.js so we go ahead and handle it
httpBackend.expectGET('/static/config.js').respond(200);
scope.$digest();
expect(ProcessErrors).toHaveBeenCalled();
});
describe('scope.formSave()', () => { describe('scope.formSave()', () => {
it('should call TemplatesService.createWorkflowJobTemplate', ()=>{ it('should call TemplatesService.createWorkflowJobTemplate', ()=>{