diff --git a/app/controllers/internalRequestController.js b/app/controllers/internalRequestController.js index b04e37e..e5490b9 100644 --- a/app/controllers/internalRequestController.js +++ b/app/controllers/internalRequestController.js @@ -6,6 +6,8 @@ app.controller('InternalRequestController', function ($controller, $scope, ApiRe $scope.internalRequests = InternalRequestRepo.getAll(); + + $scope.internalRequestToCreate = InternalRequestRepo.getScaffold(); $scope.internalRequestToEdit = {}; $scope.internalRequestToDelete = {}; @@ -32,6 +34,21 @@ app.controller('InternalRequestController', function ($controller, $scope, ApiRe return RemoteProductManagerRepo.findById(remoteProductManagerId); }; + $scope.createInternalRequest = function () { + $scope.internalRequestToCreate.createdOn = new Date().getTime(); + + InternalRequestRepo.create($scope.internalRequestToCreate).then(function (res) { + if (angular.fromJson(res.body).meta.status === 'SUCCESS') { + $scope.resetCreateInternalRequest(); + } + }); + }; + + $scope.resetCreateInternalRequest = function () { + angular.extend($scope.internalRequestToCreate, InternalRequestRepo.getScaffold()); + $scope.resetInternalRequestForms(); + }; + $scope.pushInternalRequest = function (internalRequest) { $scope.featureRequestToPush = { id: internalRequest.id, diff --git a/app/repo/internalRequestRepo.js b/app/repo/internalRequestRepo.js index d635441..7dcc844 100644 --- a/app/repo/internalRequestRepo.js +++ b/app/repo/internalRequestRepo.js @@ -4,7 +4,7 @@ app.repo("InternalRequestRepo", function InternalRequestRepo() { internalRequestRepo.scaffold = { title: '', description: '', - timestamp: null + createdOn: null }; return internalRequestRepo; diff --git a/app/views/management/internalRequests.html b/app/views/management/internalRequests.html index d4b91d9..5653fed 100644 --- a/app/views/management/internalRequests.html +++ b/app/views/management/internalRequests.html @@ -1,5 +1,8 @@
+ +
+ @@ -19,6 +22,7 @@
Title
+ diff --git a/app/views/modals/addInternalRequestModal.html b/app/views/modals/addInternalRequestModal.html new file mode 100644 index 0000000..db5170a --- /dev/null +++ b/app/views/modals/addInternalRequestModal.html @@ -0,0 +1,42 @@ + + +
+ + + + + + +
diff --git a/tests/mock/repo/mockInternalRequestRepo.js b/tests/mock/repo/mockInternalRequestRepo.js index 638c56a..5f96699 100644 --- a/tests/mock/repo/mockInternalRequestRepo.js +++ b/tests/mock/repo/mockInternalRequestRepo.js @@ -19,10 +19,10 @@ var dataInternalRequestRepo3 = [ angular.module("mock.internalRequestRepo", []).service("InternalRequestRepo", function ($q) { var repo = mockRepo("InternalRequestRepo", $q, mockInternalRequest, dataInternalRequestRepo1); - this.scaffold = { - title: "", - description: "", - createdOn: "" + repo.scaffold = { + title: '', + description: '', + createdOn: null }; return repo; diff --git a/tests/unit/controllers/internalRequestControllerTest.js b/tests/unit/controllers/internalRequestControllerTest.js index e8f32cb..36e8094 100644 --- a/tests/unit/controllers/internalRequestControllerTest.js +++ b/tests/unit/controllers/internalRequestControllerTest.js @@ -90,11 +90,13 @@ describe("controller: InternalRequestController", function () { "cancelEditInternalRequest", "cancelPushFeatureRequest", "confirmDeleteInternalRequest", + "createInternalRequest", "deleteInternalRequest", "editInternalRequest", "getRemoteProductManagerRemoteProducts", "pushFeatureRequest", "pushInternalRequest", + "resetCreateInternalRequest", "resetInternalRequestForms", "updateInternalRequest" ]; @@ -109,8 +111,6 @@ describe("controller: InternalRequestController", function () { for (var i in methods) { it(methods[i] + " defined", scopeMethodExists(methods[i])); } - - //initializeController({role: "ROLE_MANAGER"}); }); describe("Does the scope method", function () { @@ -165,6 +165,21 @@ describe("controller: InternalRequestController", function () { expect($scope.internalRequestToDelete).toEqual(internalRequest); }); + it("createInternalRequest create a new Internal Requst", function () { + var internalRequest = new mockInternalRequest($q); + var id = dataInternalRequestRepo1.length + 1; + + internalRequest.mock({ + id: id, + name: "Mock Internal Request " + id + }); + + $scope.internalRequestToCreate = internalRequest; + $scope.createInternalRequest(); + + expect(InternalRequestRepo.findById(id)).toEqual(internalRequest); + }); + it("deleteInternalRequest call the repo delete method and then call cancelDeleteInternalRequest when successful", function () { var internalRequest = new mockInternalRequest($q); @@ -230,6 +245,35 @@ describe("controller: InternalRequestController", function () { expect($scope.openModal).toHaveBeenCalled(); }); + it("resetCreateInternalRequest call resetInternalRequestForms() and clear out the properties", function () { + var internalRequest = new mockInternalRequest($q); + var id = dataInternalRequestRepo1.length + 1; + + internalRequest.mock({ + id: id, + name: "Mock Internal Request " + id + }); + + $scope.internalRequestToCreate = internalRequest; + + var modal = angular.element($templateCache.get("views/modals/addInternalRequestModal.html")); + modal = $compile(modal)($scope); + + var form = $scope.internalRequestForms.create; + form.$setDirty(); + + expect(form.$dirty).toEqual(true); + + spyOn($scope, "resetInternalRequestForms"); + + $scope.resetCreateInternalRequest(); + + expect($scope.internalRequestToCreate.title).toEqual(""); + expect($scope.internalRequestToCreate.description).toEqual(""); + expect($scope.internalRequestToCreate.createdOn).toBe(null); + expect($scope.resetInternalRequestForms).toHaveBeenCalled(); + }); + it("resetInternalRequestForms should close modals and reset InternalRequest forms", function () { var modal = angular.element($templateCache.get("views/modals/editInternalRequestModal.html")); modal = $compile(modal)($scope);