diff --git a/app/mirage/config.js b/app/mirage/config.js
index 935eb17..418da09 100644
--- a/app/mirage/config.js
+++ b/app/mirage/config.js
@@ -19,11 +19,13 @@ export function testConfig() {
this.post('/species');
this.get('/species/:id');
this.put('/species/:id');
+ this.delete('/species/:id');
this.get('/characteristics');
this.post('/characteristics');
this.get('/characteristics/:id');
this.put('/characteristics/:id');
+ this.delete('/characteristics/:id');
this.get('/strains', function(db /*, request*/) {
return {
@@ -39,4 +41,5 @@ export function testConfig() {
};
});
this.put('/strains/:id');
+ this.delete('/strains/:id');
}
diff --git a/app/pods/components/delete-button/component.js b/app/pods/components/delete-button/component.js
index 1cd364a..77fc1d0 100644
--- a/app/pods/components/delete-button/component.js
+++ b/app/pods/components/delete-button/component.js
@@ -1,16 +1,23 @@
import Ember from 'ember';
-export default Ember.Component.extend({
- tagName: 'button',
- classNames: ["button-red", "smaller", "delete"],
+const { Component } = Ember;
+
+export default Component.extend({
+ tagName: 'span',
showConfirmDelete: false,
- click: function() {
- if (!this.get('showConfirmDelete')) {
+ actions: {
+ initialClick: function() {
this.set('showConfirmDelete', true);
- } else {
+ },
+
+ cancelDelete: function() {
+ this.set('showConfirmDelete', false);
+ },
+
+ confirmDelete: function() {
this.attrs.delete();
- }
+ },
},
});
diff --git a/app/pods/components/delete-button/template.hbs b/app/pods/components/delete-button/template.hbs
index de6c612..0fd90d7 100644
--- a/app/pods/components/delete-button/template.hbs
+++ b/app/pods/components/delete-button/template.hbs
@@ -1,5 +1,12 @@
-{{#if showConfirmDelete}}
- Are you sure?
+{{#unless showConfirmDelete}}
+
{{else}}
- Delete
-{{/if}}
+
+
+{{/unless}}
diff --git a/tests/acceptance/characteristics-test.js b/tests/acceptance/characteristics-test.js
index ad62807..b8a2edd 100644
--- a/tests/acceptance/characteristics-test.js
+++ b/tests/acceptance/characteristics-test.js
@@ -6,10 +6,10 @@ import { authenticateSession } from '../helpers/ember-simple-auth';
module('Acceptance | characteristics', {
beforeEach: function() {
this.application = startApp();
+ server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
- server.create('users', { role: 'A', canEdit: true });
},
afterEach: function() {
@@ -70,3 +70,22 @@ test('creating /characteristics/new', function(assert) {
});
});
});
+
+test('deleting /characteristics/:id', function(assert) {
+ const characteristic = server.create('characteristics', { 'canEdit': true });
+ visit(`/characteristics/${characteristic.id}`);
+
+ andThen(function() {
+ assert.equal(currentURL(), `/characteristics/${characteristic.id}`);
+ click('button.delete');
+
+ andThen(function() {
+ click('button.delete-confirm');
+
+ andThen(function() {
+ assert.equal(currentURL(), `/characteristics`);
+ assert.equal(server.db.characteristics.length, 0);
+ });
+ });
+ });
+});
diff --git a/tests/acceptance/species-test.js b/tests/acceptance/species-test.js
index 1b4fe85..a137276 100644
--- a/tests/acceptance/species-test.js
+++ b/tests/acceptance/species-test.js
@@ -6,10 +6,10 @@ import { authenticateSession } from '../helpers/ember-simple-auth';
module('Acceptance | species', {
beforeEach: function() {
this.application = startApp();
+ server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
- server.create('users', { role: 'A', canEdit: true });
},
afterEach: function() {
@@ -69,3 +69,22 @@ test('creating /species/new', function(assert) {
});
});
});
+
+test('deleting /species/:id', function(assert) {
+ const species = server.create('species', { 'canEdit': true });
+ visit(`/species/${species.id}`);
+
+ andThen(function() {
+ assert.equal(currentURL(), `/species/${species.id}`);
+ click('button.delete');
+
+ andThen(function() {
+ click('button.delete-confirm');
+
+ andThen(function() {
+ assert.equal(currentURL(), `/species`);
+ assert.equal(server.db.species.length, 0);
+ });
+ });
+ });
+});
diff --git a/tests/acceptance/strains-test.js b/tests/acceptance/strains-test.js
index a52e7ed..405960a 100644
--- a/tests/acceptance/strains-test.js
+++ b/tests/acceptance/strains-test.js
@@ -6,10 +6,10 @@ import { authenticateSession } from '../helpers/ember-simple-auth';
module('Acceptance | strains', {
beforeEach: function() {
this.application = startApp();
+ server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
- server.create('users', { role: 'A', canEdit: true });
},
afterEach: function() {
@@ -74,3 +74,23 @@ test('creating /strains/new', function(assert) {
});
});
});
+
+test('deleting /strains/:id', function(assert) {
+ const species = server.create('species');
+ const strain = server.create('strains', { canEdit: true , species: species.id });
+ visit(`/strains/${strain.id}`);
+
+ andThen(function() {
+ assert.equal(currentURL(), `/strains/${strain.id}`);
+ click('button.delete');
+
+ andThen(function() {
+ click('button.delete-confirm');
+
+ andThen(function() {
+ assert.equal(currentURL(), `/strains`);
+ assert.equal(server.db.strains.length, 0);
+ });
+ });
+ });
+});
diff --git a/tests/acceptance/users-test.js b/tests/acceptance/users-test.js
index ed08d72..2fe4d4d 100644
--- a/tests/acceptance/users-test.js
+++ b/tests/acceptance/users-test.js
@@ -6,10 +6,10 @@ import { invalidateSession, authenticateSession } from '../helpers/ember-simple-
module('Acceptance | users', {
beforeEach: function() {
this.application = startApp();
+ server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
- server.create('users', { role: 'A', canEdit: true });
},
afterEach: function() {