Set up tests for existing pod

This commit is contained in:
Matthew Dillon 2015-11-05 10:16:27 -07:00
parent d59aa0e321
commit 35c53fc79b
5 changed files with 89 additions and 3 deletions

View file

@ -16,4 +16,9 @@ export function testConfig() {
this.post('/species');
this.get('/species/:id');
this.put('/species/:id');
this.get('/characteristics');
this.post('/characteristics');
this.get('/characteristics/:id');
this.put('/characteristics/:id');
}

View file

@ -0,0 +1,10 @@
import Mirage, { faker } from 'ember-cli-mirage';
export default Mirage.Factory.extend({
characteristicName() { return faker.lorem.words().join(' '); },
characteristicTypeName() { return faker.lorem.words().join(' '); },
strains: [],
measurements: [],
sortOrder: faker.random.number(),
canEdit: faker.random.boolean(),
});

View file

@ -4,7 +4,7 @@
<div data-row-span="1">
<div data-field-span="1">
<label>Characteristic Name</label>
{{input value=characteristic.characteristicName}}
{{input value=characteristic.characteristicName class="characteristic-name"}}
</div>
</div>
<div data-row-span="2">
@ -23,7 +23,7 @@
Cancel
</a>
{{#if characteristic.hasDirtyAttributes}}
<button type="submit" class="button-green smaller">
<button type="submit" class="button-green smaller save-characteristic">
Save
</button>
{{/if}}

View file

@ -1,5 +1,5 @@
<h2>{{genus-name}} Characteristics</h2>
<h3>Total characteristics: {{model.length}}</h3>
<h3 id="total-characteristics">Total characteristics: {{model.length}}</h3>
{{add-button label="Add Characteristic" link="protected.characteristics.new" canAdd=metaData.canAdd}}

View file

@ -0,0 +1,71 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import { authenticateSession } from '../helpers/ember-simple-auth';
module('Acceptance | characteristics', {
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 /characteristics', function(assert) {
const characteristics = server.createList('characteristics', 20);
visit('/characteristics');
andThen(function() {
assert.equal(currentURL(), '/characteristics');
assert.equal(find(".flakes-table > tbody > tr").length, characteristics.length);
assert.equal(find("#total-characteristics").text(), "Total characteristics: 20");
});
});
test('visiting /characteristics/:id', function(assert) {
const characteristic = server.create('characteristics');
visit(`/characteristics/${characteristic.id}`);
andThen(function() {
assert.equal(currentURL(), `/characteristics/${characteristic.id}`);
assert.equal(find(".flakes-information-box > legend").text().trim(), characteristic.characteristicName);
});
});
test('editing /characteristics/:id/edit', function(assert) {
const characteristic = server.create('characteristics', { 'canEdit': true });
visit(`/characteristics/${characteristic.id}/edit`);
andThen(function() {
assert.equal(currentURL(), `/characteristics/${characteristic.id}/edit`);
fillIn('.characteristic-name', 'Revised Characteristic Name');
click('.save-characteristic');
andThen(function() {
assert.equal(currentURL(), `/characteristics/${characteristic.id}`);
assert.equal(find(".flakes-information-box > legend").text().trim(), 'Revised Characteristic Name');
});
});
});
test('creating /characteristics/new', function(assert) {
visit(`/characteristics/new`);
andThen(function() {
assert.equal(currentURL(), `/characteristics/new`);
fillIn('.characteristic-name', 'New Characteristic Name');
click('.save-characteristic');
andThen(function() {
assert.equal(find(".flakes-information-box > legend").text().trim(), 'New Characteristic Name');
});
});
});