diff --git a/app/controllers/abstract-paged-controller.js b/app/controllers/abstract-paged-controller.js index e349dedeaf..ddcceae30b 100644 --- a/app/controllers/abstract-paged-controller.js +++ b/app/controllers/abstract-paged-controller.js @@ -43,6 +43,17 @@ export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSess return (!Ember.isEmpty(this.get('previousStartKey')) || !Ember.isEmpty(this.get('nextStartKey'))); }.property('nextStartKey', 'previousStartKey'), + hasRecords: Ember.computed('model.length', { + get() { + let model = this.get('model'); + if (!Ember.isEmpty(model)) { + return (model.get('length') > 0); + } else { + return false; + } + } + }), + actions: { nextPage: function() { var key = this.get('nextStartKey'), diff --git a/app/routes/abstract-index-route.js b/app/routes/abstract-index-route.js index 0790164719..5c489b4442 100644 --- a/app/routes/abstract-index-route.js +++ b/app/routes/abstract-index-route.js @@ -96,9 +96,6 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou setupController: function(controller, model) { var props = this.getProperties('firstKey', 'nextStartKey'); controller.setProperties(props); - if (!Ember.isEmpty(model)) { - controller.set('hasRecords', (model.get('length') > 0)); - } var sectionDetails = { currentScreenTitle: this.get('pageTitle') }; diff --git a/tests/acceptance/inventory-test.js b/tests/acceptance/inventory-test.js index 7050f6aabf..a95458d006 100644 --- a/tests/acceptance/inventory-test.js +++ b/tests/acceptance/inventory-test.js @@ -70,6 +70,28 @@ test('Adding a new inventory item', (assert) => { }); }); +test('Deleting the last inventory item', (assert) => { + runWithPouchDump('inventory', function() { + authenticateUser(); + visit('/inventory/listing'); + + andThen(function() { + assert.equal(currentURL(), '/inventory/listing'); + click('button:contains(Delete)'); + waitToAppear('.modal-dialog'); + andThen(() => { + assert.equal(find('.modal-title').text(), 'Delete Item', 'Deleting confirmation.'); + }); + click('.modal-content button:contains(Delete)'); + andThen(function() { + assert.equal(currentURL(), '/inventory'); + findWithAssert('p:contains(No requests found. )'); + findWithAssert('a:contains(Create a new request?)'); + }); + }); + }); +}); + test('Creating a new inventory request', function(assert) { runWithPouchDump('inventory', function() { authenticateUser();