From 3bf67fc86a63b432cf88242f43b91e30658de141 Mon Sep 17 00:00:00 2001 From: Kevin Ma <104021955+Kevma50287@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:37:06 -0400 Subject: [PATCH] Kev ma/appeals 56226 (#23343) * Add feature test setup for all inactive appeal tasks * Deepak/appeals 56223 (#23310) * update restrictions to add task * update check_inbound_ops_team_user method * update specs * update specs * test for creation & association of task objs * remove comment * refactor and add more test checks * feature test updates * combined into one it block to speed up testing * Add BvaDispatch task exception * correct conditional stmt * added retry helper method when element not found * Wrap flaky portion of test in retry block * define action in method * add logging to retry * update test --------- Co-authored-by: SanthiParakal133 <132940479+SanthiParakal133@users.noreply.github.com> --- .../correspondence/submit_intake_form_spec.rb | 81 +++++++++++++++++++ spec/support/correspondence_helpers.rb | 16 ++++ 2 files changed, 97 insertions(+) diff --git a/spec/feature/queue/correspondence/submit_intake_form_spec.rb b/spec/feature/queue/correspondence/submit_intake_form_spec.rb index a213dcdd594..7e3999246a5 100644 --- a/spec/feature/queue/correspondence/submit_intake_form_spec.rb +++ b/spec/feature/queue/correspondence/submit_intake_form_spec.rb @@ -279,4 +279,85 @@ end end end + + context "user adds tasks related to inactive appeals" do + let(:tasks_json) { JSON.parse!(File.read("client/constants/QUEUE_INTAKE_FORM_TASK_TYPES.json")) } + let(:inactive_appeal_tasks) { tasks_json["relatedToAppealInactive"] } + let(:inactive_appeal_tasks_count) { tasks_json["relatedToAppealInactive"].length } + let(:max_new_tasks) { 4 } + let(:correspondence_appeals) { CorrespondenceAppeal.where(correspondence_id: Correspondence.first.id) } + let(:created_tasks) { correspondence_appeals.map(&:tasks).flatten } + let(:organization_assignments) do + groups_by_organization = inactive_appeal_tasks.group_by { |e| e["value"]["assigned_to"] } + groups_by_organization.each do |key, value| + new_value = value.map { |v| v["value"]["klass"] } + groups_by_organization[key] = new_value + end + end + + before do + # Need to add user to BvaDispatch - new BvaDispatch tasks are automatically assigned to users + BvaDispatch.singleton.add_user(create(:user)) + + # Visit page with inactive appeals + visit_intake_form_step_2_with_inactive_appeals + existing_appeal_radio_options[:yes].click + using_wait_time(wait_time) do + within ".cf-case-list-table" do + appeal_checkboxes = page.all(".cf-form-checkbox")[0, (inactive_appeal_tasks_count / max_new_tasks).ceil] + appeal_checkboxes.each(&:click) + end + end + + # Add a new task for each existing related to inactive appeal task + add_task_buttons = page.all("#button-addTasks") + add_task_buttons.each { |button| max_new_tasks.times { button.click } } + + # Select each unique related to inactive appeal task + react_select_containers = page.all("#reactSelectContainer") + react_select_containers.each_with_index do |select_container, index| + retry_if_not_found(cleanup: click_page_body) do + using_wait_time(wait_time) do + select_container.click + find("div", exact_text: inactive_appeal_tasks[index]["label"]).click + end + end + end + + # Fill in all the required text boxes for all tasks + task_text_content_boxes = page.all("textarea#content") + task_text_content_boxes.each { |box| box.fill_in with: "Correspondence Text" } + + click_button("Continue") + click_button("Submit") + click_button("Confirm") + using_wait_time(wait_time) do + expect(page).to have_content("You have successfully submitted a correspondence record") + end + end + + it "tasks are created and assigned to proper organization without changing appeal root task" do + created_task_strings = created_tasks.map { |task| task.class.to_s } + klasses = inactive_appeal_tasks.map { |json_obj| json_obj["value"]["klass"] } + expect(klasses).to eq(created_task_strings) + + created_tasks.each do |task| + org_klass_string = Organization.find(task.assigned_to_id).class.to_s + task_klass_string = task.class.to_s + + # BvaDispatch tasks are automatically assigned to a BvaDispatch user + if organization_assignments["BvaDispatch"].include?(task_klass_string) + expect(task.on_hold?).to eq(true) + else + expect(task.assigned?).to eq(true) + end + + expect(task.assigned_to_type).to eq("Organization") + expect(organization_assignments[org_klass_string]).to include(task_klass_string) + end + + appeals = Correspondence.first.appeals + appeals.each { |appeal| expect(appeal.active?).to eq(false) } + end + end end diff --git a/spec/support/correspondence_helpers.rb b/spec/support/correspondence_helpers.rb index 89961127c56..1aa16bf992f 100644 --- a/spec/support/correspondence_helpers.rb +++ b/spec/support/correspondence_helpers.rb @@ -193,5 +193,21 @@ def inbound_ops_team_admin_setup User.authenticate!(user: current_user) end + def retry_if_not_found(max_attempts: 3, cleanup: nil) + attempts ||= 0 + begin + yield + rescue Capybara::ElementNotFound => e + attempts += 1 + Rails.logger.warn("#{e} caught. Retry attempt: #{attempts}") + cleanup&.call + retry if attempts < max_attempts + end + end + + def click_page_body + find("body").click + end + # rubocop:enable Metrics/ModuleLength end