diff --git a/app/mirage/config.js b/app/mirage/config.js index a0fc750..48732c1 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -16,4 +16,8 @@ export function testConfig() { this.get('/species', function(db) { return { 'species': db.species }; }); + + this.get('/species/:id', function(db, request) { + return { 'species': db.species.find(request.params.id) }; + }); } diff --git a/app/mirage/factories/species.js b/app/mirage/factories/species.js index 814b3f2..9e8aa7f 100644 --- a/app/mirage/factories/species.js +++ b/app/mirage/factories/species.js @@ -1,11 +1,11 @@ import Mirage, { faker } from 'ember-cli-mirage'; export default Mirage.Factory.extend({ - speciesName: faker.lorem.words, - typeSpecies: faker.random.boolean, - etymology: faker.lorem.sentences, + speciesName() { return faker.lorem.words().join(' '); }, + typeSpecies: faker.random.boolean(), + etymology: faker.lorem.sentences(), genusName: 'hymenobacter', strains: [], totalStrains: 0, - sortOrder: faker.random.number, + sortOrder: faker.random.number(), }); diff --git a/app/pods/protected/species/show/controller.js b/app/pods/protected/species/show/controller.js index b44b6a7..684673b 100644 --- a/app/pods/protected/species/show/controller.js +++ b/app/pods/protected/species/show/controller.js @@ -1,6 +1,8 @@ import Ember from 'ember'; -export default Ember.Controller.extend({ +const { Controller } = Ember; + +export default Controller.extend({ actions: { delete: function() { this.get('model').destroyRecord().then(() => { diff --git a/app/pods/protected/species/show/route.js b/app/pods/protected/species/show/route.js index 94f8361..c99362f 100644 --- a/app/pods/protected/species/show/route.js +++ b/app/pods/protected/species/show/route.js @@ -1,8 +1,10 @@ import Ember from 'ember'; -export default Ember.Route.extend({ +const { Route } = Ember; + +export default Route.extend({ model: function(params) { - return this.store.findRecord('species', params.species_id, { reload: true }); + return this.store.findRecord('species', params.species_id); }, }); diff --git a/app/pods/protected/species/show/species-card/component.js b/app/pods/protected/species/show/species-card/component.js new file mode 100644 index 0000000..1492c0b --- /dev/null +++ b/app/pods/protected/species/show/species-card/component.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; + +const { Component } = Ember; + +export default Component.extend({ + species: null, + "on-delete": null, + + actions: { + deleteSpecies: function() { + return this.attrs['on-delete'](); + }, + }, +}); diff --git a/app/pods/protected/species/show/species-card/template.hbs b/app/pods/protected/species/show/species-card/template.hbs new file mode 100644 index 0000000..fac8247 --- /dev/null +++ b/app/pods/protected/species/show/species-card/template.hbs @@ -0,0 +1,62 @@ +
+
+
+ + Species {{species.speciesName}} + + + {{! ROW 1 }} +
+
+
Strains
+
+
    + {{#each species.strains as |strain index|}} +
  • + {{#link-to 'protected.strains.show' strain.id}} + {{{strain.strainNameMU}}} + {{/link-to}} +
  • + {{/each}} +
+
+
+
+
Type Species?
+
+ {{if species.typeSpecies 'Yes' 'No'}} +
+
+
+ + {{! ROW 2 }} +
+
+
Etymology
+
+ {{{species.etymology}}} +
+
+
+ + {{! ROW 3 }} +
+
+
Record Created
+
{{null-time species.createdAt 'LL'}}
+
+
+
Record Updated
+
{{null-time species.updatedAt 'LL'}}
+
+
+
+
+
+{{#if species.canEdit}} +
+ {{#link-to 'protected.species.edit' species class="button-gray smaller"}} + Edit + {{/link-to}} + {{delete-button delete=(action 'deleteSpecies')}} +{{/if}} diff --git a/app/pods/protected/species/show/template.hbs b/app/pods/protected/species/show/template.hbs index 841a671..d2656ec 100644 --- a/app/pods/protected/species/show/template.hbs +++ b/app/pods/protected/species/show/template.hbs @@ -1,62 +1,5 @@ -
-
-
- - Species {{model.speciesName}} - - - {{! ROW 1 }} -
-
-
Strains
-
-
    - {{#each model.strains as |strain index|}} -
  • - {{#link-to 'protected.strains.show' strain.id}} - {{{strain.strainNameMU}}} - {{/link-to}} -
  • - {{/each}} -
-
-
-
-
Type Species?
-
- {{if model.typeSpecies 'Yes' 'No'}} -
-
-
- - {{! ROW 2 }} -
-
-
Etymology
-
- {{{model.etymology}}} -
-
-
- - {{! ROW 3 }} -
-
-
Record Created
-
{{null-time model.createdAt 'LL'}}
-
-
-
Record Updated
-
{{null-time model.updatedAt 'LL'}}
-
-
-
-
-
-{{#if model.canEdit}} -
- {{#link-to 'protected.species.edit' model class="button-gray smaller"}} - Edit - {{/link-to}} - {{delete-button delete=(action 'delete')}} -{{/if}} +{{ + protected/species/show/species-card + species=model + on-delete=(action 'delete') +}} diff --git a/tests/acceptance/species-test.js b/tests/acceptance/species-test.js index d6f4151..35e9af0 100644 --- a/tests/acceptance/species-test.js +++ b/tests/acceptance/species-test.js @@ -27,3 +27,13 @@ test('visiting /species', function(assert) { assert.equal(find("#total-species").text(), "Total species: 20"); }); }); + +test('visiting /species/:id', function(assert) { + const species = server.create('species'); + visit(`/species/${species.id}`); + + andThen(function() { + assert.equal(currentURL(), `/species/${species.id}`); + assert.equal(find(".flakes-information-box > legend > em").text().trim(), species.speciesName); + }); +});