Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50ec898
commit 65fb15d
Showing
2 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 48 additions & 11 deletions
59
spec/javascripts/components/generic_object_definition/main-custom-button-form_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,70 @@ | ||
describe('main-custom-button-form-component', function() { | ||
var $componentController, vm, miqService, API, $scope; | ||
beforeEach(module('ManageIQ')); | ||
beforeEach(inject(function (_$componentController_, _API_, _miqService_, $rootScope) { | ||
beforeEach(inject(function (_$componentController_, _API_, _$httpBackend_, _miqService_, $rootScope, $q) { | ||
$componentController = _$componentController_; | ||
API = _API_; | ||
miqService = _miqService_; | ||
$scope = $rootScope.$new(); | ||
spyOn(miqService, 'miqFlash'); | ||
$httpBackend = _$httpBackend_; | ||
|
||
var bindings = {genericObjectDefinitionRecordId: '1', customButtonGroupRecordId: '2', customButtonRecordId: '3', redirectUrl: '/redirect/url'}; | ||
vm = $componentController('mainCustomButtonFormController', null, bindings); | ||
var volumeChoicesResponse = {volume_choices: [{ name : "original value" }, { name: "changed value" }]}; | ||
API.whenGET('/cloud_volume_backup/volume_form_choices').respond(volumeChoicesResponse); | ||
vm = $componentController("mainCustomButtonFormComponent", null, bindings); | ||
var deferred = $q.defer(); | ||
spyOn(API, 'get').and.callFake(function() {return deferred.promise;}); | ||
var domainsResponse = { | ||
data:{ | ||
distinct_instances_across_domains: ["Automation", "Event", "GenericObject", "MiqEvent", "Request", "parse_automation_request", "parse_event_stream", "parse_provider_category"] | ||
} | ||
}; | ||
$httpBackend.whenGET('/generic_object_definition/retrieve_distinct_instances_across_domains').respond(domainsResponse); | ||
vm.$onInit(); | ||
$httpBackend.flush(); | ||
})); | ||
|
||
describe('#saveClick', function() { | ||
beforeEach(function(){ | ||
vm.saveClicked(); | ||
spyOn(window, 'add_flash'); | ||
}); | ||
it('delegates miqService ajaxButton', function() { | ||
expect(miqService.miqAjaxButton).toHaveBeenCalledWith('/cloud_volume_backup/backup_restore/1111?button=restore', vm.cloudVolumeBackupModel, { complete: false }); | ||
|
||
it('catch 400 and call add_flash if error is name/description taken', function(done) { | ||
var rejectionData = {status: 400, data: {error: {message: "Name has already been taken, Description has already been taken"}}}; | ||
spyOn(API, 'put').and.returnValue(Promise.reject(rejectionData)); | ||
vm.saveClicked() | ||
.then( function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}) | ||
.catch(function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#addClick', function() { | ||
beforeEach(function(){ | ||
vm.addClicked(); | ||
spyOn(window, 'add_flash'); | ||
spyOn(miqService, 'handleFailure').and.callFake(function() {debugger;return Promise.reject()}); | ||
}); | ||
it('delegates miqService ajaxButton', function() { | ||
expect(miqService.miqAjaxButton).toHaveBeenCalledWith('/cloud_volume_backup/backup_restore/1111?button=restore', vm.cloudVolumeBackupModel, { complete: false }); | ||
|
||
it('catch 400 and call add_flash', function(done) { | ||
var rejectionData = {status: 400, data: {error: {message: "Name has already been taken, Description has already been taken"}}}; | ||
spyOn(API, 'post').and.returnValue(Promise.reject(rejectionData)); | ||
vm.addClicked() | ||
.then( function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}) | ||
.catch(function () { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |