diff --git a/app/mirage/config.js b/app/mirage/config.js index 3982c0c..e39ccee 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -24,4 +24,19 @@ export function testConfig() { this.post('/characteristics'); this.get('/characteristics/:id'); this.put('/characteristics/:id'); + + this.get('/strains', function(db /*, request*/) { + return { + strains: db.strains, + species: db.species, + }; + }); + this.post('/strains'); + this.get('/strains/:id', function(db, request) { + return { + strain: db.strains.find(request.params.id), + species: db.species, // Just send back everything we've got + } + }); + this.put('/strains/:id'); } diff --git a/app/mirage/factories/strains.js b/app/mirage/factories/strains.js new file mode 100644 index 0000000..6165528 --- /dev/null +++ b/app/mirage/factories/strains.js @@ -0,0 +1,17 @@ +import Mirage, { faker } from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + measurements: [], + characteristics: [], + species: 0, + strainName() { return faker.lorem.words().join(' '); }, + typeStrain: faker.random.boolean(), + accessionNumbers() { return faker.lorem.words().join(' '); }, + genbank() { return faker.lorem.words().join(' '); }, + wholeGenomeSequence() { return faker.lorem.words().join(' '); }, + isolatedFrom: faker.lorem.sentences(), + notes: faker.lorem.sentences(), + totalMeasurements: 0, + sortOrder: faker.random.number(), + canEdit: faker.random.boolean(), +}); diff --git a/app/pods/protected/strains/index/template.hbs b/app/pods/protected/strains/index/template.hbs index 077d22a..851f93b 100644 --- a/app/pods/protected/strains/index/template.hbs +++ b/app/pods/protected/strains/index/template.hbs @@ -1,5 +1,5 @@

{{genus-name}} Strains

-

Total strains: {{model.length}}

+

Total strains: {{model.length}}

{{add-button label="Add Strain" link="protected.strains.new" canAdd=metaData.canAdd}} diff --git a/app/pods/protected/strains/show/template.hbs b/app/pods/protected/strains/show/template.hbs index 8a10e60..87d5d4f 100644 --- a/app/pods/protected/strains/show/template.hbs +++ b/app/pods/protected/strains/show/template.hbs @@ -1,7 +1,7 @@
- Strain {{model.strainNameMU}} + {{model.strainNameMU}} {{! ROW 1 }} diff --git a/app/pods/protected/strains/strain-form/template.hbs b/app/pods/protected/strains/strain-form/template.hbs index 109d037..fef122d 100644 --- a/app/pods/protected/strains/strain-form/template.hbs +++ b/app/pods/protected/strains/strain-form/template.hbs @@ -4,7 +4,7 @@
- {{input value=strain.strainName}} + {{input value=strain.strainName class="strain-name"}}
@@ -62,7 +62,7 @@ Cancel {{#if strain.hasDirtyAttributes}} - {{/if}} diff --git a/tests/acceptance/strains-test.js b/tests/acceptance/strains-test.js new file mode 100644 index 0000000..a52e7ed --- /dev/null +++ b/tests/acceptance/strains-test.js @@ -0,0 +1,76 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; +import startApp from '../helpers/start-app'; +import { authenticateSession } from '../helpers/ember-simple-auth'; + +module('Acceptance | strains', { + beforeEach: function() { + this.application = startApp(); + authenticateSession(this.application, { + access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg" + }); + server.create('users', { role: 'A', canEdit: true }); + }, + + afterEach: function() { + Ember.run(this.application, 'destroy'); + } +}); + +test('visiting /strains', function(assert) { + const species = server.create('species'); + const strains = server.createList('strains', 20, { species: species.id }); + visit('/strains'); + + andThen(function() { + assert.equal(currentURL(), '/strains'); + assert.equal(find(".flakes-table > tbody > tr").length, strains.length); + assert.equal(find("#total-strains").text(), "Total strains: 20"); + }); +}); + +test('visiting /strains/:id', function(assert) { + const species = server.create('species'); + const strain = server.create('strains', { species: species.id }); + visit(`/strains/${strain.id}`); + + andThen(function() { + assert.equal(currentURL(), `/strains/${strain.id}`); + const typeStrain = strain.typeStrain ? 'T' : ''; + assert.equal(find(".flakes-information-box > legend").text().trim(), `${strain.strainName}${typeStrain}`); + }); +}); + +test('editing /strains/:id/edit', function(assert) { + const species = server.create('species'); + const strain = server.create('strains', { canEdit: true , species: species.id }); + visit(`/strains/${strain.id}/edit`); + + andThen(function() { + assert.equal(currentURL(), `/strains/${strain.id}/edit`); + + fillIn('.strain-name', 'Revised Strain Name'); + click('.save-strain'); + + andThen(function() { + assert.equal(currentURL(), `/strains/${strain.id}`); + const typeStrain = strain.typeStrain ? 'T' : ''; + assert.equal(find(".flakes-information-box > legend").text().trim(), `Revised Strain Name${typeStrain}`); + }); + }); +}); + +test('creating /strains/new', function(assert) { + visit(`/strains/new`); + + andThen(function() { + assert.equal(currentURL(), `/strains/new`); + fillIn('.strain-name', 'New Strain Name'); + click('.save-strain'); + + andThen(function() { + assert.equal(find(".flakes-information-box > legend").text().trim(), `New Strain Name`); + assert.equal(server.db.strains.length, 1); + }); + }); +});