Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create post_test.rb to test posting at /post #5605

Merged
merged 22 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<input
class="form-control input-lg"
type="text"
id="title-input"
placeholder="Title"
value="<%= if @node then @node.title else params[:title] end %>"
/>
Expand Down Expand Up @@ -425,4 +426,4 @@
}
console.log("Draft:", editor.data.draft);
}
</script>
</script>
2 changes: 1 addition & 1 deletion app/views/user_sessions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<input type="hidden" name="hash_params" value="" />

<div class="input-group-inline">
<button class="btn btn-primary btn-lg" type="submit" tabindex="3"><%= t('user_sessions.new.log_in') %></button>
<button id="login-button" class="btn btn-primary btn-lg" type="submit" tabindex="3"><%= t('user_sessions.new.log_in') %></button>

<div class="form-check-inline">
<label class="form-check-label" style="margin-left:12px;">
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ scraped_image:
nid: 27
uid: 2
title: Post test review 4
body: "Lots of text and then an image: ![image preview](/url/to/image.png)"
body: "Lots of text and then an image: ![image preview](/images/pl.png)"
timestamp: <%= DateTime.new(2018,8,20).to_i %>

search_trawl:
Expand Down Expand Up @@ -340,4 +340,4 @@ purple_air_with_hyphen:
title: "This is purple-air with hyphen"
body: "Is Purple-air searched with hyphens or without hyphens?"
timestamp: <%= DateTime.new(2019,2,20).to_i %>


32 changes: 32 additions & 0 deletions test/system/post_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "application_system_test_case"
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test

class PostTest < ApplicationSystemTestCase

def setup
activate_authlogic
end

test 'posting from the editor' do
visit '/'

This comment was marked as resolved.


click_on 'Login'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Here we are visiting login but on line 29 we get the message
    User was successfully created. Can you please explain this code snippet?
  2. We have same integration test here
    test 'redirect to login page if user is not logged in and then redirect back to desired page after login' do
    get '/post?tags=question:question&template=question'
    follow_redirect!
    assert_equal '/login', path
    post '/user_sessions', params: { user_session: { username: users(:jeff).username, password: 'secretive' } }
    follow_redirect!
    assert_equal '/post?tags=question:question&template=question', request.fullpath
    end
    so one of these will become redundant.
  3. In theory of Software Testing at my university, we are taught that System tests are written to validate the non-functional parameters like server load time, access time between end nodes etc. Are we also going to do those amazing stuff later on?
  4. I am having difficulty in installing the prerequisites for System tests. Can you please tell a good reference? I searched a lot but none worked during past one week.
  5. How can we use Recaptcha or Spamaway in system test? Any idea. You may require them in this pr too in case we want assert_selector('#notice', 'User was successfully created.').

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on redundant, but I'm not sure how to create a session we can use to test logged-in stuff. I tried doing as we do in other tests, with UserSession.new() or whatever, but I think it literally isn't connecting that session we make in the back-end to an actual logged in session that Capybara can interact with on headless chrome! So, i'm trying to log in manually here... how else ought we to log in? Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we also going to do those amazing stuff later on?

My biggest interests in system tests are:

  1. testing the interaction of our complex JS with the Rails app, end-to-end, because things keep breaking here
  2. seeing screenshots!

But yeah... lots of other possibilities.

fill_in("username-login", with: "Bob")
fill_in("password-signup", with: "secretive")
click_on "Log in"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are logging in first and then going to '/post. I think it should be go to the '/post being not logged in then the person is redirected to the '/login' page then person logs in.....

What do you suggest Jeff?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, good idea... let me try...


visit '/post'

fill_in("Title", with: "My new post")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill_in(x, with: Y)
I can't get what is x? X is supposed to be class or id or what? I cannot find id with Title.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X is ... i can't remember the term... maybe a locator? It's a Capybara term. I believe it can take the id, the name, or... not sure, and there's an order to it too: https://github.com/teamcapybara/capybara#the-dsl

fill_in("text-input", with: "All about this interesting stuff")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we need a better way to select the right field. Maybe this is because we're in wysiwyg and not markdown mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


find('.ple-publish').click

assert_response :redirect
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, here... NoMethodError: NoMethodError: undefined method response_code' for nil:NilClass`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 26 is not right, we shouldn't have to click twice. Not sure why this isn't working...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. i used Capycorder to try this but it didn't get everything:

it 'SHOULDDOSOMETHING' do
  visit('/post')
  page.should have_selector('.wk-wysiwyg')
  page.should have_selector('html  > body > .container > .row > .pl-editor > .ple-content > .ple-module-title.ple-module.row > .ple-module-content.col-lg-9:nth-child(1) > .form-control.input-lg')
  fill_in('undefined', :with => 'title title')
  page.should have_selector('.ple-publish.btn.btn-lg.btn-primary.float-right')
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in fact on stable, posting is not working, so maybe this is just because the functionality is broken?

Copy link
Member Author

@jywarren jywarren May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see a 500 on https://stable.publiclab.org/post,

title: testing
body: testing
authenticity_token: yYh7o/22lYcj6XJ0dJViugBbFW72WK790hzjEJAFI52tUAZEijrbnzc3+d1ZZaj+LgBwIoz2PK6pwJslzEWgRw==
draft: false
tags: 
has_main_image: 
main_image: 
node_images: 
image[photo]: 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 500 possibly due to email not sending? I thought we'd resolved this but who knows... hmm. We may need to try to pull the logs here since this is not failing in tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, think I resolved the 500 on stable... testing....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's resolved on stable. Still not here, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I realized that it's not doing a real redirect... it's JS sending us to a new page. So, I'm using a snippet from https://stackoverflow.com/questions/20243208/how-can-i-test-in-capybara-that-a-page-has-not-reloaded-javascript-onclick-in to show that assert_page_reloads and then just going forward with the next steps!

follow_redirect!

assert_selector('h1', text: 'My new post')
assert_selector('#notice', 'User was successfully created.')
end

end
2 changes: 1 addition & 1 deletion test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def setup

test 'should show scraped image' do
node = nodes(:scraped_image)
assert_equal '/url/to/image.png', node.scraped_image
assert_equal '/images/pl.png', node.scraped_image
end

test 'contribution graph making' do
Expand Down