From 9c065af74a0a9f4b1ed881296cddbd42cab91464 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 2 Nov 2015 18:06:45 -0700 Subject: [PATCH] Rough in species index test --- app/mirage/config.js | 14 +++++++-- app/mirage/factories/contact.js | 20 ------------- app/mirage/factories/species.js | 11 +++++++ app/mirage/factories/users.js | 8 +++++ .../species/index/species-table/template.hbs | 2 +- config/environment.js | 1 + tests/acceptance/species-test.js | 29 +++++++++++++++++++ 7 files changed, 61 insertions(+), 24 deletions(-) delete mode 100644 app/mirage/factories/contact.js create mode 100644 app/mirage/factories/species.js create mode 100644 app/mirage/factories/users.js create mode 100644 tests/acceptance/species-test.js diff --git a/app/mirage/config.js b/app/mirage/config.js index 02a1be7..a0fc750 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -1,11 +1,19 @@ export default function() { // Don't use mirage for development (for now) this.urlPrefix = 'http://127.0.0.1:8901'; - this.namespace = 'api'; + this.namespace = '/api'; this.passthrough(); } export function testConfig() { - this.urlPrefix = 'http://127.0.0.1:8901'; - this.namespace = 'api'; + this.urlPrefix = 'https://bactdb-test.herokuapp.com'; + this.namespace = '/api/hymenobacter'; + + this.get('/users/:id', function(db, request) { + return { 'user': db.users.find(request.params.id) }; + }); + + this.get('/species', function(db) { + return { 'species': db.species }; + }); } diff --git a/app/mirage/factories/contact.js b/app/mirage/factories/contact.js deleted file mode 100644 index 1b3a3ea..0000000 --- a/app/mirage/factories/contact.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - This is an example factory definition. - - Create more files in this directory to define additional factories. -*/ -import Mirage/*, {faker} */ from 'ember-cli-mirage'; - -export default Mirage.Factory.extend({ - // name: 'Pete', // strings - // age: 20, // numbers - // tall: true, // booleans - - // email: function(i) { // and functions - // return 'person' + i + '@test.com'; - // }, - - // firstName: faker.name.firstName, // using faker - // lastName: faker.name.firstName, - // zipCode: faker.address.zipCode -}); diff --git a/app/mirage/factories/species.js b/app/mirage/factories/species.js new file mode 100644 index 0000000..814b3f2 --- /dev/null +++ b/app/mirage/factories/species.js @@ -0,0 +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, + genusName: 'hymenobacter', + strains: [], + totalStrains: 0, + sortOrder: faker.random.number, +}); diff --git a/app/mirage/factories/users.js b/app/mirage/factories/users.js new file mode 100644 index 0000000..7e14018 --- /dev/null +++ b/app/mirage/factories/users.js @@ -0,0 +1,8 @@ +import Mirage, { faker } from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + name() { return faker.name.firstName() + ' ' + faker.name.lastName(); }, + email: faker.internet.email, + role: 'R', + canEdit: false, +}); diff --git a/app/pods/protected/species/index/species-table/template.hbs b/app/pods/protected/species/index/species-table/template.hbs index b56eba8..f96f9cf 100644 --- a/app/pods/protected/species/index/species-table/template.hbs +++ b/app/pods/protected/species/index/species-table/template.hbs @@ -1,4 +1,4 @@ -

Total species: {{species.length}}

+

Total species: {{species.length}}

{{add-button label="Add Species" link="protected.species.new" canAdd=metaData.canAdd}} diff --git a/config/environment.js b/config/environment.js index fed6d95..849cfed 100644 --- a/config/environment.js +++ b/config/environment.js @@ -36,6 +36,7 @@ module.exports = function(environment) { apiURL = 'https://bactdb-test.herokuapp.com'; ENV.APP.LOG_ACTIVE_GENERATION = false; ENV.APP.LOG_VIEW_LOOKUPS = false; + ENV.locationType = 'none'; } if (environment === 'production') { diff --git a/tests/acceptance/species-test.js b/tests/acceptance/species-test.js new file mode 100644 index 0000000..d6f4151 --- /dev/null +++ b/tests/acceptance/species-test.js @@ -0,0 +1,29 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; +import startApp from '../helpers/start-app'; +import { authenticateSession } from '../helpers/ember-simple-auth'; + +module('Acceptance | species', { + 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 /species', function(assert) { + const species = server.createList('species', 20); + visit('/species'); + + andThen(function() { + assert.equal(currentURL(), '/species'); + assert.equal(find(".flakes-table > tbody > tr").length, species.length); + assert.equal(find("#total-species").text(), "Total species: 20"); + }); +});