Skip to content

Commit

Permalink
Uncomment commented out ember integration tests
Browse files Browse the repository at this point in the history
* adding an author
* inviting an editor
  • Loading branch information
pairing committed May 7, 2015
1 parent d6e0c77 commit 7e62de5
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 146 deletions.
4 changes: 3 additions & 1 deletion client/tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"andThen",
"currentURL",
"currentPath",
"currentRouteName"
"currentRouteName",
"pickFromSelect2",
"pickFromChosenSingle"
],
"node": false,
"browser": false,
Expand Down
58 changes: 0 additions & 58 deletions client/tests/addons/add-author-test.coffee

This file was deleted.

59 changes: 59 additions & 0 deletions client/tests/addons/add-author-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Ember from "ember";
import { module, test } from "qunit";
import startApp from "tahi/tests/helpers/start-app";
import FactoryGuy from "ember-data-factory-guy";
import TestHelper from "ember-data-factory-guy/factory-guy-test-helper";

TestHelper.mapFind = function(modelName, json) {
let responseJson = {};
if ((/Task/).test(modelName)) {
responseJson["tasks"] = json;
} else {
responseJson[Ember.String.pluralize(modelName)] = json;
}
return responseJson;
};


let App, paper, phase, task;

module("Integration: adding an author", {
teardown() {
Ember.run(function() {
TestHelper.teardown();
App.destroy();
});
},

setup() {
App = startApp();
TestHelper.setup(App);

$.mockjax({url: "/api/admin/journals/authorization", status: 204});
$.mockjax({url: "/api/user_flows/authorization", status: 204});
$.mockjax({url: "/api/affiliations", status: 200, responseText: []});

phase = FactoryGuy.make("phase");
task = FactoryGuy.make("plos-authors-task", { phase: phase });
paper = FactoryGuy.make('paper', { phases: [phase], tasks: [task], editable: true });
}
});

test("can add a new author", function(assert) {
Ember.run(function() {
let name = "James";

TestHelper.handleFind(task);
TestHelper.handleCreate("plos-author");

visit(`/papers/${paper.id}/tasks/${task.id}`);
click(".button-primary:contains('Add a New Author')");
fillIn(".author-name input:first", name);
click(".author-contributions input:first");
click(".author-form-buttons .button-secondary:contains('done')");

andThen(function() {
assert.ok(find(`.authors-overlay-item .author-name:contains('${name}')`).length);
});
});
});
87 changes: 0 additions & 87 deletions client/tests/addons/inviting-an-editor-test.coffee

This file was deleted.

96 changes: 96 additions & 0 deletions client/tests/addons/inviting-an-editor-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Ember from "ember";
import { module, test } from "qunit";
import startApp from "tahi/tests/helpers/start-app";
import FactoryGuy from "ember-data-factory-guy";
import TestHelper from "ember-data-factory-guy/factory-guy-test-helper";


TestHelper.mapFind = function(modelName, json) {
let responseJson = {};
if ((/Task/).test(modelName)) {
responseJson["tasks"] = json;
} else {
responseJson[Ember.String.pluralize(modelName)] = json;
}
return responseJson;
};

let App, paper, phase, task, inviteeEmail;

module("Integration: inviting an editor", {
afterEach() {
Ember.run(function() {
TestHelper.teardown();
App.destroy();
});
},

beforeEach() {
App = startApp();
TestHelper.setup(App);

$.mockjax({url: "/api/admin/journals/authorization", status: 204});
$.mockjax({url: "/api/user_flows/authorization", status: 204});
$.mockjax({url: /\/api\/papers\/\d+\/manuscript_manager/, status: 204});
$.mockjax({url: "/api/formats", status: 200, responseText: {
import_formats: [],
export_formats: []
}});

inviteeEmail = window.currentUserData.user.email;
$.mockjax({
url: /\/api\/filtered_users/,
status: 200,
contentType: "application/json",
responseText: {
filtered_users: [{ id: 1, full_name: "Aaron", email: inviteeEmail }]
}
});

phase = FactoryGuy.make("phase");
task = FactoryGuy.make("paper-editor-task", { phase: phase });
paper = FactoryGuy.make('paper', { phases: [phase], tasks: [task] });
TestHelper.handleFind(paper);
}
});

test("displays the email of the invitee", function(assert) {
Ember.run(function() {
TestHelper.handleFind(task);
visit(`/papers/${paper.id}/workflow`);
click("#manuscript-manager .card-content:contains('Assign Editors')");
pickFromSelect2(".overlay-main-work", inviteeEmail);

TestHelper.handleCreate("invitation").andReturn({state: "invited"});

click(".invite-editor-button");

andThen(function() {
assert.ok(find(`.overlay-main-work:contains('${inviteeEmail} has been invited to be Editor on this manuscript.')`));
});
});
});

test("can withdraw the invitation", function(assert) {
Ember.run(function() {
let invitation = FactoryGuy.make("invitation", {email: "[email protected]", state: "invited"});
task.set("invitation", invitation);
TestHelper.handleFind(task);

visit(`/papers/${paper.id}/workflow`);
click("#manuscript-manager .card-content:contains('Assign Editors')");

andThen(function() {
let msgEl = find(".invite-editor-text:contains('[email protected] has been invited to be Editor on this manuscript.')");
assert.ok(msgEl[0] !== undefined, "has pending invitation");

TestHelper.handleDelete("invitation", invitation.id);
click(".button-primary:contains('Withdraw invitation')");

andThen(function() {
assert.equal(task.get('invitation'), null);
});
});

});
});
7 changes: 7 additions & 0 deletions client/tests/factories/invitation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define("invitation", {
default: {
state: "invited",
}
});
14 changes: 14 additions & 0 deletions client/tests/factories/journal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define("journal", {
sequences: {
journalName: function(num) {
return `PLOS Yeti ${num}`;
}
},

default: {
name: FactoryGuy.generate("journalName"),
paperTypes: ["Research"]
}
});
9 changes: 9 additions & 0 deletions client/tests/factories/paper-editor-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define('paper-editor-task', {
default: {
title: 'Assign Editors',
type: 'PaperEditorTask',
completed: false,
}
});
14 changes: 14 additions & 0 deletions client/tests/factories/paper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define("paper", {
default: {
journal: FactoryGuy.belongsTo("journal"),

title: '',
shortTitle: '',
submitted: false,
roles: [],
relatedAtDate: "2014-09-28T13:54:58.028Z",
editable: true,
}
});
8 changes: 8 additions & 0 deletions client/tests/factories/phase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define("phase", {
default: {
position: 1,
name: "Assign Editor",
}
});
11 changes: 11 additions & 0 deletions client/tests/factories/plos-author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define("plos-author", {
default: {
paper: FactoryGuy.belongsTo("paper"),
plos_authors_task: FactoryGuy.belongsTo("plos-authors-task"),

first_name: "Adam",
position: 1,
}
});
9 changes: 9 additions & 0 deletions client/tests/factories/plos-authors-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FactoryGuy from "ember-data-factory-guy";

FactoryGuy.define('plos-authors-task', {
default: {
title: 'Assign Editors',
type: 'PlosAuthorsTask',
completed: false,
}
});

0 comments on commit 7e62de5

Please sign in to comment.