2017-04-06 15:00:18 +00:00
|
|
|
shared_examples 'discussion comments' do |resource_name|
|
|
|
|
let(:form_selector) { '.js-main-target-form' }
|
|
|
|
let(:dropdown_selector) { "#{form_selector} .comment-type-dropdown" }
|
|
|
|
let(:toggle_selector) { "#{dropdown_selector} .dropdown-toggle" }
|
|
|
|
let(:menu_selector) { "#{dropdown_selector} .dropdown-menu" }
|
|
|
|
let(:submit_selector) { "#{form_selector} .js-comment-submit-button" }
|
|
|
|
let(:close_selector) { "#{form_selector} .btn-comment-and-close" }
|
2017-04-06 23:56:46 +00:00
|
|
|
let(:comments_selector) { '.timeline > .note.timeline-entry' }
|
2017-04-06 15:00:18 +00:00
|
|
|
|
2017-04-12 11:10:48 +00:00
|
|
|
it 'clicking "Comment" will post a comment' do
|
2017-04-06 15:00:18 +00:00
|
|
|
expect(page).to have_selector toggle_selector
|
|
|
|
|
2017-04-06 20:15:19 +00:00
|
|
|
find("#{form_selector} .note-textarea").send_keys('a')
|
2017-08-11 23:14:45 +00:00
|
|
|
|
2017-04-06 20:15:19 +00:00
|
|
|
find(submit_selector).click
|
|
|
|
|
2017-07-17 17:12:55 +00:00
|
|
|
wait_for_requests
|
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
find(comments_selector, match: :first)
|
|
|
|
new_comment = all(comments_selector).last
|
2017-04-06 20:15:19 +00:00
|
|
|
|
|
|
|
expect(new_comment).to have_content 'a'
|
|
|
|
expect(new_comment).not_to have_selector '.discussion'
|
|
|
|
end
|
|
|
|
|
2017-04-06 22:01:19 +00:00
|
|
|
if resource_name == 'issue'
|
2017-04-06 23:56:46 +00:00
|
|
|
it "clicking 'Comment & close #{resource_name}' will post a comment and close the #{resource_name}" do
|
2017-04-06 20:15:19 +00:00
|
|
|
find("#{form_selector} .note-textarea").send_keys('a')
|
|
|
|
|
|
|
|
find(close_selector).click
|
2017-07-17 17:12:55 +00:00
|
|
|
wait_for_requests
|
2017-04-06 20:15:19 +00:00
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
find(comments_selector, match: :first)
|
|
|
|
find("#{comments_selector}.system-note")
|
|
|
|
entries = all(comments_selector)
|
2017-04-06 20:15:19 +00:00
|
|
|
close_note = entries.last
|
|
|
|
new_comment = entries[-2]
|
|
|
|
|
|
|
|
expect(close_note).to have_content 'closed'
|
|
|
|
expect(new_comment).not_to have_selector '.discussion'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-06 15:00:18 +00:00
|
|
|
describe 'when the toggle is clicked' do
|
|
|
|
before do
|
|
|
|
find("#{form_selector} .note-textarea").send_keys('a')
|
|
|
|
|
|
|
|
find(toggle_selector).click
|
|
|
|
end
|
|
|
|
|
2017-04-12 11:10:48 +00:00
|
|
|
it 'has a "Comment" item (selected by default) and "Start discussion" item' do
|
2017-04-06 15:00:18 +00:00
|
|
|
expect(page).to have_selector menu_selector
|
|
|
|
|
2017-04-06 19:13:50 +00:00
|
|
|
find("#{menu_selector} li", match: :first)
|
2017-04-06 15:00:18 +00:00
|
|
|
items = all("#{menu_selector} li")
|
|
|
|
|
|
|
|
expect(items.first).to have_content 'Comment'
|
2017-04-12 11:10:48 +00:00
|
|
|
expect(items.first).to have_content "Add a general comment to this #{resource_name}."
|
2017-04-06 15:00:18 +00:00
|
|
|
expect(items.first).to have_selector '.fa-check'
|
2017-04-06 19:13:50 +00:00
|
|
|
expect(items.first['class']).to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
|
|
|
|
expect(items.last).to have_content 'Start discussion'
|
2017-04-12 11:10:48 +00:00
|
|
|
expect(items.last).to have_content "Discuss a specific suggestion or question#{' that needs to be resolved' if resource_name == 'merge request'}."
|
2017-04-06 15:00:18 +00:00
|
|
|
expect(items.last).not_to have_selector '.fa-check'
|
2017-04-06 19:13:50 +00:00
|
|
|
expect(items.last['class']).not_to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
2017-04-12 11:10:48 +00:00
|
|
|
it 'closes the menu when clicking the toggle or body' do
|
2017-04-06 15:00:18 +00:00
|
|
|
find(toggle_selector).click
|
|
|
|
|
|
|
|
expect(page).not_to have_selector menu_selector
|
|
|
|
|
2017-04-12 11:10:48 +00:00
|
|
|
find(toggle_selector).click
|
2017-04-06 15:00:18 +00:00
|
|
|
find('body').click
|
|
|
|
|
|
|
|
expect(page).not_to have_selector menu_selector
|
|
|
|
end
|
|
|
|
|
2017-08-11 23:14:45 +00:00
|
|
|
it 'clicking the ul padding or divider should not change the text' do
|
2017-08-14 05:15:52 +00:00
|
|
|
find(menu_selector).trigger 'click'
|
|
|
|
|
2017-08-12 22:38:45 +00:00
|
|
|
if resource_name == 'issue'
|
|
|
|
expect(find(dropdown_selector)).to have_content 'Comment'
|
2017-04-06 23:56:46 +00:00
|
|
|
|
2017-08-12 22:38:45 +00:00
|
|
|
find(toggle_selector).click
|
|
|
|
find("#{menu_selector} .divider").trigger 'click'
|
|
|
|
else
|
|
|
|
find(menu_selector).trigger 'click'
|
2017-04-19 21:18:39 +00:00
|
|
|
|
2017-08-12 22:38:45 +00:00
|
|
|
expect(page).to have_selector menu_selector
|
|
|
|
expect(find(dropdown_selector)).to have_content 'Comment'
|
2017-04-19 21:18:39 +00:00
|
|
|
|
2017-08-12 22:38:45 +00:00
|
|
|
find("#{menu_selector} .divider").trigger 'click'
|
|
|
|
|
|
|
|
expect(page).to have_selector menu_selector
|
|
|
|
end
|
2017-08-14 05:15:52 +00:00
|
|
|
|
|
|
|
expect(find(dropdown_selector)).to have_content 'Comment'
|
2017-08-11 23:14:45 +00:00
|
|
|
end
|
2017-04-06 23:56:46 +00:00
|
|
|
|
2017-04-06 15:00:18 +00:00
|
|
|
describe 'when selecting "Start discussion"' do
|
|
|
|
before do
|
2017-04-06 19:13:50 +00:00
|
|
|
find("#{menu_selector} li", match: :first)
|
2017-04-06 23:56:46 +00:00
|
|
|
all("#{menu_selector} li").last.click
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
2017-07-17 17:12:55 +00:00
|
|
|
it 'updates the submit button text and closes the dropdown' do
|
2017-04-07 01:50:10 +00:00
|
|
|
expect(find(dropdown_selector)).to have_content 'Start discussion'
|
2017-04-12 11:10:48 +00:00
|
|
|
expect(page).not_to have_selector menu_selector
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if resource_name =~ /(issue|merge request)/
|
|
|
|
it 'updates the close button text' do
|
|
|
|
expect(find(close_selector)).to have_content "Start discussion & close #{resource_name}"
|
|
|
|
end
|
2017-04-06 23:56:46 +00:00
|
|
|
|
|
|
|
it 'typing does not change the close button text' do
|
|
|
|
find("#{form_selector} .note-textarea").send_keys('b')
|
|
|
|
|
|
|
|
expect(find(close_selector)).to have_content "Start discussion & close #{resource_name}"
|
|
|
|
end
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
it 'clicking "Start discussion" will post a discussion' do
|
2017-04-06 15:00:18 +00:00
|
|
|
find(submit_selector).click
|
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
find(comments_selector, match: :first)
|
|
|
|
new_comment = all(comments_selector).last
|
2017-04-06 15:00:18 +00:00
|
|
|
|
|
|
|
expect(new_comment).to have_content 'a'
|
|
|
|
expect(new_comment).to have_selector '.discussion'
|
|
|
|
end
|
|
|
|
|
2017-04-06 22:01:19 +00:00
|
|
|
if resource_name == 'issue'
|
2017-04-06 23:56:46 +00:00
|
|
|
it "clicking 'Start discussion & close #{resource_name}' will post a discussion and close the #{resource_name}" do
|
2017-04-06 15:00:18 +00:00
|
|
|
find(close_selector).click
|
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
find(comments_selector, match: :first)
|
|
|
|
find("#{comments_selector}.system-note")
|
|
|
|
entries = all(comments_selector)
|
2017-04-06 15:00:18 +00:00
|
|
|
close_note = entries.last
|
|
|
|
new_discussion = entries[-2]
|
|
|
|
|
|
|
|
expect(close_note).to have_content 'closed'
|
|
|
|
expect(new_discussion).to have_selector '.discussion'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when opening the menu' do
|
|
|
|
before do
|
|
|
|
find(toggle_selector).click
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have "Start discussion" selected' do
|
2017-04-06 19:13:50 +00:00
|
|
|
find("#{menu_selector} li", match: :first)
|
2017-04-06 15:00:18 +00:00
|
|
|
items = all("#{menu_selector} li")
|
|
|
|
|
|
|
|
expect(items.first).to have_content 'Comment'
|
|
|
|
expect(items.first).not_to have_selector '.fa-check'
|
2017-04-06 23:56:46 +00:00
|
|
|
expect(items.first['class']).not_to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
|
|
|
|
expect(items.last).to have_content 'Start discussion'
|
|
|
|
expect(items.last).to have_selector '.fa-check'
|
2017-04-06 23:56:46 +00:00
|
|
|
expect(items.last['class']).to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when selecting "Comment"' do
|
|
|
|
before do
|
2017-04-06 23:56:46 +00:00
|
|
|
find("#{menu_selector} li", match: :first).click
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
2017-07-17 17:12:55 +00:00
|
|
|
it 'updates the submit button text and closes the dropdown' do
|
2017-04-07 01:50:10 +00:00
|
|
|
expect(find(dropdown_selector)).to have_content 'Comment'
|
2017-04-12 11:10:48 +00:00
|
|
|
expect(page).not_to have_selector menu_selector
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if resource_name =~ /(issue|merge request)/
|
|
|
|
it 'updates the close button text' do
|
|
|
|
expect(find(close_selector)).to have_content "Comment & close #{resource_name}"
|
|
|
|
end
|
2017-04-06 23:56:46 +00:00
|
|
|
|
|
|
|
it 'typing does not change the close button text' do
|
|
|
|
find("#{form_selector} .note-textarea").send_keys('b')
|
|
|
|
|
|
|
|
expect(find(close_selector)).to have_content "Comment & close #{resource_name}"
|
|
|
|
end
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have "Comment" selected when opening the menu' do
|
|
|
|
find(toggle_selector).click
|
|
|
|
|
2017-04-06 19:13:50 +00:00
|
|
|
find("#{menu_selector} li", match: :first)
|
2017-04-06 15:00:18 +00:00
|
|
|
items = all("#{menu_selector} li")
|
|
|
|
|
|
|
|
expect(items.first).to have_content 'Comment'
|
|
|
|
expect(items.first).to have_selector '.fa-check'
|
2017-04-06 23:56:46 +00:00
|
|
|
expect(items.first['class']).to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
|
|
|
|
expect(items.last).to have_content 'Start discussion'
|
|
|
|
expect(items.last).not_to have_selector '.fa-check'
|
2017-04-06 23:56:46 +00:00
|
|
|
expect(items.last['class']).not_to match 'droplab-item-selected'
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-06 19:13:50 +00:00
|
|
|
|
|
|
|
if resource_name =~ /(issue|merge request)/
|
|
|
|
describe "on a closed #{resource_name}" do
|
2017-04-06 23:56:46 +00:00
|
|
|
before do
|
2017-04-07 01:50:10 +00:00
|
|
|
find("#{form_selector} .js-note-target-close").click
|
|
|
|
|
|
|
|
find("#{form_selector} .note-textarea").send_keys('a')
|
2017-04-06 23:56:46 +00:00
|
|
|
end
|
|
|
|
|
2017-04-07 01:50:10 +00:00
|
|
|
it "should show a 'Comment & reopen #{resource_name}' button" do
|
|
|
|
expect(find("#{form_selector} .js-note-target-reopen")).to have_content "Comment & reopen #{resource_name}"
|
2017-04-06 23:56:46 +00:00
|
|
|
end
|
|
|
|
|
2017-04-07 01:50:10 +00:00
|
|
|
it "should show a 'Start discussion & reopen #{resource_name}' button when 'Start discussion' is selected" do
|
2017-04-06 23:56:46 +00:00
|
|
|
find(toggle_selector).click
|
2017-04-06 19:13:50 +00:00
|
|
|
|
2017-04-06 23:56:46 +00:00
|
|
|
find("#{menu_selector} li", match: :first)
|
|
|
|
all("#{menu_selector} li").last.click
|
|
|
|
|
2017-04-07 01:50:10 +00:00
|
|
|
expect(find("#{form_selector} .js-note-target-reopen")).to have_content "Start discussion & reopen #{resource_name}"
|
2017-04-06 23:56:46 +00:00
|
|
|
end
|
2017-04-06 19:13:50 +00:00
|
|
|
end
|
|
|
|
end
|
2017-04-06 15:00:18 +00:00
|
|
|
end
|