Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kev ma/appeals 56226 #23343

Merged
merged 15 commits into from
Oct 25, 2024
Merged
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

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
Loading