This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/tests/acceptance/characteristics-test.js
2015-11-16 10:32:49 -07:00

91 lines
3 KiB
JavaScript

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();
server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
},
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');
assert.equal(server.db.characteristics.length, 1);
});
});
});
test('deleting /characteristics/:id', function(assert) {
const characteristic = server.create('characteristics', { 'canEdit': true });
visit(`/characteristics/${characteristic.id}`);
andThen(function() {
assert.equal(currentURL(), `/characteristics/${characteristic.id}`);
click('button.delete');
andThen(function() {
click('button.delete-confirm');
andThen(function() {
assert.equal(currentURL(), `/characteristics`);
assert.equal(server.db.characteristics.length, 0);
});
});
});
});