Skip to content

Commit

Permalink
Create post_test.rb to test posting at /post (#5605)
Browse files Browse the repository at this point in the history
* Create post_test.rb

*     UserSession.create(users(:bob)) # log in

* Update post_test.rb

* Update rich.html.erb

* Update post_test.rb

* Update post_test.rb

* Trying login via modal

* add login-button id

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* Update post_test.rb

* /images/pl.png in scraped image

* /images/pl.png in scraped image

* Update post_test.rb

* add assert_page_reloads

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb
  • Loading branch information
jywarren committed May 2, 2019
1 parent 66aa809 commit e190eae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/views/editor/rich.html.erb
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
2 changes: 1 addition & 1 deletion app/views/user_sessions/_form.html.erb
Expand Up @@ -51,7 +51,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
56 changes: 56 additions & 0 deletions test/system/post_test.rb
@@ -0,0 +1,56 @@
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 '/'

click_on 'Login'
fill_in("username-login", with: "Bob")
fill_in("password-signup", with: "secretive")
click_on "Log in"

visit '/post'

fill_in("Title", with: "My new post")

el = find(".wk-wysiwyg") # rich text input
el.set("All about this interesting stuff")

assert_page_reloads do

find('.ple-publish').click
assert_selector('h1', text: "My new post")
assert_selector('#content', text: "All about this interesting stuff")
assert_selector('.alert-success', text: \nSuccess! Thank you for contributing open research, and thanks for your patience while your post is approved by community moderators and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so.")

end

end

# Utility methods:

def assert_page_reloads(message = "page should reload")
page.evaluate_script "document.body.classList.add('not-reloaded')"
yield
if has_selector? "body.not-reloaded"
assert false, message
end
end

def assert_page_does_not_reload(message = "page should not reload")
page.evaluate_script "document.body.classList.add('not-reloaded')"
yield
unless has_selector? "body.not-reloaded"
assert false, message
end
page.evaluate_script "document.body.classList.remove('not-reloaded')"
end

end

0 comments on commit e190eae

Please sign in to comment.