From ebf66e499765d914014e92a62f7a1935d2691523 Mon Sep 17 00:00:00 2001 From: Will Gutierrez Date: Sun, 6 Jun 2021 20:51:46 -0700 Subject: [PATCH] prune comment system tests #9069 --- test/system/comment_test.rb | 471 ++++++++++++++++++------------------ 1 file changed, 236 insertions(+), 235 deletions(-) diff --git a/test/system/comment_test.rb b/test/system/comment_test.rb index dea8157019b..f6e9b9246a7 100644 --- a/test/system/comment_test.rb +++ b/test/system/comment_test.rb @@ -477,52 +477,72 @@ def get_path(page_type, path) end end - # PART 3: TESTS for ALL PAGE TYPES! - # - # the page_types are: Wikis, Research Notes, and Questions - # defined in test/test_helper.rb - page_types.each do |page_type, node_name| - page_type_string = page_type.to_s + test "#{page_type_string}: IMMEDIATE image SELECT upload into REPLY comment form" do + nodes(node_name).add_comment({ + uid: 5, + body: comment_text + }) + nodes(node_name).add_comment({ + uid: 2, + body: comment_text + }) + visit get_path(page_type, nodes(node_name).path) + reply_toggles = page.all('p', text: 'Reply to this comment...') + reply_toggles[2].click + reply_dropzone_id = page.find('[id^=dropzone-small-reply-]')[:id] # ID begins with... + comment_id_num = /dropzone-small-reply-(\d+)/.match(reply_dropzone_id)[1] + # upload images + # the that take image uploads are hidden, so reveal them: + Capybara.ignore_hidden_elements = false + # upload an image in the reply comment form + page.find('#fileinput-button-reply-' + comment_id_num).set("#{Rails.root.to_s}/public/images/pl.png") + wait_for_ajax + Capybara.ignore_hidden_elements = true + page.all('a', text: 'Preview')[0].click + assert_selector('#comment-' + comment_id_num + '-reply-section img', count: 1) + end - test "post #{page_type_string}, then comment on FRESH #{page_type_string}" do - title_text, body_text = String.new, String.new - case page_type_string - when 'note' - visit '/post' - title_text = 'Ahh, a nice fresh note' - body_text = "Can\'t wait to write in it!" - fill_in('title-input', with: title_text) - find('.wk-wysiwyg').set(body_text) - find('.ple-publish').click() - when 'question' - visit '/questions/new?&tags=question%3Ageneral' - title_text = "Let's talk condiments" - body_text = 'Ketchup or mayo?' - find("input[aria-label='Enter question']", match: :first) - .click() - .fill_in with: title_text - find('.wk-wysiwyg').set(body_text) - find('.ple-publish').click() - when 'wiki' - visit '/wiki/new' - title_text = 'pokemon' - body_text = 'Gotta catch em all!' - fill_in('title', with: title_text) - fill_in('text-input-main', with: body_text) - find('#publish').click() - visit "/wiki/#{title_text}/comments" - end - assert_selector('h1', text: title_text) - page.find("textarea#text-input-main") - .click - .fill_in with: comment_text - # preview comment - find("#toggle-preview-button-main").click - find("p", text: comment_text) - # publish comment - click_on "Publish" - find(".noty_body", text: "Comment Added!") - find("p", text: comment_text) + test "#{page_type_string}: IMMEDIATE image DRAG & DROP into REPLY comment form" do + Capybara.ignore_hidden_elements = false + visit get_path(page_type, nodes(node_name).path) + find("p", text: "Reply to this comment...").click() + # Upload the image + drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", ".dropzone-large") + # Wait for image upload to finish + wait_for_ajax + Capybara.ignore_hidden_elements = true + # Toggle preview + reply_preview_button = page.all('.preview-btn')[0] + reply_preview_button.click() + # Make sure that image has been uploaded + page.assert_selector('.comment-preview img', count: 1) + end + + test "#{page_type_string}: IMMEDIATE image CHOOSE ONE upload into REPLY comment form" do + Capybara.ignore_hidden_elements = false + visit get_path(page_type, nodes(node_name).path) + # Open reply comment form + find("p", text: "Reply to this comment...").click() + first("a", text: "choose one").click() + reply_preview_button = page.first('a', text: 'Preview') + Capybara.ignore_hidden_elements = false + # Upload the image + fileinput_element = page.first("[id^=fileinput-button-reply]") + fileinput_element.set("#{Rails.root.to_s}/public/images/pl.png") + Capybara.ignore_hidden_elements = true + wait_for_ajax + # Toggle preview + reply_preview_button.click() + # Make sure that image has been uploaded + page.assert_selector('.comment-preview img', count: 1) + end + + test "#{page_type_string}: IMMEDIATE rich-text input works in MAIN form" do + visit get_path(page_type, nodes(node_name).path) + main_comment_form = page.find('h4', text: /Post comment|Post Comment/).find(:xpath, '..') # title text on wikis is 'Post comment' + main_comment_form.find("[data-original-title='Bold']").click + text_input_value = main_comment_form.find('#text-input-main').value + assert_equal(text_input_value, '****') end # navigate to page, immediately upload into EDIT form by SELECTing image @@ -637,65 +657,54 @@ def get_path(page_type, path) visit get_path(page_type, nodes(node_name).path) assert_selector("#c#{comment.id}", count: 0) end + end - test "#{page_type_string}: IMMEDIATE image SELECT upload into REPLY comment form" do - nodes(node_name).add_comment({ - uid: 5, - body: comment_text - }) - nodes(node_name).add_comment({ - uid: 2, - body: comment_text - }) - visit get_path(page_type, nodes(node_name).path) - reply_toggles = page.all('p', text: 'Reply to this comment...') - reply_toggles[2].click - reply_dropzone_id = page.find('[id^=dropzone-small-reply-]')[:id] # ID begins with... - comment_id_num = /dropzone-small-reply-(\d+)/.match(reply_dropzone_id)[1] - # upload images - # the that take image uploads are hidden, so reveal them: - Capybara.ignore_hidden_elements = false - # upload an image in the reply comment form - page.find('#fileinput-button-reply-' + comment_id_num).set("#{Rails.root.to_s}/public/images/pl.png") - wait_for_ajax - Capybara.ignore_hidden_elements = true - page.all('a', text: 'Preview')[0].click - assert_selector('#comment-' + comment_id_num + '-reply-section img', count: 1) - end - - test "#{page_type_string}: IMMEDIATE image DRAG & DROP into REPLY comment form" do - Capybara.ignore_hidden_elements = false - visit get_path(page_type, nodes(node_name).path) - find("p", text: "Reply to this comment...").click() - # Upload the image - drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", ".dropzone-large") - # Wait for image upload to finish - wait_for_ajax - Capybara.ignore_hidden_elements = true - # Toggle preview - reply_preview_button = page.all('.preview-btn')[0] - reply_preview_button.click() - # Make sure that image has been uploaded - page.assert_selector('.comment-preview img', count: 1) - end + # PART 3: TESTS for ALL PAGE TYPES! + # + # the page_types are: Wikis, Research Notes, and Questions + # defined in test/test_helper.rb + page_types.each do |page_type, node_name| + page_type_string = page_type.to_s - test "#{page_type_string}: IMMEDIATE image CHOOSE ONE upload into REPLY comment form" do - Capybara.ignore_hidden_elements = false - visit get_path(page_type, nodes(node_name).path) - # Open reply comment form - find("p", text: "Reply to this comment...").click() - first("a", text: "choose one").click() - reply_preview_button = page.first('a', text: 'Preview') - Capybara.ignore_hidden_elements = false - # Upload the image - fileinput_element = page.first("[id^=fileinput-button-reply]") - fileinput_element.set("#{Rails.root.to_s}/public/images/pl.png") - Capybara.ignore_hidden_elements = true - wait_for_ajax - # Toggle preview - reply_preview_button.click() - # Make sure that image has been uploaded - page.assert_selector('.comment-preview img', count: 1) + test "post #{page_type_string}, then comment on FRESH #{page_type_string}" do + title_text, body_text = String.new, String.new + case page_type_string + when 'note' + visit '/post' + title_text = 'Ahh, a nice fresh note' + body_text = "Can\'t wait to write in it!" + fill_in('title-input', with: title_text) + find('.wk-wysiwyg').set(body_text) + find('.ple-publish').click() + when 'question' + visit '/questions/new?&tags=question%3Ageneral' + title_text = "Let's talk condiments" + body_text = 'Ketchup or mayo?' + find("input[aria-label='Enter question']", match: :first) + .click() + .fill_in with: title_text + find('.wk-wysiwyg').set(body_text) + find('.ple-publish').click() + when 'wiki' + visit '/wiki/new' + title_text = 'pokemon' + body_text = 'Gotta catch em all!' + fill_in('title', with: title_text) + fill_in('text-input-main', with: body_text) + find('#publish').click() + visit "/wiki/#{title_text}/comments" + end + assert_selector('h1', text: title_text) + page.find("textarea#text-input-main") + .click + .fill_in with: comment_text + # preview comment + find("#toggle-preview-button-main").click + find("p", text: comment_text) + # publish comment + click_on "Publish" + find(".noty_body", text: "Comment Added!") + find("p", text: comment_text) end # Cross-Wiring Bugs @@ -707,38 +716,38 @@ def get_path(page_type, path) # there are many variations of this bug. this particular test involves: # DRAG & DROP upload into MAIN comment form # DRAG & DROP into EDIT comment form (.dropzone button) - test "#{page_type_string}: image DRAG & DROP into EDIT form isn't cross-wired with MAIN form" do - # setup page with editable comment - nodes(node_name).add_comment({ - uid: 2, - body: comment_text - }) - visit get_path(page_type, nodes(node_name).path) - # .dropzone is hidden, so reveal it for Capybara's finders: - Capybara.ignore_hidden_elements = false - # drag & drop the image. drop_in_dropzone simulates 'drop' event, see application_system_test_case.rb - drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", '#comments-list + div .dropzone-large') # this CSS selects .dropzones that belong to sibling element immediately following #comments-list. technically, there are two .dropzones in the main comment form. - Capybara.ignore_hidden_elements = true - wait_for_ajax - # we need the ID of parent div that contains

comment_text

: - comment_id = page.find('p', text: comment_text).find(:xpath, '..')[:id] - # regex to strip the ID number out of string. ID format is comment-body-4231 - comment_id_num = /comment-body-(\d+)/.match(comment_id)[1] - comment_dropzone_selector = '#comment-form-body-edit-' + comment_id_num - # open the edit comment form - page.find(".edit-comment-btn").click - # drop into the edit comment form - Capybara.ignore_hidden_elements = false - drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", comment_dropzone_selector) - Capybara.ignore_hidden_elements = true - wait_for_ajax - # open the preview for the main comment form - page.find('#toggle-preview-button-main').click - # once preview is open, the images are embedded in the page. - # there should only be 1 image in the main comment form! - preview_imgs = page.all('#comment-preview-main img').size - assert_equal(1, preview_imgs) - end + # test "#{page_type_string}: image DRAG & DROP into EDIT form isn't cross-wired with MAIN form" do + # # setup page with editable comment + # nodes(node_name).add_comment({ + # uid: 2, + # body: comment_text + # }) + # visit get_path(page_type, nodes(node_name).path) + # # .dropzone is hidden, so reveal it for Capybara's finders: + # Capybara.ignore_hidden_elements = false + # # drag & drop the image. drop_in_dropzone simulates 'drop' event, see application_system_test_case.rb + # drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", '#comments-list + div .dropzone-large') # this CSS selects .dropzones that belong to sibling element immediately following #comments-list. technically, there are two .dropzones in the main comment form. + # Capybara.ignore_hidden_elements = true + # wait_for_ajax + # # we need the ID of parent div that contains

comment_text

: + # comment_id = page.find('p', text: comment_text).find(:xpath, '..')[:id] + # # regex to strip the ID number out of string. ID format is comment-body-4231 + # comment_id_num = /comment-body-(\d+)/.match(comment_id)[1] + # comment_dropzone_selector = '#comment-form-body-edit-' + comment_id_num + # # open the edit comment form + # page.find(".edit-comment-btn").click + # # drop into the edit comment form + # Capybara.ignore_hidden_elements = false + # drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", comment_dropzone_selector) + # Capybara.ignore_hidden_elements = true + # wait_for_ajax + # # open the preview for the main comment form + # page.find('#toggle-preview-button-main').click + # # once preview is open, the images are embedded in the page. + # # there should only be 1 image in the main comment form! + # preview_imgs = page.all('#comment-preview-main img').size + # assert_equal(1, preview_imgs) + # end # cross-wiring test: # SELECT image upload in both: @@ -747,111 +756,103 @@ def get_path(page_type, path) # NOTE: this is also a test for: # IMMEDIATE image SELECT upload into MAIN comment form - test "#{page_type_string}: image SELECT upload into EDIT form isn't CROSS-WIRED with MAIN form" do - nodes(node_name).add_comment({ - uid: 5, - body: comment_text - }) - nodes(node_name).add_comment({ - uid: 2, - body: comment_text - }) - visit get_path(page_type, nodes(node_name).path) - # open the edit comment form: - find(".edit-comment-btn").click - # find the parent of edit comment's fileinput: - comment_fileinput_parent_id = page.find('[id^=dropzone-small-edit-]')[:id] # 'begins with' CSS selector - comment_id_num = /dropzone-small-edit-(\d+)/.match(comment_fileinput_parent_id)[1] - # upload images - # the that take image uploads are hidden, so reveal them: - Capybara.ignore_hidden_elements = false - # upload an image in the main comment form - page.find('#fileinput-button-main').set("#{Rails.root.to_s}/public/images/pl.png") - wait_for_ajax - # find edit comment's fileinput: - page.find('#fileinput-button-edit-' + comment_id_num).set("#{Rails.root.to_s}/public/images/pl.png") - wait_for_ajax - Capybara.ignore_hidden_elements = true - # click preview buttons in main and edit form - page.find('h4', text: /Post comment|Post Comment/) # title text on wikis is 'Post comment' - .find(:xpath, '..') - .find('a', text: 'Preview').click - page.find('#comment-form-edit-' + comment_id_num + ' a', text: 'Preview').click - # once preview is open, the images are embedded in the page. - # there should be 1 image in main, and 1 image in edit - assert_selector('#comment-preview-edit-' + comment_id_num + ' img', count: 1) - assert_selector('#comment-preview-main img', count: 1) - end + # test "#{page_type_string}: image SELECT upload into EDIT form isn't CROSS-WIRED with MAIN form" do + # nodes(node_name).add_comment({ + # uid: 5, + # body: comment_text + # }) + # nodes(node_name).add_comment({ + # uid: 2, + # body: comment_text + # }) + # visit get_path(page_type, nodes(node_name).path) + # # open the edit comment form: + # find(".edit-comment-btn").click + # # find the parent of edit comment's fileinput: + # comment_fileinput_parent_id = page.find('[id^=dropzone-small-edit-]')[:id] # 'begins with' CSS selector + # comment_id_num = /dropzone-small-edit-(\d+)/.match(comment_fileinput_parent_id)[1] + # # upload images + # # the that take image uploads are hidden, so reveal them: + # Capybara.ignore_hidden_elements = false + # # upload an image in the main comment form + # page.find('#fileinput-button-main').set("#{Rails.root.to_s}/public/images/pl.png") + # wait_for_ajax + # # find edit comment's fileinput: + # page.find('#fileinput-button-edit-' + comment_id_num).set("#{Rails.root.to_s}/public/images/pl.png") + # wait_for_ajax + # Capybara.ignore_hidden_elements = true + # # click preview buttons in main and edit form + # page.find('h4', text: /Post comment|Post Comment/) # title text on wikis is 'Post comment' + # .find(:xpath, '..') + # .find('a', text: 'Preview').click + # page.find('#comment-form-edit-' + comment_id_num + ' a', text: 'Preview').click + # # once preview is open, the images are embedded in the page. + # # there should be 1 image in main, and 1 image in edit + # assert_selector('#comment-preview-edit-' + comment_id_num + ' img', count: 1) + # assert_selector('#comment-preview-main img', count: 1) + # end # cross-wiring test # SELECT image upload in both: # EDIT FORM # REPLY form - test "#{page_type_string}: image SELECT upload into EDIT form isn't CROSS-WIRED with REPLY form" do - nodes(node_name).add_comment({ - uid: 2, - body: comment_text - }) - visit get_path(page_type, nodes(node_name).path) - # find the EDIT id - # open up the edit comment form - page.find(".edit-comment-btn").click - edit_comment_form_id = page.find('h4', text: 'Edit comment').find(:xpath, '..')[:id] - # regex to strip the ID number out of string. ID format is #c1234edit - edit_id_num = /comment-form-edit-(\d+)/.match(edit_comment_form_id)[1] - # open the edit comment form - edit_preview_id = '#comment-preview-edit-' + edit_id_num - # find the REPLY id - page.all('p', text: 'Reply to this comment...')[0].click - reply_dropzone_id = page.find('[id^=dropzone-small-reply-]')[:id] - # ID begins with... - reply_id_num = /dropzone-small-reply-(\d+)/.match(reply_dropzone_id)[1] - # upload images - # the that take image uploads are hidden, so reveal them: - Capybara.ignore_hidden_elements = false - # upload an image in the reply comment form - page.find('#fileinput-button-reply-' + reply_id_num).set("#{Rails.root.to_s}/public/images/pl.png") - wait_for_ajax - # upload an image in the edit comment form - page.find('#fileinput-button-edit-' + edit_id_num).set("#{Rails.root.to_s}/public/images/pl.png") - Capybara.ignore_hidden_elements = true - wait_for_ajax - # click preview buttons in reply and edit form - page.find('#comment-form-edit-' + edit_id_num + ' a', text: 'Preview').click - page.first('a', text: 'Preview').click - assert_selector('#comment-preview-edit-' + edit_id_num + ' img', count: 1) - assert_selector('#comment-preview-reply-' + reply_id_num, count: 1) - end - - test "#{page_type_string}: IMMEDIATE rich-text input works in MAIN form" do - visit get_path(page_type, nodes(node_name).path) - main_comment_form = page.find('h4', text: /Post comment|Post Comment/).find(:xpath, '..') # title text on wikis is 'Post comment' - main_comment_form.find("[data-original-title='Bold']").click - text_input_value = main_comment_form.find('#text-input-main').value - assert_equal(text_input_value, '****') - end - - test "#{page_type_string}: rich-text input into REPLY form isn't CROSS-WIRED with EDIT form" do - nodes(node_name).add_comment({ - uid: 5, - body: comment_text - }) - nodes(node_name).add_comment({ - uid: 2, - body: comment_text - }) - visit get_path(page_type, nodes(node_name).path) - # open up the edit comment form - page.find(".edit-comment-btn").click - # find the EDIT id - edit_comment_form_id = page.find('h4', text: 'Edit comment').find(:xpath, '..')[:id] - # open up the reply comment form - page.all('p', text: 'Reply to this comment...')[1].click - page.all("[data-original-title='Bold']")[0].click - reply_input_value = page.find('[id^=text-input-reply-]').value - edit_input_value = page.find('#' + edit_comment_form_id + ' textarea').value - assert_equal(comment_text, edit_input_value) - assert_equal('****', reply_input_value) - end + # test "#{page_type_string}: image SELECT upload into EDIT form isn't CROSS-WIRED with REPLY form" do + # nodes(node_name).add_comment({ + # uid: 2, + # body: comment_text + # }) + # visit get_path(page_type, nodes(node_name).path) + # # find the EDIT id + # # open up the edit comment form + # page.find(".edit-comment-btn").click + # edit_comment_form_id = page.find('h4', text: 'Edit comment').find(:xpath, '..')[:id] + # # regex to strip the ID number out of string. ID format is #c1234edit + # edit_id_num = /comment-form-edit-(\d+)/.match(edit_comment_form_id)[1] + # # open the edit comment form + # edit_preview_id = '#comment-preview-edit-' + edit_id_num + # # find the REPLY id + # page.all('p', text: 'Reply to this comment...')[0].click + # reply_dropzone_id = page.find('[id^=dropzone-small-reply-]')[:id] + # # ID begins with... + # reply_id_num = /dropzone-small-reply-(\d+)/.match(reply_dropzone_id)[1] + # # upload images + # # the that take image uploads are hidden, so reveal them: + # Capybara.ignore_hidden_elements = false + # # upload an image in the reply comment form + # page.find('#fileinput-button-reply-' + reply_id_num).set("#{Rails.root.to_s}/public/images/pl.png") + # wait_for_ajax + # # upload an image in the edit comment form + # page.find('#fileinput-button-edit-' + edit_id_num).set("#{Rails.root.to_s}/public/images/pl.png") + # Capybara.ignore_hidden_elements = true + # wait_for_ajax + # # click preview buttons in reply and edit form + # page.find('#comment-form-edit-' + edit_id_num + ' a', text: 'Preview').click + # page.first('a', text: 'Preview').click + # assert_selector('#comment-preview-edit-' + edit_id_num + ' img', count: 1) + # assert_selector('#comment-preview-reply-' + reply_id_num, count: 1) + # end + + # test "#{page_type_string}: rich-text input into REPLY form isn't CROSS-WIRED with EDIT form" do + # nodes(node_name).add_comment({ + # uid: 5, + # body: comment_text + # }) + # nodes(node_name).add_comment({ + # uid: 2, + # body: comment_text + # }) + # visit get_path(page_type, nodes(node_name).path) + # # open up the edit comment form + # page.find(".edit-comment-btn").click + # # find the EDIT id + # edit_comment_form_id = page.find('h4', text: 'Edit comment').find(:xpath, '..')[:id] + # # open up the reply comment form + # page.all('p', text: 'Reply to this comment...')[1].click + # page.all("[data-original-title='Bold']")[0].click + # reply_input_value = page.find('[id^=text-input-reply-]').value + # edit_input_value = page.find('#' + edit_comment_form_id + ' textarea').value + # assert_equal(comment_text, edit_input_value) + # assert_equal('****', reply_input_value) + # end end end