Skip to content

Commit

Permalink
Make smart answers optional (#136)
Browse files Browse the repository at this point in the history
* Make smart answers optional

https://eaflood.atlassian.net/browse/WC-275

In order to reduce the number of pages users have to go through, and to give more choice for those who have good knowledge of what the difference is between lower and upper tier, we will make smart answers optional.

We have already tested this in user research without issue, and the team feels it better highlights that smart answers is an aid and not an approval or clarification of what users can do (which testing has shown some view it as).

This story covers implementing the version contained in the prototype into the production renewals service.

* Scaffold the new tier_check_form

* Set up and persist the tier check form

Add text and form fields, and store the user's answer so we can prefill the form if they return to it.

The tier check form uses a new temporary attribute called temp_tier_check for the answer - this will be used for routing into or around smart answers in the future. Adding that routing is the next step.

Also update the .gitignore to get rid of pesky .DS_Store files.

* Add missing error message

* Route around smart answers based on tier check answer

If a user asks to skip smart answers, route them straight to the CBD type page instead.

If a user tries to go back from the CBD page, cehck if they have skipped smart answers and send them straight back to the tier check page if so. Otherwise, send them back through the smart answers route they came from, just as we did before.
  • Loading branch information
irisfaraway committed Apr 23, 2018
1 parent b4adf6a commit b80732e
Show file tree
Hide file tree
Showing 21 changed files with 559 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
# Ignore logfiles, tempfiles and OS-specific files
/log/*
!/log/.keep
/tmp
.DS_Store

# Ignore test coverage reports
/coverage
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/tier_check_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TierCheckFormsController < FormsController
def new
super(TierCheckForm, "tier_check_form")
end

def create
super(TierCheckForm, "tier_check_form")
end
end
18 changes: 18 additions & 0 deletions app/forms/tier_check_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class TierCheckForm < BaseForm
attr_accessor :temp_tier_check

def initialize(transient_registration)
super
self.temp_tier_check = @transient_registration.temp_tier_check
end

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.temp_tier_check = convert_to_boolean(params[:temp_tier_check])
attributes = { temp_tier_check: temp_tier_check }

super(attributes, params[:reg_identifier])
end

validates :temp_tier_check, inclusion: { in: [true, false] }
end
25 changes: 22 additions & 3 deletions app/models/concerns/can_change_workflow_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module CanChangeWorkflowStatus

state :business_type_form

state :tier_check_form
state :other_businesses_form
state :service_provided_form
state :construction_demolition_form
Expand Down Expand Up @@ -97,14 +98,21 @@ module CanChangeWorkflowStatus
if: :switch_to_lower_tier_based_on_business_type?

transitions from: :business_type_form,
to: :other_businesses_form,
to: :tier_check_form,
if: :business_type_change_valid?

transitions from: :business_type_form,
to: :cannot_renew_type_change_form

# Smart answers

transitions from: :tier_check_form,
to: :cbd_type_form,
if: :skip_tier_check?

transitions from: :tier_check_form,
to: :other_businesses_form

transitions from: :other_businesses_form,
to: :construction_demolition_form,
if: :only_carries_own_waste?
Expand Down Expand Up @@ -274,13 +282,16 @@ module CanChangeWorkflowStatus

# Smart answers

transitions from: :other_businesses_form,
transitions from: :tier_check_form,
to: :location_form,
if: :based_overseas?

transitions from: :other_businesses_form,
transitions from: :tier_check_form,
to: :business_type_form

transitions from: :other_businesses_form,
to: :tier_check_form

transitions from: :service_provided_form,
to: :other_businesses_form

Expand All @@ -294,6 +305,10 @@ module CanChangeWorkflowStatus
transitions from: :construction_demolition_form,
to: :service_provided_form

transitions from: :cbd_type_form,
to: :tier_check_form,
if: :skip_tier_check?

transitions from: :cbd_type_form,
to: :construction_demolition_form,
if: :only_carries_own_waste?
Expand Down Expand Up @@ -463,6 +478,10 @@ def require_new_registration_based_on_company_no?
old_company_no != company_no
end

def skip_tier_check?
temp_tier_check == false
end

def only_carries_own_waste?
other_businesses == false
end
Expand Down
1 change: 1 addition & 0 deletions app/models/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TransientRegistration
field :temp_company_postcode, type: String
field :temp_contact_postcode, type: String
field :temp_os_places_error, type: Boolean
field :temp_tier_check, type: Boolean

# Check if the user has changed the registration type, as this incurs an additional 40GBP charge
def registration_type_changed?
Expand Down
66 changes: 66 additions & 0 deletions app/views/tier_check_forms/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<%= render("shared/back", back_path: back_tier_check_forms_path(@tier_check_form.reg_identifier)) %>

<div class="text">
<%= form_for(@tier_check_form) do |f| %>
<%= render("shared/errors", object: @tier_check_form) %>

<h1 class="heading-large"><%= t(".heading") %></h1>

<p><%= t(".paragraph_1") %></p>
<p><%= t(".paragraph_2") %></p>
<p><%= t(".paragraph_3") %></p>

<div class="form-group">
<details>
<summary>
<span class="summary"><%= t(".tier_details_subheading") %></span>
</summary>
<div class="panel panel-border-narrow">
<p><%= t(".tier_details_paragraph_1") %></p>
<p class="strong"><%= t(".tier_details_paragraph_2") %></p>
<ul class="list list-bullet">
<% t(".tier_details_list_1").each do |item| %>
<li><%= item[:item] %></li>
<% end %>
</ul>
<p class="strong"><%= t(".tier_details_paragraph_3") %></p>
<ul class="list list-bullet">
<% t(".tier_details_list_2").each do |item| %>
<li><%= item[:item] %></li>
<% end %>
</ul>
</div>
</details>
</div>

<% if @tier_check_form.errors[:temp_tier_check].any? %>
<div class="form-group form-group-error">
<% else %>
<div class="form-group">
<% end %>
<fieldset id="temp_tier_check">
<legend class="visuallyhidden">
<%= t(".heading") %>
</legend>

<% if @tier_check_form.errors[:temp_tier_check].any? %>
<span class="error-message"><%= @tier_check_form.errors[:temp_tier_check].join(", ") %></span>
<% end %>

<div class="multiple-choice">
<%= f.radio_button :temp_tier_check, "true" %>
<%= f.label :temp_tier_check, t(".options.true"), value: "true" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :temp_tier_check, "false" %>
<%= f.label :temp_tier_check, t(".options.false"), value: "false" %>
</div>
</fieldset>
</div>

<%= f.hidden_field :reg_identifier, value: @tier_check_form.reg_identifier %>
<div class="form-group">
<%= f.submit t(".next_button"), class: "button" %>
</div>
<% end %>
</div>
35 changes: 35 additions & 0 deletions config/locales/forms/tier_check_forms/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
en:
tier_check_forms:
new:
title: Check your tier
heading: You are renewing an upper tier registration
paragraph_1: "If you're not sure if you should be upper or lower tier, you can answer a few questions about your business's activities to check."
paragraph_2: The questions only relate to your business activities and what type of waste you currently deal with.
paragraph_3: "Upper tier registrations need to be renewed every 3 years for a cost. Lower tier registrations are free and don’t expire."
tier_details_subheading: "What’s the difference between upper and lower tier?"
tier_details_paragraph_1: This depends on what waste you deal with and who creates it.
tier_details_paragraph_2: "You need an upper tier registration if you do any of the following:"
tier_details_list_1:
- item: transport other people's waste (for example, a skip company)
- item: carry construction or demolition waste
- item: buy and/or sell waste or arrange for others to carry it
tier_details_paragraph_3: "If your activities are limited to the categories below, you only need a lower tier registration:"
tier_details_list_2:
- item: "You ONLY deal with waste you produce in the course of carrying out your business – for example, a hairdresser dealing with hair clippings. This does not include construction or demolition waste"
- item: "You ONLY deal with waste from mines or quarries, from agricultural premises, or animal by-products"
options:
"true": I want to check if my tier is correct before renewing
"false": I am happy to skip this check
error_heading: Something is wrong
next_button: Continue
activemodel:
errors:
models:
tier_check_form:
attributes:
temp_tier_check:
inclusion: "You must answer this question"
reg_identifier:
invalid_format: "The registration ID is not in a valid format"
no_registration: "There is no registration matching this ID"
renewal_in_progress: "This renewal is already in progress"
10 changes: 10 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
on: :collection
end

resources :tier_check_forms,
only: [:new, :create],
path: "tier-check",
path_names: { new: "/:reg_identifier" } do
get "back/:reg_identifier",
to: "tier_check_forms#go_back",
as: "back",
on: :collection
end

resources :other_businesses_forms,
only: [:new, :create],
path: "other-businesses",
Expand Down
4 changes: 2 additions & 2 deletions spec/cassettes/contact_postcode_form_modified_postcode.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/cassettes/contact_postcode_form_no_matches_postcode.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/cassettes/contact_postcode_form_valid_postcode.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions spec/factories/forms/tier_check_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :tier_check_form do
trait :has_required_data do
temp_tier_check false

initialize_with { new(create(:transient_registration, :has_required_data, workflow_state: "tier_check_form")) }
end
end
end
2 changes: 1 addition & 1 deletion spec/forms/declare_convictions_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

context "when a declared_convictions is false" do
before(:each) do
declare_convictions_form.declared_convictions = true
declare_convictions_form.declared_convictions = false
end

it "is valid" do
Expand Down
Loading

0 comments on commit b80732e

Please sign in to comment.