Skip to content

Commit

Permalink
feat(cms): add internal business project to case summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Serena Abbott authored and Serena Abbott committed Oct 27, 2023
1 parent 1e2cdff commit 48fd93a
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/controllers/support/cases/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def form_params
:query_id,
:other_query,
:source,
:project,
:value,
:support_level,
:procurement_stage_id,
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/support/case_summary_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ module CaseSummaryHelper
def available_sources
I18nOption.from("support.case.label.source.%%key%%", Support::Case.sources.keys)
end

def available_projects
Support::Case.distinct.pluck(:project).compact
end

def project_grouped_options
[["Existing projects", available_projects], ["Or", ["Add new project"]]]
end
end
end
29 changes: 29 additions & 0 deletions app/javascript/request/add_project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
window.addEventListener("load", () => {
const projectSelect = document.getElementById("select_project");
projectSelect.addEventListener("change", toggleNewProjectTextVisibility);
toggleNewProjectTextVisibility.bind(projectSelect)();
});

function changeNewProjectTextState(state) {
const newProjectText = document.getElementById("new_project_text");

if (state == "hidden") {
newProjectText.value = '';
newProjectText.classList.add("govuk-!-display-none");
newProjectText.parentNode.childNodes[0].classList.add("govuk-!-display-none");
newProjectText.setAttribute("disabled", true);

} else if (state == "visible") {
newProjectText.classList.remove("govuk-!-display-none");
newProjectText.parentNode.childNodes[0].classList.remove("govuk-!-display-none");
newProjectText.removeAttribute("disabled");
}
}

function toggleNewProjectTextVisibility() {
if (this.options[this.selectedIndex].text == 'Add new project') {
changeNewProjectTextState("visible");
} else {
changeNewProjectTextState("hidden");
}
}
1 change: 1 addition & 0 deletions app/models/support/case/summarisable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def summary_defaults
procurement_stage_id:,
value:,
source:,
project:,
next_key_date:,
next_key_date_description:,
}
Expand Down
2 changes: 2 additions & 0 deletions app/models/support/case/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Support::Case::Summary
attribute :procurement_stage_id
attribute :value
attribute :source
attribute :project
attribute :next_key_date
attribute :next_key_date_description

Expand Down Expand Up @@ -42,6 +43,7 @@ def save!
procurement_stage_id:,
value:,
source:,
project:,
next_key_date:,
next_key_date_description:,
)
Expand Down
14 changes: 14 additions & 0 deletions app/views/support/cases/show/_case_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@
<dd class="govuk-summary-list__actions"></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.project.header") %>
</dt>
<dd class="govuk-summary-list__value">
<% if current_case.project.present? %>
<%= current_case.project %>
<% else %>
<%= I18n.t("support.case.label.project.unspecified") %>
<% end %>
</dd>
<dd class="govuk-summary-list__actions"></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.problem_description") %>
Expand Down
28 changes: 26 additions & 2 deletions app/views/support/cases/summaries/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= javascript_include_tag "request/add_project" %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= I18n.t("support.case_summary.edit.header") %></h1>
Expand All @@ -7,6 +9,13 @@
url: support_case_summary_path(@current_case),
method: :patch, class: "govuk-!-display-inline",
html: { "data-controller" => "case-summary", "data-case-summary-case-stage-outlet" => ".case-stage-fields", "data-case-summary-request-type-outlet" => ".request-type-radios" } do |form| %>

<%
new_project_hidden = unless form.object.project == "Add new project"
"govuk-!-display-none"
end
%>

<%= form.govuk_error_summary %>

<%= render "support/cases/request_details/form_fields", form: form %>
Expand All @@ -19,11 +28,26 @@
options_for_select(available_sources.map { |s| [s.title, s.id] },
form.object.source),
options: { include_blank: I18n.t("support.case_summary.edit.source.blank") },
label: { text: I18n.t("support.case_summary.edit.source.label"), size: "m" } %>
label: { text: I18n.t("support.case_summary.edit.source.label"), size: "m" },
disabled: true %>

<%= form.hidden_field :source, value: form.object.source %>

<%= form.govuk_select :project,
grouped_options_for_select(project_grouped_options, form.object.project),
id: "select_project",
options: { include_blank: I18n.t("support.case_summary.edit.project.blank") },
label: { text: I18n.t("support.case_summary.edit.project.label"), size: "m", for: "select_project" } %>

<%= form.govuk_text_field :project,
class: "#{new_project_hidden} govuk-input",
id: "new_project_text",
label: { text: I18n.t("support.case_summary.edit.project.new_project"), class: "#{new_project_hidden} govuk-label", for: "new_project_text"} %>

<%= render "support/cases/components/next_key_date", form: form %>

<%= form.button I18n.t("support.case_summary.edit.submit"), class: "govuk-button", role: "button", value: "confirm", "data-action": "case-summary#submit" %>
<% end %>
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions app/views/support/cases/summaries/update.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
</dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.project.header") %>
</dt>
<dd class="govuk-summary-list__value">
<% if @case_summary.project.present? %>
<%= @case_summary.project %>
<% else %>
<%= I18n.t("support.case.label.project.unspecified") %>
<% end %>
</dd>
<dd class="govuk-summary-list__actions">
<%= form.button I18n.t("support.case_request_details.check_answers.change"), class: "govuk-link link-styled-button", value: "change" %>
</dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.next_key_date.label") %>
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,9 @@ en:
schools_commercial_team: Schools Commercial Team (SCT)
sw_hub: South West (SW) Hub
unspecified: "-"
project:
header: "Project"
unspecified: "-"
discovery_method:
legend: Case origin
field: Origin
Expand Down Expand Up @@ -1475,6 +1478,11 @@ en:
source:
blank: Please select
label: Case source
project:
add_new_project: Add new project
blank: Please select
label: Case project
new_project: New project
flash:
updated: Case summary successfully updated
invalid_date: Provide a valid date
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231018135128_add_project_to_support_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProjectToSupportCase < ActiveRecord::Migration[7.0]
def change
add_column :support_cases, :project, :string
end
end
9 changes: 5 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_10_10_122627) do
ActiveRecord::Schema[7.0].define(version: 2023_10_18_135128) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -340,8 +340,8 @@
t.string "title"
t.text "body"
t.string "slug"
t.datetime "created_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.string "contentful_id"
t.text "sidebar"
t.string "breadcrumbs", default: [], array: true
Expand Down Expand Up @@ -517,6 +517,7 @@
t.string "next_key_date_description"
t.integer "discovery_method"
t.string "discovery_method_other_text"
t.string "project"
t.index ["category_id"], name: "index_support_cases_on_category_id"
t.index ["existing_contract_id"], name: "index_support_cases_on_existing_contract_id"
t.index ["new_contract_id"], name: "index_support_cases_on_new_contract_id"
Expand Down Expand Up @@ -761,7 +762,7 @@
t.string "ukprn"
t.string "telephone_number"
t.jsonb "local_authority"
t.datetime "opened_date", precision: nil
t.datetime "opened_date"
t.string "number"
t.string "rsc_region"
t.string "trust_name"
Expand Down
33 changes: 29 additions & 4 deletions spec/features/support/agent_can_change_case_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "Agent can change case summary", js: true do
include_context "with an agent"

let(:support_case) { create(:support_case, support_level: :L1, value: nil, source: "nw_hub", category: gas_category, procurement_stage: need_stage) }
let(:support_case) { create(:support_case, support_level: :L1, value: nil, source: "nw_hub", project: "test project", category: gas_category, procurement_stage: need_stage) }

before do
define_basic_categories
Expand All @@ -17,12 +17,12 @@
end
end

context "when changing the support level, procurement stage, case value, case source, and next key date" do
context "when changing the support level, procurement stage, case value, case project, and next key date" do
before do
choose "4 - DfE buying through a framework"
select "Tender preparation", from: "Procurement stage"
fill_in "Case value or estimated contract value (optional)", with: "123.32"
select "Email", from: "Case source"
select "Please select", from: "select_project"
fill_in "Day", with: "10"
fill_in "Month", with: "08"
fill_in "Year", with: "2023"
Expand All @@ -35,7 +35,8 @@
expect(support_case.reload.support_level).to eq("L4")
expect(support_case.reload.procurement_stage.key).to eq("tender_preparation")
expect(support_case.reload.value).to eq(123.32)
expect(support_case.reload.source).to eq("incoming_email")
expect(support_case.reload.source).to eq("nw_hub")
expect(support_case.reload.project).to eq(nil)
expect(support_case.reload.next_key_date).to eq(Date.parse("2023-08-10"))
expect(support_case.reload.next_key_date_description).to eq("Key event")
end
Expand Down Expand Up @@ -65,4 +66,28 @@
end
end
end

describe "Agent can add a new project" do
before do
select "Add new project", from: "select_project"
find("#new_project_text").set("brand new project")
click_continue
end

it "allows the user to check their answers" do
within ".govuk-summary-list__row", text: "Project" do
expect(page).to have_content("brand new project")
end
end

describe "submitting results" do
it "shows the new project in case details" do
click_button "Save"

within ".govuk-summary-list__row", text: "Project" do
expect(page).to have_content("brand new project")
end
end
end
end
end
5 changes: 3 additions & 2 deletions spec/features/support/case_tabs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
expect(all(".govuk-summary-list__row")[2]).to have_text "Case value"
expect(all(".govuk-summary-list__row")[3]).to have_text "Origin"
expect(all(".govuk-summary-list__row")[4]).to have_text "Source"
expect(all(".govuk-summary-list__row")[5]).to have_text "Description of query"
expect(all(".govuk-summary-list__row")[6]).to have_text "Next key date and description"
expect(all(".govuk-summary-list__row")[5]).to have_text "Project"
expect(all(".govuk-summary-list__row")[6]).to have_text "Description of query"
expect(all(".govuk-summary-list__row")[7]).to have_text "Next key date and description"
end
end

Expand Down

0 comments on commit 48fd93a

Please sign in to comment.