Skip to content

Commit

Permalink
Merge pull request #3278 from DFE-Digital/remove-degree-autocomplete
Browse files Browse the repository at this point in the history
Removing DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED feature flag
  • Loading branch information
martyn-w authored Sep 30, 2024
2 parents c66bea4 + 423c3b8 commit c796da1
Show file tree
Hide file tree
Showing 32 changed files with 367 additions and 151 deletions.
2 changes: 0 additions & 2 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ DFE_SIGNIN_API_ENABLED="1"
DFE_SIGNIN_API_SCHOOL_CHANGE_ENABLED="1"
GTM_ID=GTM-W3VGWP6
BIGQUERY_DATASET=gse_events_production

DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=1
2 changes: 0 additions & 2 deletions .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ DFE_SIGNIN_API_ENABLED="1"
DFE_SIGNIN_API_SCHOOL_CHANGE_ENABLED="1"
GTM_ID=GTM-PN3BPDM
BIGQUERY_DATASET=gse_events_staging

DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=1
2 changes: 0 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Add public environment variables here for the Test environment
SECRET_KEY_BASE=stubbed

DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=1
36 changes: 8 additions & 28 deletions app/services/candidates/registrations/behaviours/education.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ module Education
validates :degree_stage, inclusion: { in: :available_degree_stages }, if: -> { degree_stage.present? }
validates :degree_stage_explaination, presence: true, if: :degree_stage_explaination_required?

# if DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=true (degree_subject_autocomplete?)
# + if javascript is disabled (nojs?), then
validates :degree_subject_nojs, presence: true, if: -> { degree_subject_autocomplete? && nojs? && degree_stage_requires_subject? }
validates :degree_subject_nojs, absence: true, if: -> { degree_subject_autocomplete? && nojs? && !degree_stage_requires_subject? }

# # + else if javascript is enabled (js?), then
validates :degree_subject, presence: true, if: -> { degree_subject_autocomplete? && js? && degree_stage_requires_subject? }
validates :degree_subject, absence: true, if: -> { degree_subject_autocomplete? && js? && !degree_stage_requires_subject? }

# if DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=false (degree_subject_simple?)
validates :degree_subject, presence: true, if: -> { degree_subject_simple? && degree_stage_requires_subject? }
validates :degree_subject, inclusion: { in: :available_degree_subjects }, if: -> { degree_subject_simple? && degree_stage_requires_subject? }
validates :degree_subject, inclusion: [NO_DEGREE_SUBJECT], if: -> { degree_subject_simple? && degree_stage_requires_n_a_subject? }
validates :degree_subject, exclusion: [NO_DEGREE_SUBJECT], if: -> { degree_subject_simple? && degree_stage_requires_subject_in_subjects_list? }
# if javascript is disabled (nojs?), then
validates :degree_subject_nojs, presence: true, if: -> { nojs? && degree_stage_requires_subject? }
validates :degree_subject_nojs, absence: true, if: -> { nojs? && !degree_stage_requires_subject? }

# else if javascript is enabled (js?), then
validates :degree_subject, presence: true, if: -> { js? && degree_stage_requires_subject? }
validates :degree_subject, absence: true, if: -> { js? && !degree_stage_requires_subject? }
end

def js?
Expand All @@ -43,12 +36,7 @@ def available_degree_stages
end

def available_degree_subjects
@available_degree_subjects ||=
if degree_subject_autocomplete?
DfE::ReferenceData::Degrees::SUBJECTS.all
else
OPTIONS_CONFIG.fetch 'DEGREE_SUBJECTS'
end
@available_degree_subjects ||= DfE::ReferenceData::Degrees::SUBJECTS.all
end

def requires_subject_for_degree_stage?(some_degree_stage)
Expand All @@ -63,14 +51,6 @@ def no_degree_subject
NO_DEGREE_SUBJECT
end

def degree_subject_autocomplete?
@degree_subject_autocomplete ||= ActiveModel::Type::Boolean.new.cast(ENV.fetch("DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED", false))
end

def degree_subject_simple?
!degree_subject_autocomplete?
end

private

def degree_stage_requires_subject?
Expand Down
61 changes: 21 additions & 40 deletions app/views/candidates/registrations/educations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,27 @@
</section>

<section id="education-degree-subject-container" data-education-form-target="degreeSubjectContainer">
<% if f.object.degree_subject_autocomplete? %>
<%= f.hidden_field :nojs, value: true, class: 'nojs-flag' %>

<div id="degree_subject_nojs" class="hide-with-javascript">
<!-- no-javascript version of autocomplete box -->
<%=f.govuk_text_field :degree_subject_nojs, label: { size: 'm' } %>
</div>

<%= render DfE::Autocomplete::View.new(
f,
attribute_name: :degree_subject,
form_field: f.govuk_select(
:degree_subject,
options_for_select(dfe_autocomplete_options( f.object.available_degree_subjects), f.object.degree_subject),
label: { text: t('helpers.legend.candidates_registrations_education.degree_subject'), size: 'm', tag: 'h2' },
hint: { text: t('helpers.hint.candidates_registrations_education.degree_subject') },
data: { education_form_target: 'degreeSubject' },
class: "enable-with-javascript",
disabled: true,
),
classes: "show-with-javascript",
) %>
<% else %>
<%= f.govuk_collection_select \
:degree_subject,
f.object.available_degree_subjects,
:to_s,
:to_s,
options: { prompt: "Select" },
data: {
education_form_target: 'degreeSubject',
value_for_no_degree: f.object.no_degree_subject
},
class: "govuk-select govuk-!-width-one-half",
label: { class: "govuk-heading-m" } do %>
<p>
Select the nearest or equivalent subject.
</p>
<% end %>
<% end %>
<%= f.hidden_field :nojs, value: true, class: 'nojs-flag' %>

<div id="degree_subject_nojs" class="hide-with-javascript">
<!-- no-javascript version of autocomplete box -->
<%=f.govuk_text_field :degree_subject_nojs, label: { size: 'm' } %>
</div>

<%= render DfE::Autocomplete::View.new(
f,
attribute_name: :degree_subject,
form_field: f.govuk_select(
:degree_subject,
options_for_select(dfe_autocomplete_options( f.object.available_degree_subjects), f.object.degree_subject),
label: { text: t('helpers.legend.candidates_registrations_education.degree_subject'), size: 'm', tag: 'h2' },
hint: { text: t('helpers.hint.candidates_registrations_education.degree_subject') },
data: { education_form_target: 'degreeSubject' },
class: "enable-with-javascript",
disabled: true,
),
classes: "show-with-javascript",
) %>
</section>

<%= f.govuk_submit 'Continue' %>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"devDependencies": {
"babel-plugin-dynamic-import-node": "^2.3.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"webpack-dev-server": "4"
},
"jest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe Candidates::Registrations::BackgroundChecksController, type: :request do
include_context 'Stubbed current_registration'
include_context "Degree subject autocomplete enabled"

before do
FactoryBot.create :bookings_school, urn: 11_048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe Candidates::Registrations::ConfirmationEmailsController, type: :request do
include_context 'Stubbed candidates school'
include_context 'Stubbed current_registration'
include_context "Degree subject autocomplete enabled"

let :registration_session do
FactoryBot.build :registration_session, urn: school.urn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe Candidates::Registrations::EducationsController, type: :request do
include_context 'Stubbed current_registration'
include_context "Degree subject autocomplete enabled"

let :registration_session do
FactoryBot.build :registration_session, with: %i[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe Candidates::Registrations::PlacementPreferencesController, type: :request do
include_context 'Stubbed candidates school'
include_context 'Stubbed current_registration'
include_context "Degree subject autocomplete enabled"

let :registration_session do
FactoryBot.build :registration_session, with: %i[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ArchivedPlacementRequestsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let(:school) { Bookings::School.find_by! urn: urn }
let!(:profile) { create :bookings_profile, school: school }
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/schools/attendances_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::AttendancesController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let! :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::CancelledBookingsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let! :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ConfirmAttendanceController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let(:school) { Bookings::School.find_by(urn: urn) }
let!(:profile) { create(:bookings_profile, school: school) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ConfirmedBookings::Cancellations::NotificationDeliveriesController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ConfirmedBookings::CancellationsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ConfirmedBookings::DateController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let(:booking) do
create(:bookings_booking, :accepted, bookings_school: @current_user_school)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::ConfirmedBookingsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let! :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::Acceptance::ConfirmBookingController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let!(:pr) { create(:bookings_placement_request, school: @current_user_school) }
before { create(:bookings_profile, school: @current_user_school) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::Acceptance::MakeChangesController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let!(:pr) { create(:bookings_placement_request, school: @current_user_school) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::Acceptance::PreviewConfirmationEmailController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school_experience do
instance_double(Bookings::Gitis::SchoolExperience)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::Cancellations::NotificationDeliveriesController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::CancellationsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::PastAttendanceController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let(:school) { Bookings::School.find_by! urn: urn }
let!(:profile) { create :bookings_profile, school: school }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PlacementRequests::UnderConsiderationController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

describe '#place_under_consideration' do
include_context "logged in DfE user"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
describe Schools::PlacementRequestsController, type: :request do
include ActiveSupport::Testing::TimeHelpers
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by! urn: urn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::PreviousBookingsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let! :school do
Bookings::School.find_by!(urn: urn).tap do |s|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::RejectedRequestsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |school|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

describe Schools::WithdrawnRequestsController, type: :request do
include_context "logged in DfE user"
include_context "Degree subject autocomplete enabled"

let :school do
Bookings::School.find_by!(urn: urn).tap do |school|
Expand Down
31 changes: 0 additions & 31 deletions spec/services/candidates/registrations/education_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,4 @@
end
end
end

describe '#degree_subject_autocomplete?' do
before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED", false).and_return(degree_subject_autocomplete_flag)
end

context "when DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED is not set" do
let(:degree_subject_autocomplete_flag) { nil }

it "returns false" do
expect(subject).not_to be_degree_subject_autocomplete
end
end

context "when DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=0" do
let(:degree_subject_autocomplete_flag) { "0" }

it "returns false" do
expect(subject).not_to be_degree_subject_autocomplete
end
end

context "when DEGREE_SUBJECT_AUTOCOMPLETE_ENABLED=1" do
let(:degree_subject_autocomplete_flag) { "1" }

it "returns true" do
expect(subject).to be_degree_subject_autocomplete
end
end
end
end
17 changes: 0 additions & 17 deletions spec/support/degree_subject_autocomplete.rb

This file was deleted.

Loading

0 comments on commit c796da1

Please sign in to comment.