From 35c53fc79bff1c7315d8c86eefa664e72edf041f Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 5 Nov 2015 10:16:27 -0700 Subject: [PATCH] Set up tests for existing pod --- app/mirage/config.js | 5 ++ app/mirage/factories/characteristics.js | 10 +++ .../characteristic-form/template.hbs | 4 +- .../characteristics/index/template.hbs | 2 +- tests/acceptance/characteristics-test.js | 71 +++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 app/mirage/factories/characteristics.js create mode 100644 tests/acceptance/characteristics-test.js diff --git a/app/mirage/config.js b/app/mirage/config.js index 79cee5e..929ea8a 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -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'); } diff --git a/app/mirage/factories/characteristics.js b/app/mirage/factories/characteristics.js new file mode 100644 index 0000000..5999c50 --- /dev/null +++ b/app/mirage/factories/characteristics.js @@ -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(), +}); diff --git a/app/pods/protected/characteristics/characteristic-form/template.hbs b/app/pods/protected/characteristics/characteristic-form/template.hbs index b1d68c0..e53cea3 100644 --- a/app/pods/protected/characteristics/characteristic-form/template.hbs +++ b/app/pods/protected/characteristics/characteristic-form/template.hbs @@ -4,7 +4,7 @@
- {{input value=characteristic.characteristicName}} + {{input value=characteristic.characteristicName class="characteristic-name"}}
@@ -23,7 +23,7 @@ Cancel {{#if characteristic.hasDirtyAttributes}} - {{/if}} diff --git a/app/pods/protected/characteristics/index/template.hbs b/app/pods/protected/characteristics/index/template.hbs index 3430386..2aaf25b 100644 --- a/app/pods/protected/characteristics/index/template.hbs +++ b/app/pods/protected/characteristics/index/template.hbs @@ -1,5 +1,5 @@

{{genus-name}} Characteristics

-

Total characteristics: {{model.length}}

+

Total characteristics: {{model.length}}

{{add-button label="Add Characteristic" link="protected.characteristics.new" canAdd=metaData.canAdd}} diff --git a/tests/acceptance/characteristics-test.js b/tests/acceptance/characteristics-test.js new file mode 100644 index 0000000..f53da89 --- /dev/null +++ b/tests/acceptance/characteristics-test.js @@ -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'); + }); + }); +});