Skip to content

Commit

Permalink
REFACTOR: post_test.rb [Travis optimization] (publiclab#7275)
Browse files Browse the repository at this point in the history
The most important improvement is the removal of assert_page_reloads statement.
This block of code never executed and just delayed Travis for ~1min every build.

The second improvement is the addition of the "setup" function.
Instead of writing login logic in every test, now before every test the
"setup" function will run and log in the user.

Part of publiclab#7272
  • Loading branch information
VladimirMikulic authored and NitinBhasneia committed Feb 5, 2020
1 parent d779c8d commit 3466be4
Showing 1 changed file with 11 additions and 41 deletions.
52 changes: 11 additions & 41 deletions test/system/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,35 @@ class PostTest < ApplicationSystemTestCase
include ActiveJob::TestHelper
Capybara.default_max_wait_time = 60

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

click_on 'Login'
fill_in("username-login", with: "Bob")
find(".nav-link.loginToggle").click()
fill_in("username-login", with: "jeff")
fill_in("password-signup", with: "secretive")
click_on "Log in"

find(".login-modal-form #login-button").click()
end

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

fill_in("title-input", 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
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: \nResearch note published. Get the word out on the discussion lists!")
end

test 'adding tags to the post' do
visit '/wiki/wiki-page-path/comments'

find('a[data-target="#loginModal"]', text: 'Login').click()

fill_in 'user_session[username]', with: 'jeff'
fill_in 'user_session[password]', with: 'secretive'

find(".login-modal-form #login-button").click()

find('a#tags-open').click()

find('.tag-input').set('nature').native.send_keys(:return)
Expand All @@ -53,13 +46,6 @@ class PostTest < ApplicationSystemTestCase
test 'removing tags from the post' do
visit '/wiki/wiki-page-path/comments'

find('a[data-target="#loginModal"]', text: 'Login').click()

fill_in 'user_session[username]', with: 'jeff'
fill_in 'user_session[password]', with: 'secretive'

find(".login-modal-form #login-button").click()

find('a#tags-open').click()

find('.tag-input').set('nature').native.send_keys(:return)
Expand All @@ -75,13 +61,6 @@ class PostTest < ApplicationSystemTestCase
test 'like button on the post' do
visit '/wiki/wiki-page-path/comments'

find('a[data-target="#loginModal"]', text: 'Login').click()

fill_in 'user_session[username]', with: 'jeff'
fill_in 'user_session[password]', with: 'secretive'

click_on 'Log in'

like_button = find('.btn-like').click();

# Make sure that star is toggled
Expand Down Expand Up @@ -109,11 +88,7 @@ def assert_page_does_not_reload(message = "page should not reload")

test "edit wiki" do
visit '/wiki/wiki-page-path/'
click_on "Login"

fill_in 'user_session[username]', with: 'jeff'
fill_in 'user_session[password]', with: 'secretive'
click_on "Log in"
find('a.btn-circle:first-of-type .fa-pencil').click()
fill_in("body", with: "Test for editing wikis!")

Expand All @@ -131,11 +106,6 @@ def assert_page_does_not_reload(message = "page should not reload")
Capybara.ignore_hidden_elements = false
visit '/wiki/new'

find('.login-page-form #username-login').set('jeff')
find('.login-page-form #password-signup').set('secretive')

find('.login-page-form #login-button').click()

# Upload the image
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png")

Expand Down

0 comments on commit 3466be4

Please sign in to comment.