From 7e62de583adefc627833f8340efc463e66e1cb91 Mon Sep 17 00:00:00 2001 From: Pairing Date: Wed, 6 May 2015 19:15:46 -0400 Subject: [PATCH] Uncomment commented out ember integration tests * adding an author * inviting an editor --- client/tests/.jshintrc | 4 +- client/tests/addons/add-author-test.coffee | 58 ----------- client/tests/addons/add-author-test.js | 59 ++++++++++++ .../addons/inviting-an-editor-test.coffee | 87 ----------------- .../tests/addons/inviting-an-editor-test.js | 96 +++++++++++++++++++ client/tests/factories/invitation.js | 7 ++ client/tests/factories/journal.js | 14 +++ client/tests/factories/paper-editor-task.js | 9 ++ client/tests/factories/paper.js | 14 +++ client/tests/factories/phase.js | 8 ++ client/tests/factories/plos-author.js | 11 +++ client/tests/factories/plos-authors-task.js | 9 ++ 12 files changed, 230 insertions(+), 146 deletions(-) delete mode 100644 client/tests/addons/add-author-test.coffee create mode 100644 client/tests/addons/add-author-test.js delete mode 100644 client/tests/addons/inviting-an-editor-test.coffee create mode 100644 client/tests/addons/inviting-an-editor-test.js create mode 100644 client/tests/factories/invitation.js create mode 100644 client/tests/factories/journal.js create mode 100644 client/tests/factories/paper-editor-task.js create mode 100644 client/tests/factories/paper.js create mode 100644 client/tests/factories/phase.js create mode 100644 client/tests/factories/plos-author.js create mode 100644 client/tests/factories/plos-authors-task.js diff --git a/client/tests/.jshintrc b/client/tests/.jshintrc index ea8b88f6246..29f6c4590db 100644 --- a/client/tests/.jshintrc +++ b/client/tests/.jshintrc @@ -21,7 +21,9 @@ "andThen", "currentURL", "currentPath", - "currentRouteName" + "currentRouteName", + "pickFromSelect2", + "pickFromChosenSingle" ], "node": false, "browser": false, diff --git a/client/tests/addons/add-author-test.coffee b/client/tests/addons/add-author-test.coffee deleted file mode 100644 index 43470652b62..00000000000 --- a/client/tests/addons/add-author-test.coffee +++ /dev/null @@ -1,58 +0,0 @@ -`import Ember from "ember";` -`import startApp from "../helpers/start-app";` -`import FactoryGuy from "factory-guy";` -`import { test } from "ember-qunit";` -`import { testMixin as FactoryGuyTestMixin } from "factory-guy";` -`import setupFactories from "../helpers/factories";` - -TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin) - -app = null -paper = null -task = null -testHelper = null - -setupFactories() - -module "Integration: adding an author", - - teardown: -> - Ember.run -> - testHelper.teardown() - app.destroy() - - setup: -> - app = startApp() - testHelper = 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 }) - - $.mockjax - url: "/api/plos_authors" - status: 201 - responseText: { - plos_authors:[ - { - id:4, - first_name:'James', - position:1, - paper_id:paper.id, - plos_authors_task_id:task.id - } - ] - } - -# test "can add a new author", -> -# visit("/papers/#{paper.id}/tasks/#{task.id}") -# click(".button-primary:contains('Add a New Author')") -# fillIn(".author-name input:first", "James") -# click(".author-contributions input:first") -# click(".author-form-buttons .button-secondary:contains('done')") -# andThen -> -# ok(find(".authors-overlay-item .author-name:contains('James')")) diff --git a/client/tests/addons/add-author-test.js b/client/tests/addons/add-author-test.js new file mode 100644 index 00000000000..5d8bb2da45e --- /dev/null +++ b/client/tests/addons/add-author-test.js @@ -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); + }); + }); +}); diff --git a/client/tests/addons/inviting-an-editor-test.coffee b/client/tests/addons/inviting-an-editor-test.coffee deleted file mode 100644 index 3502d4c29d9..00000000000 --- a/client/tests/addons/inviting-an-editor-test.coffee +++ /dev/null @@ -1,87 +0,0 @@ -`import Ember from "ember";` -`import startApp from "../helpers/start-app";` -`import FactoryGuy from "factory-guy";` -`import { test } from "ember-qunit";` -`import { testMixin as FactoryGuyTestMixin } from "factory-guy";` -`import setupFactories from "../helpers/factories";` - -TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin) - -app = null -paper = null -task = null -testHelper = null - -setupFactories() - -module "Integration: inviting an editor", - - teardown: -> - Ember.run -> - testHelper.teardown() - app.destroy() - - setup: -> - app = startApp() - testHelper = TestHelper.setup(app) - - $.mockjax(url: "/api/admin/journals/authorization", status: 204) - $.mockjax(url: "/api/user_flows/authorization", status: 204) - $.mockjax - url: "/api/formats" - status: 200 - responseText: - "export_formats": [{ "format": "docx" }, { "format": "latex" }] - "import_formats": [{ "format": "docx" }, { "format": "odt" }] - $.mockjax - url: /\/api\/papers\/\d+\/manuscript_manager/ - status: 204 - contentType: "application/html" - headers: { 'tahi-authorization-check': true } - responseText: "" - - $.mockjax - url: /\/api\/filtered_users/ - status: 200 - contentType: "application/json" - responseText: - filtered_users: [{ id: 1, full_name: "Aaron", email: "aaron@neo.com" }] - - 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", -> -# $.mockjax -# url: /\/api\/filtered_users/ -# status: 200 -# contentType: "application/json" -# responseText: -# filtered_users: [{ id: 1, full_name: "Aaron", email: "aaron@neo.com" }] -# -# testHelper.handleCreate("invitation") -# -# visit("/papers/#{paper.id}/workflow") -# click("#manuscript-manager .card-content:contains('Assign Editors')") -# pickFromSelect2(".overlay-main-work", "aaron@neo.com") -# click(".invite-editor-button") -# -# andThen -> -# ok(find(".overlay-main-work:contains('aaron@neo.com has been invited to be Editor on this manuscript.')")) -# -# test "can withdraw the invitation", -> -# testHelper.handleFind("paper", paper) -# invitation = FactoryGuy.make("invitation", email: "foo@bar.com") -# Ember.run => -# task.set("invitation", invitation) -# -# visit("/papers/#{paper.id}/workflow") -# click("#manuscript-manager .card-content:contains('Assign Editors')") -# ok(find(".invite-editor-task:contains('foo@bar.com has been invited to be Editor on this manuscript.')"), "has pending invitation") -# -# testHelper.handleDelete("invitation", invitation.id) -# click(".button-primary:contains('Withdraw invitation')") -# -# andThen -> -# equal(task.get('invitation'), null) diff --git a/client/tests/addons/inviting-an-editor-test.js b/client/tests/addons/inviting-an-editor-test.js new file mode 100644 index 00000000000..fd569d92a9b --- /dev/null +++ b/client/tests/addons/inviting-an-editor-test.js @@ -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: "foo@bar.com", 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('foo@bar.com 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); + }); + }); + + }); +}); diff --git a/client/tests/factories/invitation.js b/client/tests/factories/invitation.js new file mode 100644 index 00000000000..4aa6706601e --- /dev/null +++ b/client/tests/factories/invitation.js @@ -0,0 +1,7 @@ +import FactoryGuy from "ember-data-factory-guy"; + +FactoryGuy.define("invitation", { + default: { + state: "invited", + } +}); diff --git a/client/tests/factories/journal.js b/client/tests/factories/journal.js new file mode 100644 index 00000000000..15cd3a5f23a --- /dev/null +++ b/client/tests/factories/journal.js @@ -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"] + } +}); diff --git a/client/tests/factories/paper-editor-task.js b/client/tests/factories/paper-editor-task.js new file mode 100644 index 00000000000..314f7598742 --- /dev/null +++ b/client/tests/factories/paper-editor-task.js @@ -0,0 +1,9 @@ +import FactoryGuy from "ember-data-factory-guy"; + +FactoryGuy.define('paper-editor-task', { + default: { + title: 'Assign Editors', + type: 'PaperEditorTask', + completed: false, + } +}); diff --git a/client/tests/factories/paper.js b/client/tests/factories/paper.js new file mode 100644 index 00000000000..01464250185 --- /dev/null +++ b/client/tests/factories/paper.js @@ -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, + } +}); diff --git a/client/tests/factories/phase.js b/client/tests/factories/phase.js new file mode 100644 index 00000000000..ef1a25f9ae7 --- /dev/null +++ b/client/tests/factories/phase.js @@ -0,0 +1,8 @@ +import FactoryGuy from "ember-data-factory-guy"; + +FactoryGuy.define("phase", { + default: { + position: 1, + name: "Assign Editor", + } +}); diff --git a/client/tests/factories/plos-author.js b/client/tests/factories/plos-author.js new file mode 100644 index 00000000000..347f4efb6fc --- /dev/null +++ b/client/tests/factories/plos-author.js @@ -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, + } +}); diff --git a/client/tests/factories/plos-authors-task.js b/client/tests/factories/plos-authors-task.js new file mode 100644 index 00000000000..21abbf746f8 --- /dev/null +++ b/client/tests/factories/plos-authors-task.js @@ -0,0 +1,9 @@ +import FactoryGuy from "ember-data-factory-guy"; + +FactoryGuy.define('plos-authors-task', { + default: { + title: 'Assign Editors', + type: 'PlosAuthorsTask', + completed: false, + } +});