Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/case_court_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified app/documents/templates/report_template_non_transition.docx
Binary file not shown.
10 changes: 2 additions & 8 deletions app/views/case_court_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@

<hr>

<%= form_with do |form| %>
<%= form_with url: "#", local: false do |form| %>
<div class="field form-group">
<%= label_tag :case_number, "Case Number:" %>
<% select_options = @assigned_cases.map { |casa_case| casa_case.decorate.court_report_select_option } %>
<%= select_tag :case_number,
options_for_select(
select_options,
{disabled: @non_transition_aged_youth_cases}
),
options_for_select(select_options),
prompt: "Select a case to generate report",
include_blank: false,
id: "case-selection",
class: "custom-select" %>

<p class="small">
* Reporting for non transition aged youth cases is coming soon!
</p>
</div>
<div class="form-group">
<%= button_tag "Generate Report", type: :submit,
Expand Down
3 changes: 3 additions & 0 deletions spec/models/case_court_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 46 additions & 26 deletions spec/system/case_court_reports/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -60,68 +61,87 @@
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
end
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}
Expand Down