Skip to content

Commit 3b51863

Browse files
committed
fix: widen Contact Dates column in Prince George court report template
Resolves #6730 The contacts table in the Prince George report template had three equal-width columns (~2.2" each), making the Contact Dates column too narrow for entries with multiple dates. This caused formatting issues reported by the Prince George CASA stakeholders. Adjusted column widths to give Contact Dates ~4 inches (5760 twips) while narrowing Name and Title/Relationship to ~1.33" each. The total table width (9606 twips) is preserved. Before: Name 2.28" | Title 2.16" | Dates 2.24" After: Name 1.33" | Title 1.34" | Dates 4.00" Also added a spec to verify the template column widths and prevent regressions.
1 parent a7cb545 commit 3b51863

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
-1.1 MB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
require "zip"
5+
require "rexml/document"
6+
7+
RSpec.describe "Prince George report template" do
8+
let(:template_path) { Rails.root.join("app/documents/templates/prince_george_report_template.docx").to_s }
9+
let(:w_ns) { "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }
10+
11+
def extract_document_xml(docx_path)
12+
Zip::File.open(docx_path) do |zip|
13+
entry = zip.find_entry("word/document.xml")
14+
REXML::Document.new(entry.get_input_stream.read)
15+
end
16+
end
17+
18+
def find_contacts_table(doc)
19+
tables = REXML::XPath.match(doc, "//w:tbl", "w" => w_ns)
20+
tables.find do |tbl|
21+
text = ""
22+
REXML::XPath.each(tbl, ".//w:t", "w" => w_ns) { |t| text += t.text.to_s }
23+
text.include?("Contact Dates")
24+
end
25+
end
26+
27+
describe "contacts table column widths" do
28+
it "allocates more width to the Contact Dates column than Name or Title columns" do
29+
doc = extract_document_xml(template_path)
30+
table = find_contacts_table(doc)
31+
expect(table).not_to be_nil, "Could not find contacts table in template"
32+
33+
grid_cols = REXML::XPath.match(table, ".//w:tblGrid/w:gridCol", "w" => w_ns)
34+
expect(grid_cols.length).to eq(3)
35+
36+
widths = grid_cols.map { |col| col.attributes["w:w"].to_i }
37+
name_width, title_width, dates_width = widths
38+
39+
expect(dates_width).to be > name_width, "Contact Dates column (#{dates_width}) should be wider than Name column (#{name_width})"
40+
expect(dates_width).to be > title_width, "Contact Dates column (#{dates_width}) should be wider than Title column (#{title_width})"
41+
expect(dates_width).to be >= 5760, "Contact Dates column should be at least 4 inches (5760 twips), got #{dates_width}"
42+
end
43+
44+
it "preserves the total table width" do
45+
doc = extract_document_xml(template_path)
46+
table = find_contacts_table(doc)
47+
grid_cols = REXML::XPath.match(table, ".//w:tblGrid/w:gridCol", "w" => w_ns)
48+
total = grid_cols.sum { |col| col.attributes["w:w"].to_i }
49+
50+
expect(total).to eq(9606), "Total table width should be 9606 twips (original width), got #{total}"
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)