Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
334 delete inventory requests (#1071)
Browse files Browse the repository at this point in the history
* Add delete request to inventory/index

* Add delete inventory request tests
  • Loading branch information
stoyan-ekupov authored and jkleinsc committed May 18, 2017
1 parent 17d2eeb commit 63d9022
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
10 changes: 9 additions & 1 deletion app/inventory/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Ember from 'ember';
import AbstractPagedController from 'hospitalrun/controllers/abstract-paged-controller';
import UserSession from 'hospitalrun/mixins/user-session';

const { computed } = Ember;

export default AbstractPagedController.extend(UserSession, {
startKey: [],
canAdd: function() {
Expand All @@ -8,5 +12,9 @@ export default AbstractPagedController.extend(UserSession, {

canFulfill: function() {
return this.currentUserCan('fulfill_inventory');
}.property()
}.property(),

currentUserName: computed('', function() {
return this.getUserName();
})
});
15 changes: 8 additions & 7 deletions app/inventory/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
<th>{{t 'labels.quantity'}}</th>
<th>{{t 'labels.requestedOn'}}</th>
<th>{{t 'labels.requestedBy'}}</th>
{{#if canFulfill}}
<th>{{t 'labels.actions'}}</th>
{{/if}}
<th>{{t 'labels.actions'}}</th>
</tr>
{{#each model as |request|}}
<tr>
<td>{{request.inventoryItem.name}}</td>
<td>{{request.quantity}}</td>
<td>{{date-format request.dateRequested}}</td>
<td>{{request.requestedBy}}</td>
{{#if canFulfill}}
<td>
<td>
{{#if canFulfill}}
<button class="btn btn-primary" {{action 'fulfill' request}}>{{t 'labels.fulfill'}}</button>
</td>
{{/if}}
{{/if}}
{{#if (or canFulfill (and canAdd (eq request.requestedBy currentUserName)))}}
<button class="btn btn-default warning" {{action 'deleteItem' request bubbles=false }}><span class="octicon octicon-x"></span> {{t 'buttons.delete'}}</button>
{{/if}}
</td>
</tr>
{{/each}}
</table>
Expand Down
43 changes: 43 additions & 0 deletions tests/acceptance/inventory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,49 @@ test('Fulfilling an inventory request', function(assert) {
});
});

test('Deleting an inventory request', function(assert) {
runWithPouchDump('inventory', function() {
authenticateUser();
visit('/inventory');

andThen(() => {
assert.equal(currentURL(), '/inventory', 'Navigated to /inventory');
assert.equal(find('button:contains(Delete)').length, 1, 'There is one request');
});

click('button:contains(Delete)');
waitToAppear('.modal-dialog');

andThen(() => {
assert.equal(find('.modal-title').text(), 'Delete Item', 'Deleting confirmation');
});

click('.modal-content button:contains(Delete)');
waitToAppear('.panel-body .alert-info');

andThen(function() {
assert.equal(currentURL(), '/inventory', 'Navigated to /inventory');
assert.equal(find('button:contains(Delete)').length, 0, 'Request was deleted');
});
});
});

test('User with add_inventory_request and without fulfill_inventory rights should not be able to delete others\' requests', function(assert) {
runWithPouchDump('inventory', function() {
authenticateUser({
name: 'nurse.mgr',
roles: ['Nurse Manager', 'user'],
role: 'Nurse Manager'
});
visit('/inventory');

andThen(() => {
assert.equal(currentURL(), '/inventory', 'Navigated to /inventory');
assert.equal(find('button:contains(Delete)').length, 0, 'User doesn\'t see Delete button');
});
});
});

test('Receiving inventory', function(assert) {
runWithPouchDump('inventory', function() {
authenticateUser();
Expand Down

0 comments on commit 63d9022

Please # to comment.