Skip to content

Commit

Permalink
Kev ma/appeals 56226 (#23343)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Kevma50287 and SanthiParakal133 authored Oct 25, 2024
1 parent cd5de70 commit 3bf67fc
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
81 changes: 81 additions & 0 deletions spec/feature/queue/correspondence/submit_intake_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/support/correspondence_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3bf67fc

Please sign in to comment.