Skip to content

Commit

Permalink
Issue 50: add a create button for Internal Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed May 1, 2020
1 parent 47a3353 commit f89bd75
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 7 deletions.
17 changes: 17 additions & 0 deletions app/controllers/internalRequestController.js
Expand Up @@ -6,6 +6,8 @@ app.controller('InternalRequestController', function ($controller, $scope, ApiRe

$scope.internalRequests = InternalRequestRepo.getAll();


$scope.internalRequestToCreate = InternalRequestRepo.getScaffold();
$scope.internalRequestToEdit = {};
$scope.internalRequestToDelete = {};

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/repo/internalRequestRepo.js
Expand Up @@ -4,7 +4,7 @@ app.repo("InternalRequestRepo", function InternalRequestRepo() {
internalRequestRepo.scaffold = {
title: '',
description: '',
timestamp: null
createdOn: null
};

return internalRequestRepo;
Expand Down
4 changes: 4 additions & 0 deletions app/views/management/internalRequests.html
@@ -1,5 +1,8 @@
<div class="management-table" ng-controller="InternalRequestController">

<button class="btn btn-default view-action-button" ng-click="openModal('#addInternalRequestModal')">Add an Internal Request</button>
<hr>

<table class="table table-bordered table-striped internalRequest-table">
<tr>
<th>Title</th>
Expand All @@ -19,6 +22,7 @@
</tr>
</table>

<modal modal-id="addInternalRequestModal" modal-view="views/modals/addInternalRequestModal.html" modal-header-class="modal-header-primary" wvr-modal-backdrop="static"></modal>
<modal modal-id="pushInternalRequestModal" modal-view="views/modals/pushInternalRequestModal.html" modal-header-class="modal-header-primary" wvr-modal-backdrop="static"></modal>
<modal modal-id="editInternalRequestModal" modal-view="views/modals/editInternalRequestModal.html" modal-header-class="modal-header-primary" wvr-modal-backdrop="static"></modal>
<modal modal-id="deleteInternalRequestModal" modal-view="views/modals/deleteInternalRequestModal.html" modal-header-class="modal-header-danger" wvr-modal-backdrop="static"></modal>
Expand Down
42 changes: 42 additions & 0 deletions app/views/modals/addInternalRequestModal.html
@@ -0,0 +1,42 @@
<div class="modal-header {{attr.modalHeaderClass}}">
<button type="button" class="close modal-close" aria-label="Close" ng-click="resetCreateInternalRequest()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Create Internal Request</h4>
</div>

<form name="internalRequestForms.create" ng-submit="createInternalRequest()" novalidate class="internalRequest-forms-create">

<validationmessage results="internalRequestForms.getResults()"></validationmessage>

<div class="modal-body">
<validatedinput
id="internalRequestTitle"
model="internalRequestToCreate"
property="title"
placeholder="Title of the Internal Request"
label="Title"
form="internalRequest.create"
validations="internalRequestForms.validations"
results="internalRequestForms.getResults()"
autocomplete="off">
</validatedinput>

<validatedinput
id="internalRequestDescription"
model="internalRequestToCreate"
property="description"
placeholder="Description of the Internal Request"
label="Description"
form="internalRequest.create"
validations="internalRequestForms.validations"
results="internalRequestForms.getResults()"
autocomplete="off">
</validatedinput>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="resetCreateInternalRequest()">Cancel</button>
<button type="submit" class="btn btn-success" ng-disabled="internalRequestForms.create.$invalid">Create</button>
</div>
</form>
8 changes: 4 additions & 4 deletions tests/mock/repo/mockInternalRequestRepo.js
Expand Up @@ -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;
Expand Down
48 changes: 46 additions & 2 deletions tests/unit/controllers/internalRequestControllerTest.js
Expand Up @@ -90,11 +90,13 @@ describe("controller: InternalRequestController", function () {
"cancelEditInternalRequest",
"cancelPushFeatureRequest",
"confirmDeleteInternalRequest",
"createInternalRequest",
"deleteInternalRequest",
"editInternalRequest",
"getRemoteProductManagerRemoteProducts",
"pushFeatureRequest",
"pushInternalRequest",
"resetCreateInternalRequest",
"resetInternalRequestForms",
"updateInternalRequest"
];
Expand All @@ -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 () {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f89bd75

Please sign in to comment.