diff --git a/app/controllers/case_court_reports_controller.rb b/app/controllers/case_court_reports_controller.rb
index 89fb6f8c2c..0d05e8ff73 100644
--- a/app/controllers/case_court_reports_controller.rb
+++ b/app/controllers/case_court_reports_controller.rb
@@ -8,7 +8,6 @@ class CaseCourtReportsController < ApplicationController
def index
@assigned_cases = CasaCase.actively_assigned_to(current_user)
.select(:id, :case_number, :transition_aged_youth)
- @non_transition_aged_youth_cases = @assigned_cases&.reject(&:transition_aged_youth)&.map(&:case_number)
end
# GET /case_court_reports/:id
@@ -75,12 +74,15 @@ def path_to_template(type)
"app/documents/templates/report_template_#{type}.docx"
end
+ # Use Tempfile Utility Class to generate a temporary file from the Word template into memory
def send_report(data)
Tempfile.create do |t|
t.binmode
t.write(data)
t.rewind
t.close
+
+ # `rb` = read-binary mode
send_data File.open(t.path, "rb").read, type: :docx, disposition: "attachment", status: :ok
end
end
diff --git a/app/documents/templates/report_template_non_transition.docx b/app/documents/templates/report_template_non_transition.docx
index bcca6fe813..d8f4cf14ef 100644
Binary files a/app/documents/templates/report_template_non_transition.docx and b/app/documents/templates/report_template_non_transition.docx differ
diff --git a/app/views/case_court_reports/index.html.erb b/app/views/case_court_reports/index.html.erb
index 513cd82ac0..32f855b9d2 100644
--- a/app/views/case_court_reports/index.html.erb
+++ b/app/views/case_court_reports/index.html.erb
@@ -10,23 +10,17 @@
- <%= form_with do |form| %>
+ <%= form_with url: "#", local: false do |form| %>
<%= button_tag "Generate Report", type: :submit,
diff --git a/spec/models/case_court_report_spec.rb b/spec/models/case_court_report_spec.rb
index 169321cbb1..0c05253836 100644
--- a/spec/models/case_court_report_spec.rb
+++ b/spec/models/case_court_report_spec.rb
@@ -55,6 +55,9 @@
report.generate!
expect(File.exist?(path_to_report)).to eq true
+
+ # clean up after testing
+ File.delete(path_to_report) if File.exist?(path_to_report)
end
end
end
diff --git a/spec/system/case_court_reports/index_spec.rb b/spec/system/case_court_reports/index_spec.rb
index 751b1c5be1..b5ba44f6af 100644
--- a/spec/system/case_court_reports/index_spec.rb
+++ b/spec/system/case_court_reports/index_spec.rb
@@ -11,25 +11,26 @@
context "when first arriving to 'Generate Court Report' page, by default" do
it "sees 'Generate Report' button" do
- options = {text: "Generate Report"}
+ options = {text: "Generate Report", visible: true}
expect(page).to have_selector "#btnGenerateReport", **options
end
- it "does not see 'Download Court Report' button, which is hidden", js: true do
- options = {text: "Download Court Report", visible: :hidden}
+ it "has 'Download Court Report' button with Bootstrap class '.d-none'" do
+ options = {text: "Download Court Report", class: ["d-none"]}
expect(page).to have_selector "#btnDownloadReport", **options
end
- it "shows a select element with default selection 'Select a case to generate report'", js: true do
+ it "shows a select element with default selection 'Select a case to generate report'" do
expected_text = "Select a case to generate report"
+ find("#case-selection").click.first("option", text: expected_text).select_option
- expect(page).to have_selector "#case-selection option[value]", text: expected_text
+ expect(page).to have_selector "#case-selection option:first-of-type", text: expected_text
expect(page).to have_select "case-selection", selected: expected_text
end
- it "shows 3 options: 2 assigned case + 1 prompt text" do
+ it "shows n+1 options in total, e.g 3 options <- 2 assigned cases + 1 prompt text" do
expected_number_of_options = casa_cases.size + 1
expect(page).to have_selector "#case-selection option", count: expected_number_of_options
@@ -48,7 +49,7 @@
end
end
- context "when choosing the prompt option (value is empty) and click on 'Generate Report' button, nothing should happen" do
+ context "when choosing the prompt option (value is empty) and click on 'Generate Report' button, nothing should happen", js: true do
let(:option_text) { "Select a case to generate report" }
before do
@@ -60,26 +61,26 @@
click_button "Generate Report"
end
- context "'Generate Report' button" do
- it "does not become disabled", js: true do
+ describe "'Generate Report' button" do
+ it "does not become disabled" do
expect(page).not_to have_selector "#btnGenerateReport[disabled]"
end
- it "does not have label changed to 'Court report generating. Do not refresh or leave this page'", js: true do
+ it "does not have label changed to 'Court report generating. Do not refresh or leave this page'" do
options = {text: "Court report generating. Do not refresh or leave this page"}
expect(page).not_to have_selector "#btnGenerateReport[disabled]", **options
end
end
- context "'Download Court Report' button" do
- it "does not become visible", js: true do
+ describe "'Download Court Report' button" do
+ it "does not become visible" do
options = {text: "Download Court Report", visible: :hidden}
expect(page).to have_selector "#btnDownloadReport", **options
end
- it "does not change href value from '#'", js: true do
+ it "does not change href value from '#'" do
options = {id: "btnDownloadReport", visible: :hidden, href: "#"}
expect(page).to have_link "Download Court Report", **options
@@ -87,41 +88,60 @@
end
end
- context "when selecting transition case, volunteer can generate and download a report" do
+ describe "'Case Number' dropdown list", js: true do
+ let(:transitioned_case_number) { casa_cases.find(&:has_transitioned?).case_number.to_s }
+ let(:transitioned_option_text) { "#{transitioned_case_number} - transition" }
+ let(:non_transitioned_case_number) { casa_cases.reject(&:has_transitioned?).first.case_number.to_s }
+ let(:non_transitioned_option_text) { "#{non_transitioned_case_number} - non-transition" }
+
+ it "has transition case option selected" do
+ page.select transitioned_option_text, from: "case-selection"
+
+ click_button "Generate Report"
+
+ expect(page).to have_select "case-selection", selected: transitioned_option_text
+ end
+
+ it "has non-transitioned case option selected" do
+ page.select non_transitioned_option_text, from: "case-selection"
+
+ click_button "Generate Report"
+
+ expect(page).to have_select "case-selection", selected: non_transitioned_option_text
+ end
+ end
+
+ context "when selecting a case, volunteer can generate and download a report", js: true do
let(:case_number) { casa_cases.find(&:has_transitioned?).case_number.to_s }
- let(:transition_option_text) { "#{case_number} - transition" }
+ let(:option_text) { "#{case_number} - transition" }
before do
# to find the select element, use either 'name' or 'id' attribute
# in this case, id = "case-selection", name = "case_number"
- page.select transition_option_text, from: "case-selection"
+ page.select option_text, from: "case-selection"
click_button "Generate Report"
end
- it "has transition case option selected", js: true do
- expect(page).to have_select "case-selection", selected: transition_option_text
- end
-
- context "'Generate Report' button" do
- it "becomes disabled", js: true do
+ describe "'Generate Report' button" do
+ it "becomes disabled" do
expect(page).to have_selector "#btnGenerateReport[disabled]"
end
- it "has label changed to 'Court report generating. Do not refresh or leave this page'", js: true do
+ it "has label changed to 'Court report generating. Do not refresh or leave this page'" do
options = {text: "Court report generating. Do not refresh or leave this page"}
expect(page).to have_selector "#btnGenerateReport[disabled]", **options
end
end
- context "'Download Court Report' button" do
- it "becomes visible", js: true do
+ describe "'Download Court Report' button" do
+ it "becomes visible" do
options = {text: "Download Court Report", visible: :visible}
expect(page).to have_selector "#btnDownloadReport", **options
end
- it "changes href value from '#' to a link with .docx format", js: true do
+ it "changes href value from '#' to a link with .docx format" do
download_link = "/case_court_reports/#{case_number}.docx"
options = {id: "btnDownloadReport", visible: :visible, href: download_link}