Skip to content

Commit 0bd3778

Browse files
committed
Allow editing of phase values
Add a "Change" link from the school edit screen for the Phase value. Users can choose from one of the four default phase groups.
1 parent a772c50 commit 0bd3778

11 files changed

Lines changed: 152 additions & 36 deletions

File tree

app/components/app_location_search_form_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(form, url:)
88

99
private
1010

11-
PHASES = %w[nursery primary secondary other].freeze
11+
PHASES = Location::PHASES
1212

1313
attr_reader :form, :url
1414

app/components/app_school_summary_component.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,26 @@ def name_row
6262
end
6363

6464
def phase_row
65-
{
65+
row = {
6666
key: {
6767
text: "Phase"
6868
},
6969
value: {
7070
text: schoolable.human_enum_name(:phase)
7171
}
7272
}
73+
74+
if change_links[:phase]
75+
row[:actions] = [
76+
{
77+
text: change_links[:phase][:text] || "Change",
78+
href: change_links[:phase][:link],
79+
visually_hidden_text: "phase"
80+
}
81+
]
82+
end
83+
84+
row
7385
end
7486

7587
def programmes_row

app/controllers/draft_schools_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DraftSchoolsController < ApplicationController
1212
before_action :set_name, if: -> { current_step == :confirm_urn }
1313
before_action :set_address,
1414
if: -> { %i[details confirm_urn].include?(current_step) }
15+
before_action :set_phases, if: -> { current_step == :phase }
1516
before_action :set_year_groups, if: -> { current_step == :year_groups }
1617
before_action :set_back_link_path
1718

@@ -91,6 +92,10 @@ def set_name
9192
@draft_school.name ||= @draft_school.source_location&.name
9293
end
9394

95+
def set_phases
96+
@phases = Location::PHASES
97+
end
98+
9499
def set_year_groups
95100
@year_groups =
96101
Location::YearGroup::DEFAULT_VALUE_RANGE.map do |n|
@@ -231,6 +236,7 @@ def update_params
231236
address_town
232237
address_postcode
233238
],
239+
phase: [:phase],
234240
year_groups: [{ year_groups: [] }],
235241
confirm: []
236242
}.fetch(current_step)

app/models/draft_school.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DraftSchool
1414
attribute :address_town, :string
1515
attribute :address_postcode, :string
1616
attribute :selected_year_groups, default: []
17+
attribute :phase, :string
1718
attribute :context, :string
1819

1920
attr_reader :current_team
@@ -51,6 +52,7 @@ def wizard_steps
5152
(:details if add_site_context? || editing?),
5253
(:urn if add_school_context?),
5354
(:confirm_urn if add_school_context?),
55+
:phase,
5456
:year_groups,
5557
:confirm
5658
].compact
@@ -93,6 +95,10 @@ def add_site_context?
9395
validates :address_postcode, postcode: true
9496
end
9597

98+
on_wizard_step :phase, exact: true do
99+
validates :phase, presence: true, inclusion: { in: Location::PHASES }
100+
end
101+
96102
on_wizard_step :year_groups, exact: true do
97103
validates :selected_year_groups, presence: true
98104
validate :cannot_remove_year_groups
@@ -141,7 +147,7 @@ def readable_attribute_names
141147
end
142148

143149
def writable_attribute_names
144-
%w[name address_line_1 address_line_2 address_town address_postcode]
150+
%w[name address_line_1 address_line_2 address_town address_postcode phase]
145151
end
146152

147153
def resolved_urn
@@ -167,6 +173,10 @@ def next_site_letter
167173
existing_sites.max_by { [it.length, it] }.next
168174
end
169175

176+
def phase
177+
super.presence || source_location&.phase
178+
end
179+
170180
def existing_year_groups
171181
source_location&.year_groups.presence ||
172182
source_location&.gias_year_groups || []
@@ -190,7 +200,7 @@ def programmes
190200
end
191201

192202
def human_enum_name(attr)
193-
source_location&.human_enum_name(attr)
203+
Location.human_enum_name(attr, public_send(attr))
194204
end
195205

196206
def schools_with_urn

app/views/draft_schools/confirm.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
{
2525
name: { link: wizard_path(:details) },
2626
address: { link: wizard_path(:details) },
27+
phase: { link: wizard_path(:phase) },
2728
year_groups: { link: wizard_path("year-groups") },
2829
}
2930
else
30-
{ year_groups: { link: wizard_path("year-groups") } }
31+
{
32+
phase: { link: wizard_path(:phase) },
33+
year_groups: { link: wizard_path("year-groups") },
34+
}
3135
end
3236
elsif @draft_school.add_site_context?
3337
{ urn: { link: wizard_path(:school), text: "Change parent school" } }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<% content_for :before_main do %>
2+
<%= govuk_back_link(href: @back_link_path) %>
3+
<% end %>
4+
5+
<% legend = "Phase" %>
6+
<% content_for :page_title, legend %>
7+
8+
<%= form_with model: @draft_school, url: wizard_path, method: :put do |f| %>
9+
<%= f.mavis_error_summary %>
10+
<%= f.govuk_collection_radio_buttons :phase, @phases, :itself, :humanize,
11+
legend: { text: legend, size: "l", tag: "h1" },
12+
caption: { text: @draft_school.name || @draft_school.source_location&.name, size: "l" } %>
13+
14+
<%= f.govuk_submit "Continue" %>
15+
<% end %>

config/locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ en:
9494
inclusion: Choose if this is the correct school
9595
name:
9696
blank: Enter a name
97+
phase:
98+
blank: Choose a phase
99+
inclusion: Choose a phase
97100
parent_urn_and_site:
98101
blank: Choose a school
99102
selected_year_groups:
@@ -778,6 +781,8 @@ en:
778781
inclusion: Choose a GIAS phase
779782
name:
780783
blank: Enter a name
784+
phase:
785+
inclusion: Choose a phase
781786
ods_code:
782787
blank: Enter an ODS code
783788
exclusion: This ODS code is not allowed

config/locales/wicked.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ en:
3838
outcome: outcome
3939
parent: parent
4040
parent_details: parent-details
41+
phase: phase
4142
programmes: programmes
4243
programmes_check: programmes-check
4344
questions: questions

spec/components/app_school_summary_component_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
link: "/address",
5454
text: "Change address"
5555
},
56+
phase: {
57+
link: "/phase"
58+
},
5659
year_groups: {
5760
link: "/year-groups"
5861
}
@@ -62,6 +65,7 @@
6265

6366
it { should have_link("Change name", href: "/name") }
6467
it { should have_link("Change address", href: "/address") }
68+
it { should have_link("Change phase", href: "/phase") }
6569
it { should have_link("Change year groups", href: "/year-groups") }
6670
end
6771

@@ -142,6 +146,12 @@
142146
expect(rendered).to have_content("Secondary")
143147
end
144148

149+
it "shows the selected phase when overridden in the draft" do
150+
draft_school.phase = "primary"
151+
expect(rendered).to have_content("Primary")
152+
expect(rendered).not_to have_content("Secondary")
153+
end
154+
145155
it "shows programmes from the underlying location" do
146156
expect(rendered).to have_content("Programmes")
147157
expect(rendered).to have_content("HPV")

spec/features/manage_teams_spec.rb

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050

5151
when_i_confirm_the_school
5252
and_i_continue
53+
then_i_see_the_phase_screen
54+
55+
when_i_select_a_phase
56+
and_i_continue
5357
then_i_see_the_year_groups_screen
5458
and_year_groups_are_pre_selected
5559

@@ -80,6 +84,10 @@
8084

8185
when_i_fill_in_the_school_site_details
8286
and_i_continue
87+
then_i_see_the_phase_screen
88+
89+
when_i_select_a_phase
90+
and_i_continue
8391
then_i_see_the_year_groups_screen
8492
and_year_groups_are_pre_selected
8593

@@ -136,6 +144,25 @@
136144
and_the_site_details_are_updated
137145
end
138146

147+
scenario "Editing a school phase" do
148+
given_my_team_exists
149+
150+
when_i_click_on_team_settings
151+
when_i_click_on_schools
152+
153+
when_i_click_on_edit_a_school
154+
then_i_see_the_school_summary_with_phase_and_year_groups_links
155+
156+
when_i_click_on_change_phase
157+
and_i_select_a_new_phase
158+
and_i_continue
159+
then_i_see_the_phase_is_updated
160+
161+
when_i_click_save_changes
162+
then_i_see_the_team_schools
163+
and_the_school_phase_is_updated
164+
end
165+
139166
scenario "Editing a school" do
140167
given_my_team_exists
141168

@@ -144,7 +171,7 @@
144171
then_i_see_the_team_schools
145172

146173
when_i_click_on_edit_a_school
147-
then_i_see_the_school_summary_with_only_year_groups_link
174+
then_i_see_the_school_summary_with_phase_and_year_groups_links
148175

149176
when_i_click_on_change_year_groups
150177
when_i_try_to_remove_a_year_group
@@ -241,11 +268,13 @@ def then_i_see_the_school_summary_with_edit_links
241268
expect(page).to have_content("Site B")
242269
expect(page).to have_link("Change", text: /name/i)
243270
expect(page).to have_link("Change", text: /address/i)
271+
expect(page).to have_link("Change", text: /phase/i)
244272
expect(page).to have_link("Change", text: /year groups/i)
245273
end
246274

247-
def then_i_see_the_school_summary_with_only_year_groups_link
275+
def then_i_see_the_school_summary_with_phase_and_year_groups_links
248276
expect(page).to have_content(@school.name)
277+
expect(page).to have_link("Change", text: /phase/i)
249278
expect(page).to have_link("Change", text: /year groups/i)
250279
expect(page).not_to have_link("Change", text: /name/i)
251280
expect(page).not_to have_link("Change", text: /address/i)
@@ -529,4 +558,31 @@ def and_the_school_has_the_correct_year_groups
529558
@available_school.reload
530559
expect(@available_school.location_year_groups.pluck(:value)).to include(12)
531560
end
561+
562+
def then_i_see_the_phase_screen
563+
expect(page).to have_content("Phase")
564+
expect(page).to have_field("Primary", type: :radio)
565+
expect(page).to have_field("Secondary", type: :radio)
566+
end
567+
568+
def when_i_select_a_phase
569+
choose "Secondary"
570+
end
571+
572+
def when_i_click_on_change_phase
573+
click_on "Change phase"
574+
end
575+
576+
def and_i_select_a_new_phase
577+
choose "Primary"
578+
end
579+
580+
def then_i_see_the_phase_is_updated
581+
expect(page).to have_content("Primary")
582+
end
583+
584+
def and_the_school_phase_is_updated
585+
@school.reload
586+
expect(@school.phase).to eq("primary")
587+
end
532588
end

0 commit comments

Comments
 (0)