Matthew Phelan
3 years ago
17 changed files with 154 additions and 55 deletions
@ -1,2 +1,2 @@
|
||||
DB_USERNAME:postgres-user |
||||
DB_PASSWORD:postgres-password |
||||
DB_USERNAME=postgres-user |
||||
DB_PASSWORD=postgres-password |
||||
|
@ -0,0 +1,7 @@
|
||||
class AddPostcodeToCaseLogs < ActiveRecord::Migration[6.1] |
||||
def change |
||||
change_table :case_logs, bulk: true do |t| |
||||
t.column :postcode, :string |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
### ADR - 003: Form Submission Flow |
||||
|
||||
Turbo Frames (https://github.com/hotwired/turbo-rails) for form pages/questions with data saved (but not necessarily fully validated) to Active Record model on each submit. |
||||
|
||||
|
||||
#### Impact on Performance |
||||
|
||||
Using Turbo Frames allows us to swap out just the question part of the page without needing full page refreshes as you go through the form and provides a "Single Page Application like" user experience. Each question still gets a unique URL that can be navigated to directly with the Case Log ID and the overall user experience is that form navigation feels faster. |
||||
|
||||
#### Impact on interrupted sessions |
||||
|
||||
We currently have a single Active Record model for Case Logs that contains all the question fields. Every time a question is submitted the answer will be saved in the Active Record model instance before the next frame is rendered. This model will need to be able to handle partial records and partial validation anyway since not all API users will have all the required data. Validation can occur based on the data already saved and/or once the form is finally submitted. Front end validation will still happen additionally as you go through the form to help make sure users don't get a long list of errors at the end. Using session data here and updating the model only once the form is completed would not seem to have any advantages over this approach. |
||||
|
||||
This means that when a user navigates away from the form or closes the tab etc, they can use the URL to navigate directly back to where they left off, or follow the form flow through again, and in both cases their submitted answers will still be there. |
||||
|
||||
|
||||
#### Impact on API |
||||
|
||||
The API will still expect to take a JSON describing the case log, instantiate the model with the given fields, and run validations as if it had been submitted. |
@ -1,6 +1,17 @@
|
||||
FactoryBot.define do |
||||
factory :case_log do |
||||
id { 342_351 } |
||||
status { 0 } |
||||
sequence(:id) { |i| i } |
||||
trait :in_progress do |
||||
status { 0 } |
||||
tenant_code { "TH356" } |
||||
postcode { "SW2 6HI" } |
||||
end |
||||
trait :submitted do |
||||
status { 1 } |
||||
tenant_code { "BZ737" } |
||||
postcode { "NW1 7TY" } |
||||
end |
||||
created_at { Time.zone.now } |
||||
updated_at { Time.zone.now } |
||||
end |
||||
end |
||||
|
@ -0,0 +1,42 @@
|
||||
require "rails_helper" |
||||
RSpec.describe "case_logs/index" do |
||||
let(:in_progress_log) { FactoryBot.build(:case_log, :in_progress) } |
||||
let(:submitted_log) { FactoryBot.build(:case_log, :submitted) } |
||||
|
||||
context "given an in progress log list" do |
||||
it "renders a table for in progress logs only" do |
||||
assign(:in_progress_case_logs, [in_progress_log]) |
||||
assign(:submitted_case_logs, []) |
||||
render |
||||
expect(rendered).to match(/<table class="govuk-table">/) |
||||
expect(rendered).to match(/Logs you need to complete/) |
||||
expect(rendered).not_to match(/Logs you've submitted/) |
||||
expect(rendered).to match(in_progress_log.tenant_code) |
||||
expect(rendered).to match(in_progress_log.postcode) |
||||
end |
||||
end |
||||
|
||||
context "given a submitted log list" do |
||||
it "renders a table for in progress logs only" do |
||||
assign(:in_progress_case_logs, []) |
||||
assign(:submitted_case_logs, [submitted_log]) |
||||
render |
||||
expect(rendered).to match(/<table class="govuk-table">/) |
||||
expect(rendered).to match(/Logs you've submitted/) |
||||
expect(rendered).not_to match(/Logs you need to complete/) |
||||
expect(rendered).to match(submitted_log.tenant_code) |
||||
expect(rendered).to match(submitted_log.postcode) |
||||
end |
||||
end |
||||
|
||||
context "given a submitted log list and an in_progress log list" do |
||||
it "renders two tables, one for each status" do |
||||
assign(:in_progress_case_logs, [in_progress_log]) |
||||
assign(:submitted_case_logs, [submitted_log]) |
||||
render |
||||
expect(rendered).to match(/<table class="govuk-table">/) |
||||
expect(rendered).to match(/Logs you've submitted/) |
||||
expect(rendered).to match(/Logs you need to complete/) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue