Skip to content

Commit

Permalink
Add javascript for controlling generic object delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarizio committed Nov 18, 2016
1 parent 0032945 commit 2df237f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ManageIQ.angular.app.controller('genericObjectDefinitionFormController', ['$http

genericObjectSubscriptionService.subscribeToShowAddForm(showAddForm);
genericObjectSubscriptionService.subscribeToShowEditForm(showEditForm);
genericObjectSubscriptionService.subscribeToDeleteGenericObject(deleteGenericObject);
genericObjectSubscriptionService.subscribeToTreeClicks(showSelectedItem);
genericObjectSubscriptionService.subscribeToRootTreeclicks(showAllItems);
};
Expand All @@ -25,6 +26,12 @@ ManageIQ.angular.app.controller('genericObjectDefinitionFormController', ['$http
sendDataWithRx({eventType: 'updateToolbarCount', countSelected: 0});
};

var deleteGenericObject = function(_response) {
var data = {id: $scope.genericObjectDefinitionModel.id};

$http.post('delete', data).then(addedOrUpdatedGenericObject);
};

var showAllItems = function(response) {
$scope.genericObjectList = response;
$scope.showSingleItem = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ ManageIQ.angular.app.service('genericObjectSubscriptionService', ['subscriptionS
subscriptionService.subscribeToEventType('showEditForm', callback);
};

this.subscribeToDeleteGenericObject = function(callback) {
subscriptionService.subscribeToEventType('deleteGenericObject', callback);
};

this.subscribeToTreeClicks = function(callback) {
subscriptionService.subscribeToEventType('treeClicked', callback);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('genericObjectDefinitionFormController', function() {
var $scope, $controller, $httpBackend, miqService, genericObjectSubscriptionService;
var showAddFormCallback, showEditFormCallback, treeClickCallback, rootTreeClickCallback;
var showAddFormCallback, showEditFormCallback, deleteGenericObjectCallback, treeClickCallback, rootTreeClickCallback;
var treeData = {the: 'tree_data'};

beforeEach(module('ManageIQ'));
Expand All @@ -24,6 +24,11 @@ describe('genericObjectDefinitionFormController', function() {
showEditFormCallback = callback;
}
);
spyOn(genericObjectSubscriptionService, 'subscribeToDeleteGenericObject').and.callFake(
function(callback) {
deleteGenericObjectCallback = callback;
}
);
spyOn(genericObjectSubscriptionService, 'subscribeToTreeClicks').and.callFake(
function(callback) {
treeClickCallback = callback;
Expand All @@ -38,6 +43,7 @@ describe('genericObjectDefinitionFormController', function() {
$httpBackend.whenGET('tree_data').respond({tree_data: JSON.stringify(treeData)});
$httpBackend.whenPOST('create', {id: '', name: 'name', description: 'description'}).respond({message: "success"});
$httpBackend.whenPOST('save', {id: 123, name: 'new name', description: 'description'}).respond({message: "success"});
$httpBackend.whenPOST('delete', {id: 123}).respond({message: "success"});

$controller = _$controller_('genericObjectDefinitionFormController', {
$scope: $scope,
Expand Down Expand Up @@ -118,7 +124,7 @@ describe('genericObjectDefinitionFormController', function() {
});

it('copies the model to prepare for the reset button', function() {
expect($scope.backupGenericObjectDefinitionModel).toEqual({name: '', description: ''});
expect($scope.backupGenericObjectDefinitionModel).toEqual({id: '', name: '', description: ''});
});

it('sets the newRecord to false', function() {
Expand All @@ -134,6 +140,24 @@ describe('genericObjectDefinitionFormController', function() {
});
});

describe('initialization deleteGenericObjectCallback', function() {
var response = 'does not matter';

beforeEach(function() {
$scope.genericObjectDefinitionModel = {
id: 123,
name: 'potato',
description: 'potato'
};
});

it('posts to the delete action', function() {
$httpBackend.expectPOST('delete', {id: 123}).respond(200, '');
deleteGenericObjectCallback(response);
$httpBackend.flush();
});
});

describe('initialization treeClickCallback', function() {
var response = {id: '123', name: 'name', description: 'description'};

Expand Down Expand Up @@ -234,7 +258,7 @@ describe('genericObjectDefinitionFormController', function() {
});

it('makes a create http request', function() {
$httpBackend.expectPOST('create', {name: 'name', description: 'description'}).respond(200, '');
$httpBackend.expectPOST('create', {id: '', name: 'name', description: 'description'}).respond(200, '');
$scope.addClicked();
$httpBackend.flush();
});
Expand Down Expand Up @@ -283,6 +307,7 @@ describe('genericObjectDefinitionFormController', function() {

it('clears the form', function() {
expect($scope.genericObjectDefinitionModel).toEqual({
id: '',
name: '',
description: ''
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ describe('genericObjectSubscriptionService', function() {
});
});

describe('#subscribeToDeleteGenericObject', function() {
beforeEach(function() {
testService.subscribeToDeleteGenericObject(callback);
});

it('subscribes', function() {
expect(subscriptionService.subscribeToEventType).toHaveBeenCalledWith('deleteGenericObject', callback);
});
});

describe('#subscribeToTreeClicks', function() {
beforeEach(function() {
testService.subscribeToTreeClicks(callback);
Expand Down

0 comments on commit 2df237f

Please sign in to comment.