Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaphysiker committed Sep 20, 2021
1 parent d2ef052 commit 74a191d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 106 deletions.
20 changes: 11 additions & 9 deletions app/views/submissions/_buttons.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<div class="col-12">
<%#= mail_to "", "send to external referee", subject: "Review for Dialectica", body: "Dear Reviewer \n\n There is a new submission on Dialectica called \"#{submission.title}\". \n\n Please take a look, as it is in your area of expertise! \n\n View it here: #{submission_url(submission)} \n\n Kind regards \n\n #{current_user.name unless current_user.blank?}", class: "btn btn-light border my-2" %>
<% if is_user_reviewer?(current_user) %>
<h5>reviewer-tools<h5>
<% if current_user.submissions.where(id: submission.id).empty? %>
<% if !submission.users.empty? %>
<div class="d-inline-block">
Expand All @@ -18,15 +19,15 @@
</div>
<% end %>

<%= link_to "fish this", submissions_add_user_to_submission_path(current_user.id, submission.id), method: :post, class: "btn btn-light border my-2" %>
<%= link_to "fish this", submissions_add_user_to_submission_path(current_user.id, submission.id), method: :post, class: "btn btn-light border my-2", data: { cy: "submissions_add_user_to_submission" } %>
<%#= link_to "I know someone who could review it", submissions_add_user_to_submission_path(current_user.id, submission.id), method: :post, class: "btn btn-success my-2" %>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#suggestionModal">
suggest to internal reviewer
</button>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#uploadfileModal">
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#uploadfileModal" data-cy="upload_file_button">
upload file
</button>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#addCommentModal">
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#addCommentModal" data-cy="add_comment_to_submission_button">
add comment
</button>
<% else %>
Expand All @@ -38,14 +39,14 @@
<% end %>
</div>
<% end %>
<%= link_to "leave it", submissions_remove_user_from_submission_path(current_user.id, submission.id), method: :post, class: "btn btn-light border my-2" %>
<%= link_to "leave it", submissions_remove_user_from_submission_path(current_user.id, submission.id), method: :post, class: "btn btn-light border my-2", data: { cy: "submissions_remove_user_to_submission" } %>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#suggestionModal">
suggest to internal reviewer
</button>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#uploadfileModal">
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#uploadfileModal" data-cy="upload_file_button">
upload file
</button>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#addCommentModal">
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#addCommentModal" data-cy="add_comment_to_submission_button">
add comment
</button>
<button type="button" class="btn btn-light border" data-toggle="modal" data-target="#send_to_external_refereeModal">
Expand Down Expand Up @@ -74,6 +75,7 @@

<% if is_user_editor?(current_user) && submission.dead == "false" %>
<hr />
<h5>editor-tools<h5>
<%= link_to "accept", accept_submission_path(submission.id), method: :post, class: "btn btn-light border my-2" %>
<%= link_to "reject", reject_submission_path(submission.id), method: :post, class: "btn btn-light border my-2" %>
<%= link_to "resurrect", resurrect_submission_path(submission.id), method: :post, class: "btn btn-light border my-2" %>
Expand Down Expand Up @@ -125,10 +127,10 @@
<%#= file_field_tag :file, class: "btn btn-secondary" %>
<%#= hidden_field_tag :submission_id, submission.id %>
<%#= submit_tag "Submit", class: "btn btn-primary", id: "actual_bibtex_enter_button" %>
<%= file_field_tag :attachments %>
<%= file_field_tag :attachments, id: "upload_file_field_tag" %>
<br />
<br />
<%= button_tag "upload file", class: "btn btn-light border" %>
<%= button_tag "upload file", class: "btn btn-light border", data: {cy: "submit_upload_file_button"} %>

<% end %>
</div>
Expand All @@ -155,7 +157,7 @@
<%= simple_form_for :comment, url: add_comment_to_submission_path(submission) do |f| %>
<%#= f.input :comment, as: :text %>
<%= f.text_area :comment, :class => "tinymce", :rows => 40, :cols => 120 %>
<%= f.submit "add comment", class: "btn btn-light border my-2" %>
<%= f.submit "add comment", class: "btn btn-light border my-2", data: {cy: "submit_comment_to_submission_button"} %>
<% end %>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/_card.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% random_id = SecureRandom.random_number(10000000) %>
<div id="submission-<%= submission.id %> submission-<%= submission.id %>-random-id-<%= random_id %>" class="card h-100 mb-3 <%= submission.submission_urgency %> <%= submission.get_frame_status_color(current_user) %> <%= "animate__animated animate__shakeX animate__slow animate__repeat-2" if submission.suggested_to_me?(current_user) %> btn btn-light pool-select-button" style="" value="<%=submission.id%>">
<div id="submission-<%= submission.id %> submission-<%= submission.id %>-random-id-<%= random_id %>" class="card h-100 mb-3 <%= submission.submission_urgency %> <%= submission.get_frame_status_color(current_user) %> <%= "animate__animated animate__shakeX animate__slow animate__repeat-2" if submission.suggested_to_me?(current_user) %> btn btn-light pool-select-button" style="" value="<%=submission.id%>" data-cy="submission_card">
<div class="card-body">
<p class="card-text">
<strong>#<%= submission.id %> - <%= l submission.created_at, format: :usa %></strong>
Expand Down
27 changes: 27 additions & 0 deletions cypress/integration/archive/maybe-useful.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
before(function () {
//creates 20 submissions
cy.fixture('submissions.json').then(submissions => {
submissions.forEach(submission => {
//start

cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
cy.get('#submission_title').type(submission.title)
cy.get('#submission_email').type(submission.email)
cy.get('#submission_firstname').type(submission.firstname)
cy.get('#submission_lastname').type(submission.lastname)
cy.get('#submission_other_authors').type(submission.other_authors)
cy.get('#submission_country').then($country => {$country.val(submission.country)})
cy.get('#submission_file').attachFile('sample.pdf');
cy.setTinyMceContent('submission_comment', submission.comment);
cy.root().submit();
});
cy.contains("submission was successfully created.");

//end
});
});


})
142 changes: 46 additions & 96 deletions cypress/integration/submission-reviewer-tools.spec.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,60 @@
describe('Submission Reviewer Tools', () => {

before(function () {
//creates 20 submissions
cy.fixture('submissions.json').then(submissions => {
submissions.forEach(submission => {
//start

cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
cy.get('#submission_title').type(submission.title)
cy.get('#submission_email').type(submission.email)
cy.get('#submission_firstname').type(submission.firstname)
cy.get('#submission_lastname').type(submission.lastname)
cy.get('#submission_other_authors').type(submission.other_authors)
cy.get('#submission_country').then($country => {$country.val(submission.country)})
cy.get('#submission_file').attachFile('sample.pdf');
cy.setTinyMceContent('submission_comment', submission.comment);
cy.root().submit();
});
cy.contains("submission was successfully created.");

//end
});
});


})
beforeEach(function () {
cy.login_as_reviewer();
});

afterEach(function(){
//cy.destroy_user_account()
//cy.login_as_reviewer();
})

it('submits a submission, expects the reviewer and editor to see it and editor to delete it.', () => {
cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
cy.fixture('submission.json').then((submission) => {
cy.get('#submission_title').type(submission.title)
cy.get('#submission_email').type(submission.email)
cy.get('#submission_firstname').type(submission.firstname)
cy.get('#submission_lastname').type(submission.lastname)
cy.get('#submission_other_authors').type(submission.other_authors)
cy.get('#submission_country').then($country => {$country.val(submission.country)})
cy.get('#submission_file').attachFile('sample.pdf');
//cy.get('#submission_comment').type(submission.comment)
cy.setTinyMceContent('submission_comment', submission.comment);

})
cy.root().submit();
});

cy.contains("submission was successfully created.");

//reviewer
cy.login_as_reviewer();
cy.visit('http://localhost:3000/submission_pool')

cy.fixture('submission.json').then((submission) => {
cy.contains(submission.title).click();
cy.contains(submission.title)
cy.contains(submission.comment)
});
cy.logout();

//editor
cy.login_as_editor();
cy.visit('http://localhost:3000/submission_pool')

cy.fixture('submission.json').then((submission) => {
cy.contains(submission.title).click();
cy.contains(submission.title)
cy.contains(submission.comment)
//deletes it
cy.contains("delete this submission").click();
cy.contains("submission was successfully deleted.");
});

cy.logout();
cy.logout();
});

it("adds submission to the current user, shows up in the user's pool and removes it again.", () => {
const uuid = () => Cypress._.random(0, 1e6)
const id = uuid()
const testname = `testname${id}`
cy.create_submission(testname)

cy.get('[data-cy=submissions_add_user_to_submission]').first().click(); //fish this
cy.contains("signed up as internal referee");

cy.visit('http://localhost:3000/submission_pool');

cy.contains("submissions to be reviewed by me").first().click();
cy.contains(testname).first().click();

cy.get('[data-cy=submissions_remove_user_to_submission]').first().click(); //fish this
cy.contains("quit as internal referee ");
});

it('submits an empty submission and expects error messages', () => {
cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
it("adds a comment to submission.", () => {
const comment_text = "This is my comment on this submission";
const uuid = () => Cypress._.random(0, 1e6)
const id = uuid()
const testname = `testname${id}`
cy.create_submission(testname);

cy.root().submit();
})
cy.get('[data-cy=add_comment_to_submission_button]').first().click();
cy.setTinyMceContent('comment_comment', comment_text);
cy.get('[data-cy=submit_comment_to_submission_button]').first().click();

cy.contains("Title can't be blank");
cy.contains("Firstname can't be blank");
cy.contains("Lastname can't be blank");
cy.contains("Email can't be blank");
cy.contains("File can't be blank");
cy.contains(comment_text);
//cy.get('[data-cy=]').first().click();
});

it('submits a png instead of a pdf and expects error messages', () => {
cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
cy.get('#submission_file').attachFile('sample.png');
cy.root().submit();
});
cy.contains("File is not a PDF");
it("uploads a file to a submission.", () => {
const uuid = () => Cypress._.random(0, 1e6)
const id = uuid()
const testname = `testname${id}`
cy.create_submission(testname);

cy.get('[data-cy=upload_file_button]').first().click();
cy.get('#upload_file_field_tag').attachFile('sample.pdf');
cy.get('[data-cy=submit_upload_file_button]').first().click();


cy.contains("uploaded a file: sample.pdf");
//cy.get('[data-cy=]').first().click();
});


});
21 changes: 21 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ Cypress.Commands.add('login_as_editor', () => {
cy.contains('Signed in successfully.')
})

Cypress.Commands.add('create_submission', (title) => {
cy.visit('http://localhost:3000/submissions/new');
cy.contains("new submission to dialectica");
cy.get('[data-cy=new_submission_form]').within(($form) => {
cy.fixture('submission.json').then((submission) => {
cy.get('#submission_title').type(title)
cy.get('#submission_email').type(submission.email)
cy.get('#submission_firstname').type(submission.firstname)
cy.get('#submission_lastname').type(submission.lastname)
cy.get('#submission_other_authors').type(submission.other_authors)
cy.get('#submission_country').then($country => {$country.val(submission.country)})
cy.get('#submission_file').attachFile('sample.pdf');
//cy.get('#submission_comment').type(submission.comment)
cy.setTinyMceContent('submission_comment', submission.comment);

})
cy.root().submit();
});
cy.contains("submission was successfully created.");
})


Cypress.Commands.add('logout', () => {
cy.get("[data-cy=logout]").click();
Expand Down

0 comments on commit 74a191d

Please sign in to comment.