Skip to content

Commit

Permalink
Add new facet to SFO finder
Browse files Browse the repository at this point in the history
  • Loading branch information
GDSNewt committed Nov 7, 2024
1 parent aacd4d5 commit 3a62be1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/sfo_case.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class SfoCase < Document
validates :sfo_case_state, presence: true
validates :sfo_case_opened_date, allow_blank: true, date: true

FORMAT_SPECIFIC_FIELDS = %i[
sfo_case_state
sfo_case_opened_date
].freeze

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
2 changes: 2 additions & 0 deletions app/views/metadata_fields/_sfo_cases.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= render layout: "shared/date_fields", locals: { f: f, field: :sfo_case_opened_date, format: :sfo_case, label: "Opened date" } do %>
<% end %>
<%= render layout: "shared/form_group", locals: { f: f, field: :sfo_case_state, label: "Case state" } do %>
<%= f.select :sfo_case_state, facet_options(f, :sfo_case_state), {}, { class: 'form-control' } %>
<% end %>
8 changes: 8 additions & 0 deletions lib/documents/schemas/sfo_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"value": "closed"
}
]
},
{
"key": "sfo_case_opened_date",
"name": "Opened date",
"short_name": "Opened date",
"type": "date",
"display_as_result_metadata": true,
"filterable": true
}
]
}
4 changes: 4 additions & 0 deletions spec/features/creating_a_sfo_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
fill_in "Summary", with: "This is the summary of an example sfo case"
fill_in "Body", with: "## Header#{"\n\nThis is the long body of an example life saving maritime appliance service station" * 2}"
select "Closed", from: "Case state"
fill_in "Opened date", with: "2023-01-01"

expect(page).to have_css("div.govspeak-help")
expect(page).to have_content("To add an attachment, please save the draft first.")
Expand Down Expand Up @@ -57,6 +58,7 @@
],
"metadata" => {
"sfo_case_state" => "closed",
"sfo_case_opened_date" => "2023-01-01",
},
"max_cache_time" => 10,
"headers" => [
Expand Down Expand Up @@ -108,6 +110,7 @@
fill_in "Title", with: "Example sfo Case"
fill_in "Summary", with: "This is the summary of an example sfo case"
fill_in "Body", with: "<script>alert('hello')</script>"
fill_in "Opened date", with: "invalid_date"

click_button "Save as draft"

Expand All @@ -118,5 +121,6 @@

expect(page).to have_content("There is a problem")
expect(page).to have_content("Body cannot include invalid Govspeak")
expect(page).to have_content("Opened date is not a valid date")
end
end
15 changes: 15 additions & 0 deletions spec/models/sfo_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
expect(sfo_case).to be_valid
end

it "is valid if the opened date is missing" do
sfo_case.sfo_case_opened_date = nil
expect(sfo_case).to be_valid
end

it "is valid if the opened date is a valid date" do
sfo_case.sfo_case_opened_date = "2023-01-01"
expect(sfo_case).to be_valid
end

it "is invalid if the case state is missing" do
sfo_case.sfo_case_state = nil
expect(sfo_case).not_to be_valid
end

it "is invalid if the opened date is not a valid date" do
sfo_case.sfo_case_opened_date = "invalid_date"
expect(sfo_case).not_to be_valid
end
end
end

0 comments on commit 3a62be1

Please sign in to comment.