From 19ad7304a85c7b6309ad5f02fb52ff715f7397d9 Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Tue, 16 Oct 2018 14:50:20 +0100 Subject: [PATCH 1/4] Resolve #5 Changing the data pulled through from Typeform that is dis... --- app/models/referral.rb | 13 +++++++++++-- test/factories/referrals.rb | 14 ++++++++++---- test/models/referral_test.rb | 5 +++-- test/system/referral_review_test.rb | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/models/referral.rb b/app/models/referral.rb index c17e5e2..41541dd 100644 --- a/app/models/referral.rb +++ b/app/models/referral.rb @@ -54,8 +54,9 @@ def to_param def extract_values(array) array&.map do |hash| - hash[:text] || hash[:email] || hash[:date] || hash[:number] || - hash[:boolean] || hash[:choices] || hash[:choice] + hash[:text] || hash[:email] || hash[:date] || + hash[:number] || hash[:choices] || + parse_choice(hash[:choice]) || parse_boolean(hash[:boolean]) end end @@ -68,4 +69,12 @@ def find_state(hash) 'review' end end + + def parse_boolean(val) + { true => 'Yes', false => 'No' }[val] + end + + def parse_choice(val) + val&.fetch(:label, nil) + end end diff --git a/test/factories/referrals.rb b/test/factories/referrals.rb index 18e761a..f112cda 100644 --- a/test/factories/referrals.rb +++ b/test/factories/referrals.rb @@ -1,13 +1,19 @@ FactoryBot.define do factory :referral do - original_response { + original_response do { form_response: { calculated: { score: 0 }, - definition: { fields: [{ title: 'q1' }, { title: 'q2' }] }, - answers: [{ text: 'a1' }, { text: 'a2' }] + definition: { + fields: [ + { title: 'q1' }, { title: 'q2' }, { title: 'q3' } + ] + }, + answers: [ + { text: 'text' }, { boolean: true }, { choice: { label: 'choice' } } + ] } } - } + end end end diff --git a/test/models/referral_test.rb b/test/models/referral_test.rb index 6504a35..cfa096b 100644 --- a/test/models/referral_test.rb +++ b/test/models/referral_test.rb @@ -60,11 +60,12 @@ class ReferralTest < ActiveSupport::TestCase end test '#response_answers found' do - assert_equal({ 'q1' => 'a1', 'q2' => 'a2' }, @subject.response_answers) + answers = { 'q1' => 'text', 'q2' => 'Yes', 'q3' => 'choice' } + assert_equal(answers, @subject.response_answers) end test '#response_identifier found' do - assert_equal('a1', @subject.response_identifier) + assert_equal('text', @subject.response_identifier) end test '#response_identifier not found' do diff --git a/test/system/referral_review_test.rb b/test/system/referral_review_test.rb index c1a8474..ca13a08 100644 --- a/test/system/referral_review_test.rb +++ b/test/system/referral_review_test.rb @@ -51,7 +51,7 @@ class ReferralReviewTest < ApplicationSystemTestCase test 'lists answers' do visit referral_path(@partner, @referral) sign_in - %w[q1 a1 q2 a2].each { |t| assert_text(t) } + %w[q1 text q2 Yes q3 choice].each { |t| assert_text(t) } end test 'not signed in referrals_path' do From 5f7a27c48ccaff9f798ee0be16ff1deb213e96bd Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Tue, 16 Oct 2018 14:54:07 +0100 Subject: [PATCH 2/4] Resolve #7 Accept & Decline button switcheroo --- app/views/referrals/show.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/referrals/show.html.erb b/app/views/referrals/show.html.erb index 67313ca..2a70f91 100644 --- a/app/views/referrals/show.html.erb +++ b/app/views/referrals/show.html.erb @@ -56,18 +56,18 @@ <%= f.input :notes, placeholder: "Leave a note to explain your decision.", input_html: { class: "rounded mb20" } %>
- <% if @referral.last_state == "accepted" %> - <%= f.button :submit, "Accepted", class: "btn-wide", disabled: true %> + <% if @referral.last_state == "declined" %> + <%= f.button :submit, "Declined", class: "btn-wide", disabled: true %> <% else %> - <%= f.button :submit, "Accept", class: "confirm btn-wide", data: { disable_with: "Accepting...", confirm: "Are you sure you want to accept this referral?" } %> + <%= f.button :submit, "Decline", class: "confirm btn-invert btn-wide", data: { disable_with: "Declining...", confirm: "Are you sure you want to decline this referral?" } %> <% end %> - <% if @referral.last_state == "declined" %> - <%= f.button :submit, "Declined", class: "btn-wide", disabled: true %> + <% if @referral.last_state == "accepted" %> + <%= f.button :submit, "Accepted", class: "btn-wide", disabled: true %> <% else %> - <%= f.button :submit, "Decline", class: "confirm btn-invert btn-wide", data: { disable_with: "Declining...", confirm: "Are you sure you want to decline this referral?" } %> + <%= f.button :submit, "Accept", class: "confirm btn-wide", data: { disable_with: "Accepting...", confirm: "Are you sure you want to accept this referral?" } %> <% end %>
<% end %> From 6b3d2c5db034400ed88b2adfcf644fdb1b96e872 Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Tue, 16 Oct 2018 15:08:39 +0100 Subject: [PATCH 3/4] Resolve #4 Change font size --- app/assets/stylesheets/modules/form.sass | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/modules/form.sass b/app/assets/stylesheets/modules/form.sass index 43aef6a..6476ac0 100644 --- a/app/assets/stylesheets/modules/form.sass +++ b/app/assets/stylesheets/modules/form.sass @@ -1,20 +1,20 @@ -input +input, textarea background: $off-white + width: 100% padding: 15px + font-size: 14px + +input border: 1px solid $grey - width: 100% + +textarea + border: none label display: block font-weight: bold margin-bottom: 5px -textarea - width: 100% - background: $off-white - border: none - padding: 15px - .boolean.label display: inline-block .checkbox From b7641921bede79b6735a0ec0aab57aa3af91288c Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Tue, 16 Oct 2018 15:18:59 +0100 Subject: [PATCH 4/4] Resolve #6 Partner referral screen --- app/views/layouts/application.html.erb | 8 ++++---- app/views/referrals/new.html.erb | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6e46d2b..b43450a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,8 +11,8 @@ - <% if user_signed_in? %> - <% if alert || notice %>
diff --git a/app/views/referrals/new.html.erb b/app/views/referrals/new.html.erb index 603a5b7..517962a 100644 --- a/app/views/referrals/new.html.erb +++ b/app/views/referrals/new.html.erb @@ -1,3 +1,5 @@ +

<%= @partner.name %>

+
<% if @partner.can_accept_referrals? %> <%= tag.div(id: "typeform", data: { form_url: @partner.form_url }) %> @@ -37,7 +39,7 @@
<% if user_signed_in? && @partner.referrals.any? %> -

Sent Referrals

+

Sent Referrals

Name