gitlab-org--gitlab-foss/spec/support/features/discussion_comments_shared_example.rb

313 lines
11 KiB
Ruby
Raw Normal View History

2017-04-06 11:00:18 -04: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 19:56:46 -04:00
let(:comments_selector) { '.timeline > .note.timeline-entry' }
2017-04-06 11:00:18 -04:00
2019-04-09 14:04:26 -04:00
it 'clicking "Comment" will post a comment', :quarantine do
2017-04-06 11:00:18 -04:00
expect(page).to have_selector toggle_selector
2017-04-06 16:15:19 -04:00
find("#{form_selector} .note-textarea").send_keys('a')
find(submit_selector).click
2017-07-17 13:12:55 -04:00
wait_for_requests
2017-04-06 19:56:46 -04:00
find(comments_selector, match: :first)
new_comment = all(comments_selector).last
2017-04-06 16:15:19 -04:00
expect(new_comment).to have_content 'a'
expect(new_comment).not_to have_selector '.discussion'
end
2017-04-06 18:01:19 -04:00
if resource_name == 'issue'
2017-04-06 19:56:46 -04:00
it "clicking 'Comment & close #{resource_name}' will post a comment and close the #{resource_name}" do
2017-04-06 16:15:19 -04:00
find("#{form_selector} .note-textarea").send_keys('a')
find(close_selector).click
2017-07-17 13:12:55 -04:00
wait_for_requests
2017-04-06 16:15:19 -04:00
2017-04-06 19:56:46 -04:00
find(comments_selector, match: :first)
find("#{comments_selector}.system-note")
entries = all(comments_selector)
2017-04-06 16:15:19 -04: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 11:00:18 -04: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 07:10:48 -04:00
it 'has a "Comment" item (selected by default) and "Start discussion" item' do
2017-04-06 11:00:18 -04:00
expect(page).to have_selector menu_selector
find("#{menu_selector} li", match: :first)
2017-04-06 11:00:18 -04:00
items = all("#{menu_selector} li")
expect(items.first).to have_content 'Comment'
2017-04-12 07:10:48 -04:00
expect(items.first).to have_content "Add a general comment to this #{resource_name}."
2017-04-06 11:00:18 -04:00
expect(items.first).to have_selector '.fa-check'
expect(items.first['class']).to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
expect(items.last).to have_content 'Start discussion'
2017-04-12 07:10:48 -04: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 11:00:18 -04:00
expect(items.last).not_to have_selector '.fa-check'
expect(items.last['class']).not_to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
end
2017-04-12 07:10:48 -04:00
it 'closes the menu when clicking the toggle or body' do
2017-04-06 11:00:18 -04:00
find(toggle_selector).click
expect(page).not_to have_selector menu_selector
2017-04-12 07:10:48 -04:00
find(toggle_selector).click
2017-11-07 10:47:09 -05:00
execute_script("document.querySelector('body').click()")
2017-04-06 11:00:18 -04:00
expect(page).not_to have_selector menu_selector
end
it 'clicking the ul padding or divider should not change the text' do
execute_script("document.querySelector('#{menu_selector}').click()")
2017-04-06 19:56:46 -04:00
# on issues page, the menu closes when clicking anywhere, on other pages it will
# remain open if clicking divider or menu padding, but should not change button action
2018-04-03 12:03:00 -04:00
#
# if dropdown menu is not toggled (and also not present),
# it's "issue-type" dropdown
if first(menu_selector, minimum: 0).nil?
expect(find(dropdown_selector)).to have_content 'Comment'
find(toggle_selector).click
execute_script("document.querySelector('#{menu_selector} .divider').click()")
else
execute_script("document.querySelector('#{menu_selector}').click()")
expect(page).to have_selector menu_selector
expect(find(dropdown_selector)).to have_content 'Comment'
execute_script("document.querySelector('#{menu_selector} .divider').click()")
expect(page).to have_selector menu_selector
end
expect(find(dropdown_selector)).to have_content 'Comment'
2017-04-06 19:56:46 -04:00
end
2017-04-06 11:00:18 -04:00
describe 'when selecting "Start discussion"' do
before do
find("#{menu_selector} li", match: :first)
2017-04-06 19:56:46 -04:00
all("#{menu_selector} li").last.click
2017-04-06 11:00:18 -04:00
end
2017-07-17 13:12:55 -04:00
it 'updates the submit button text and closes the dropdown' do
2018-04-03 12:03:00 -04:00
button = find(submit_selector)
# on issues page, the submit input is a <button>, on other pages it is <input>
2018-04-03 12:03:00 -04:00
if button.tag_name == 'button'
expect(find(submit_selector)).to have_content 'Start discussion'
else
expect(find(submit_selector).value).to eq 'Start discussion'
end
2017-04-12 07:10:48 -04:00
expect(page).not_to have_selector menu_selector
2017-04-06 11:00:18 -04: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 19:56:46 -04: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 11:00:18 -04:00
end
describe 'creating a discussion' do
before do
find(submit_selector).click
2018-04-03 12:03:00 -04:00
wait_for_requests
find(comments_selector, match: :first)
end
2017-04-06 11:00:18 -04:00
2018-12-04 05:09:51 -05:00
def submit_reply(text)
find("#{comments_selector} .js-vue-discussion-reply").click
find("#{comments_selector} .note-textarea").send_keys(text)
click_button "Comment"
wait_for_requests
end
it 'clicking "Start discussion" will post a discussion' do
new_comment = all(comments_selector).last
expect(new_comment).to have_content 'a'
expect(new_comment).to have_selector '.discussion'
end
2017-04-06 11:00:18 -04:00
2018-12-04 05:09:51 -05:00
if resource_name =~ /(issue|merge request)/
it 'can be replied to' do
submit_reply('some text')
expect(page).to have_css('.discussion-notes .note', count: 2)
expect(page).to have_content 'Collapse replies'
end
it 'can be collapsed' do
submit_reply('another text')
find('.js-collapse-replies').click
expect(page).to have_css('.discussion-notes .note', count: 1)
expect(page).to have_content '1 reply'
end
end
if resource_name == 'merge request'
2018-11-08 02:58:45 -05:00
let(:note_id) { find("#{comments_selector} .note:first-child", match: :first)['data-note-id'] }
let(:reply_id) { find("#{comments_selector} .note:last-child", match: :first)['data-note-id'] }
it 'can be replied to after resolving' do
click_button "Resolve discussion"
wait_for_requests
refresh
wait_for_requests
submit_reply('to reply or not reply')
end
it 'shows resolved discussion when toggled' do
2018-12-04 05:09:51 -05:00
submit_reply('a')
2018-11-08 02:58:45 -05:00
click_button "Resolve discussion"
2018-11-08 02:58:45 -05:00
wait_for_requests
2017-04-06 11:00:18 -04:00
expect(page).to have_selector(".note-row-#{note_id}", visible: true)
2017-04-06 11:00:18 -04:00
refresh
2018-11-08 02:58:45 -05:00
click_button "1 reply"
2018-11-08 02:58:45 -05:00
expect(page).to have_selector(".note-row-#{reply_id}", visible: true)
end
end
2017-04-06 11:00:18 -04:00
end
2017-04-06 18:01:19 -04:00
if resource_name == 'issue'
2017-04-06 19:56:46 -04:00
it "clicking 'Start discussion & close #{resource_name}' will post a discussion and close the #{resource_name}" do
2017-04-06 11:00:18 -04:00
find(close_selector).click
2017-04-06 19:56:46 -04:00
find(comments_selector, match: :first)
find("#{comments_selector}.system-note")
entries = all(comments_selector)
2017-04-06 11:00:18 -04: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 'has "Start discussion" selected' do
find("#{menu_selector} li", match: :first)
2017-04-06 11:00:18 -04: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 19:56:46 -04:00
expect(items.first['class']).not_to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
expect(items.last).to have_content 'Start discussion'
expect(items.last).to have_selector '.fa-check'
2017-04-06 19:56:46 -04:00
expect(items.last['class']).to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
end
describe 'when selecting "Comment"' do
before do
2017-04-06 19:56:46 -04:00
find("#{menu_selector} li", match: :first).click
2017-04-06 11:00:18 -04:00
end
2017-07-17 13:12:55 -04:00
it 'updates the submit button text and closes the dropdown' do
2018-04-03 12:03:00 -04:00
button = find(submit_selector)
# on issues page, the submit input is a <button>, on other pages it is <input>
2018-04-03 12:03:00 -04:00
if button.tag_name == 'button'
expect(button).to have_content 'Comment'
else
2018-04-03 12:03:00 -04:00
expect(button.value).to eq 'Comment'
end
2017-04-12 07:10:48 -04:00
expect(page).not_to have_selector menu_selector
2017-04-06 11:00:18 -04: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 19:56:46 -04: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 11:00:18 -04:00
end
it 'has "Comment" selected when opening the menu' do
2017-04-06 11:00:18 -04:00
find(toggle_selector).click
find("#{menu_selector} li", match: :first)
2017-04-06 11:00:18 -04:00
items = all("#{menu_selector} li")
expect(items.first).to have_content 'Comment'
expect(items.first).to have_selector '.fa-check'
2017-04-06 19:56:46 -04:00
expect(items.first['class']).to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
expect(items.last).to have_content 'Start discussion'
expect(items.last).not_to have_selector '.fa-check'
2017-04-06 19:56:46 -04:00
expect(items.last['class']).not_to match 'droplab-item-selected'
2017-04-06 11:00:18 -04:00
end
end
end
end
end
if resource_name =~ /(issue|merge request)/
describe "on a closed #{resource_name}" do
2017-04-06 19:56:46 -04:00
before do
2017-04-06 21:50:10 -04:00
find("#{form_selector} .js-note-target-close").click
wait_for_requests
2017-04-06 21:50:10 -04:00
find("#{form_selector} .note-textarea").send_keys('a')
2017-04-06 19:56:46 -04:00
end
2017-04-06 21:50:10 -04: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 19:56:46 -04:00
end
2017-04-06 21:50:10 -04:00
it "should show a 'Start discussion & reopen #{resource_name}' button when 'Start discussion' is selected" do
find(toggle_selector).click
2017-04-06 19:56:46 -04:00
find("#{menu_selector} li", match: :first)
all("#{menu_selector} li").last.click
2017-04-06 21:50:10 -04:00
expect(find("#{form_selector} .js-note-target-reopen")).to have_content "Start discussion & reopen #{resource_name}"
2017-04-06 19:56:46 -04:00
end
end
end
2017-04-06 11:00:18 -04:00
end