Rough in some tests
This commit is contained in:
parent
9fa701c44e
commit
35475c2b92
6 changed files with 112 additions and 4 deletions
|
@ -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');
|
||||
}
|
||||
|
|
17
app/mirage/factories/strains.js
Normal file
17
app/mirage/factories/strains.js
Normal file
|
@ -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(),
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
<h2>{{genus-name}} Strains</h2>
|
||||
<h3>Total strains: {{model.length}}</h3>
|
||||
<h3 id="total-strains">Total strains: {{model.length}}</h3>
|
||||
|
||||
{{add-button label="Add Strain" link="protected.strains.new" canAdd=metaData.canAdd}}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="span-1">
|
||||
<fieldset class="flakes-information-box">
|
||||
<legend>
|
||||
Strain {{model.strainNameMU}}
|
||||
{{model.strainNameMU}}
|
||||
</legend>
|
||||
|
||||
{{! ROW 1 }}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div data-row-span="2">
|
||||
<div data-field-span="1">
|
||||
<label>Strain Name</label>
|
||||
{{input value=strain.strainName}}
|
||||
{{input value=strain.strainName class="strain-name"}}
|
||||
</div>
|
||||
<div data-field-span="1">
|
||||
<label>Type Strain?</label>
|
||||
|
@ -62,7 +62,7 @@
|
|||
Cancel
|
||||
</a>
|
||||
{{#if strain.hasDirtyAttributes}}
|
||||
<button type="submit" class="button-green smaller">
|
||||
<button type="submit" class="button-green smaller save-strain">
|
||||
Save
|
||||
</button>
|
||||
{{/if}}
|
||||
|
|
76
tests/acceptance/strains-test.js
Normal file
76
tests/acceptance/strains-test.js
Normal file
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
Reference in a new issue