Commit e1491465 authored by Vinnie Okada's avatar Vinnie Okada

Refactor Markdown preview tests

Create a new shared module for common issue/merge request behavior,
use `expect` syntax instead of `should`, and avoid `visible: false` in
the `have_css` matcher.
parent cd3eabd7
...@@ -193,21 +193,21 @@ Feature: Project Merge Requests ...@@ -193,21 +193,21 @@ Feature: Project Merge Requests
@javascript @javascript
Scenario: I can't preview without text Scenario: I can't preview without text
Given I visit merge request page "Bug NS-04" Given I visit merge request page "Bug NS-04"
And I click link "Edit" And I click link "Edit" for the merge request
And I haven't written any description text And I haven't written any description text
Then I should not see the Markdown preview button Then I should not see the Markdown preview button
@javascript @javascript
Scenario: I can preview with text Scenario: I can preview with text
Given I visit merge request page "Bug NS-04" Given I visit merge request page "Bug NS-04"
And I click link "Edit" And I click link "Edit" for the merge request
And I write a description like "Nice" And I write a description like "Nice"
Then I should see the Markdown preview button Then I should see the Markdown preview button
@javascript @javascript
Scenario: I preview a merge request description Scenario: I preview a merge request description
Given I visit merge request page "Bug NS-04" Given I visit merge request page "Bug NS-04"
And I click link "Edit" And I click link "Edit" for the merge request
And I preview a description text like "Bug fixed :smile:" And I preview a description text like "Bug fixed :smile:"
Then I should see the Markdown preview Then I should see the Markdown preview
And I should not see the Markdown text field And I should not see the Markdown text field
...@@ -215,6 +215,6 @@ Feature: Project Merge Requests ...@@ -215,6 +215,6 @@ Feature: Project Merge Requests
@javascript @javascript
Scenario: I can edit after preview Scenario: I can edit after preview
Given I visit merge request page "Bug NS-04" Given I visit merge request page "Bug NS-04"
And I click link "Edit" And I click link "Edit" for the merge request
And I preview a description text like "Bug fixed :smile:" And I preview a description text like "Bug fixed :smile:"
Then I should see the Markdown edit button Then I should see the Markdown edit button
class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
include SharedIssuable
include SharedProject include SharedProject
include SharedNote include SharedNote
include SharedPaths include SharedPaths
...@@ -10,10 +11,6 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -10,10 +11,6 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
click_link "New Merge Request" click_link "New Merge Request"
end end
step 'I click link "Edit"' do
click_link 'Edit'
end
step 'I click link "Bug NS-04"' do step 'I click link "Bug NS-04"' do
click_link "Bug NS-04" click_link "Bug NS-04"
end end
......
...@@ -32,7 +32,7 @@ module SharedDiffNote ...@@ -32,7 +32,7 @@ module SharedDiffNote
click_diff_line(sample_commit.line_code) click_diff_line(sample_commit.line_code)
within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do
fill_in "note[note]", with: "Should fix it :smile:" fill_in "note[note]", with: "Should fix it :smile:"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
end end
end end
...@@ -41,7 +41,7 @@ module SharedDiffNote ...@@ -41,7 +41,7 @@ module SharedDiffNote
within("#{diff_file_selector} form[rel$='#{sample_commit.del_line_code}']") do within("#{diff_file_selector} form[rel$='#{sample_commit.del_line_code}']") do
fill_in "note[note]", with: "DRY this up" fill_in "note[note]", with: "DRY this up"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
end end
end end
...@@ -73,7 +73,7 @@ module SharedDiffNote ...@@ -73,7 +73,7 @@ module SharedDiffNote
step 'I should not see the diff comment preview button' do step 'I should not see the diff comment preview button' do
within(diff_file_selector) do within(diff_file_selector) do
page.should have_css('.js-md-preview-button', visible: false) expect(page).not_to have_css('.js-md-preview-button')
end end
end end
...@@ -131,27 +131,27 @@ module SharedDiffNote ...@@ -131,27 +131,27 @@ module SharedDiffNote
step 'I should see the diff comment preview' do step 'I should see the diff comment preview' do
within("#{diff_file_selector} form") do within("#{diff_file_selector} form") do
page.should have_css('.js-md-preview', visible: false) expect(page).to have_css('.js-md-preview')
end end
end end
step 'I should see the diff comment edit button' do step 'I should see the diff comment edit button' do
within(diff_file_selector) do within(diff_file_selector) do
page.should have_css('.js-md-write-button', visible: true) expect(page).to have_css('.js-md-write-button')
end end
end end
step 'I should see the diff comment preview button' do step 'I should see the diff comment preview button' do
within(diff_file_selector) do within(diff_file_selector) do
page.should have_css('.js-md-preview-button', visible: true) expect(page).to have_css('.js-md-preview-button')
end end
end end
step 'I should see two separate previews' do step 'I should see two separate previews' do
within(diff_file_selector) do within(diff_file_selector) do
page.should have_css('.js-md-preview', visible: true, count: 2) expect(page).to have_css('.js-md-preview', count: 2)
page.should have_content("Should fix it") expect(page).to have_content("Should fix it")
page.should have_content("DRY this up") expect(page).to have_content("DRY this up")
end end
end end
......
module SharedIssuable
include Spinach::DSL
def edit_issuable
find('.issue-btn-group').click_link 'Edit'
end
step 'I click link "Edit" for the merge request' do
edit_issuable
end
step 'I click link "Edit" for the issue' do
edit_issuable
end
end
...@@ -56,27 +56,27 @@ EOT ...@@ -56,27 +56,27 @@ EOT
end end
step 'I should not see the Markdown preview' do step 'I should not see the Markdown preview' do
find('.gfm-form').should have_css('.js-md-preview', visible: false) expect(find('.gfm-form')).not_to have_css('.js-md-preview')
end end
step 'I should not see the Markdown preview button' do step 'I should not see the Markdown preview button' do
find('.gfm-form').should have_css('.js-md-preview-button', visible: false) expect(find('.gfm-form')).not_to have_css('.js-md-preview-button')
end end
step 'I should not see the Markdown text field' do step 'I should not see the Markdown text field' do
find('.gfm-form').should have_css('textarea', visible: false) expect(find('.gfm-form')).not_to have_css('textarea')
end end
step 'I should see the Markdown edit button' do step 'I should see the Markdown edit button' do
find('.gfm-form').should have_css('.js-md-write-button', visible: true) expect(find('.gfm-form')).to have_css('.js-md-write-button')
end end
step 'I should see the Markdown preview' do step 'I should see the Markdown preview' do
find('.gfm-form').should have_css('.js-md-preview', visible: true) expect(find('.gfm-form')).to have_css('.js-md-preview')
end end
step 'I should see the Markdown preview button' do step 'I should see the Markdown preview button' do
find('.gfm-form').should have_css('.js-md-preview-button', visible: true) expect(find('.gfm-form')).to have_css('.js-md-preview-button')
end end
step 'I write a description like "Nice"' do step 'I write a description like "Nice"' do
...@@ -86,7 +86,7 @@ EOT ...@@ -86,7 +86,7 @@ EOT
step 'I preview a description text like "Bug fixed :smile:"' do step 'I preview a description text like "Bug fixed :smile:"' do
within('.gfm-form') do within('.gfm-form') do
fill_in 'Description', with: 'Bug fixed :smile:' fill_in 'Description', with: 'Bug fixed :smile:'
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click()
end end
end end
......
...@@ -23,7 +23,7 @@ module SharedNote ...@@ -23,7 +23,7 @@ module SharedNote
step 'I preview a comment text like "Bug fixed :smile:"' do step 'I preview a comment text like "Bug fixed :smile:"' do
within(".js-main-target-form") do within(".js-main-target-form") do
fill_in "note[note]", with: "Bug fixed :smile:" fill_in "note[note]", with: "Bug fixed :smile:"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
end end
end end
...@@ -51,13 +51,13 @@ module SharedNote ...@@ -51,13 +51,13 @@ module SharedNote
step 'I should not see the comment preview' do step 'I should not see the comment preview' do
within(".js-main-target-form") do within(".js-main-target-form") do
page.should have_css('.js-md-preview', visible: false) expect(page).not_to have_css('.js-md-preview')
end end
end end
step 'I should not see the comment preview button' do step 'I should not see the comment preview button' do
within(".js-main-target-form") do within(".js-main-target-form") do
page.should have_css('.js-md-preview-button', visible: false) expect(page).not_to have_css('.js-md-preview-button')
end end
end end
...@@ -81,19 +81,19 @@ module SharedNote ...@@ -81,19 +81,19 @@ module SharedNote
step 'I should see the comment edit button' do step 'I should see the comment edit button' do
within(".js-main-target-form") do within(".js-main-target-form") do
page.should have_css('.js-md-write-button', visible: true) expect(page).to have_css('.js-md-write-button')
end end
end end
step 'I should see the comment preview' do step 'I should see the comment preview' do
within(".js-main-target-form") do within(".js-main-target-form") do
page.should have_css('.js-md-preview', visible: true) expect(page).to have_css('.js-md-preview')
end end
end end
step 'I should see the comment preview button' do step 'I should see the comment preview button' do
within(".js-main-target-form") do within(".js-main-target-form") do
page.should have_css('.js-md-preview-button', visible: true) expect(page).to have_css('.js-md-preview-button')
end end
end end
......
...@@ -19,8 +19,10 @@ describe 'Comments' do ...@@ -19,8 +19,10 @@ describe 'Comments' do
it 'should be valid' do it 'should be valid' do
should have_css(".js-main-target-form", visible: true, count: 1) should have_css(".js-main-target-form", visible: true, count: 1)
find(".js-main-target-form input[type=submit]").value.should == "Add Comment" find(".js-main-target-form input[type=submit]").value.should == "Add Comment"
within(".js-main-target-form") { should_not have_link("Cancel") } within('.js-main-target-form') do
within('.js-main-target-form') { should have_css('.js-md-preview-button', visible: false) } expect(page).not_to have_link('Cancel')
expect(page).not_to have_css('.js-md-preview-button', visible: true)
end
end end
describe "with text" do describe "with text" do
...@@ -31,8 +33,10 @@ describe 'Comments' do ...@@ -31,8 +33,10 @@ describe 'Comments' do
end end
it 'should have enable submit button and preview button' do it 'should have enable submit button and preview button' do
within(".js-main-target-form") { should_not have_css(".js-comment-button[disabled]") } within(".js-main-target-form") do
within('.js-main-target-form') { should have_css('.js-md-preview-button', visible: true) } expect(page).not_to have_css(".js-comment-button[disabled]")
expect(page).to have_css('.js-md-preview-button')
end
end end
end end
end end
...@@ -41,15 +45,17 @@ describe 'Comments' do ...@@ -41,15 +45,17 @@ describe 'Comments' do
before do before do
within(".js-main-target-form") do within(".js-main-target-form") do
fill_in "note[note]", with: "This is awsome!" fill_in "note[note]", with: "This is awsome!"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
click_button "Add Comment" click_button "Add Comment"
end end
end end
it 'should be added and form reset' do it 'should be added and form reset' do
should have_content("This is awsome!") should have_content("This is awsome!")
within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") } within(".js-main-target-form") do
within('.js-main-target-form') { should have_css('.js-md-preview', visible: false) } expect(page).to have_no_field("note[note]", with: "This is awesome!")
expect(page).not_to have_css('.js-md-preview', visible: true)
end
within(".js-main-target-form") { should have_css(".js-note-text", visible: true) } within(".js-main-target-form") { should have_css(".js-note-text", visible: true) }
end end
end end
...@@ -172,11 +178,11 @@ describe 'Comments' do ...@@ -172,11 +178,11 @@ describe 'Comments' do
# add two separate texts and trigger previews on both # add two separate texts and trigger previews on both
within("tr[id='#{line_code}'] + .js-temp-notes-holder") do within("tr[id='#{line_code}'] + .js-temp-notes-holder") do
fill_in "note[note]", with: "One comment on line 7" fill_in "note[note]", with: "One comment on line 7"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
end end
within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
fill_in "note[note]", with: "Another comment on line 10" fill_in "note[note]", with: "Another comment on line 10"
find('.js-md-preview-button').trigger('click') find('.js-md-preview-button').click
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment