|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe "Edit parent" do |
| 4 | + before { given_a_patient_with_a_parent_exists } |
| 5 | + |
| 6 | + scenario "User edits the name of a parent" do |
| 7 | + when_i_visit_the_patient_page |
| 8 | + and_i_click_on_edit_child_record |
| 9 | + and_i_click_on_change_parent |
| 10 | + then_i_see_the_edit_parent_page |
| 11 | + |
| 12 | + when_i_change_the_name_of_the_parent |
| 13 | + then_i_see_the_new_name_of_the_parent |
| 14 | + end |
| 15 | + |
| 16 | + scenario "User edits the relationship of a parent" do |
| 17 | + when_i_visit_the_patient_page |
| 18 | + and_i_click_on_edit_child_record |
| 19 | + and_i_click_on_change_parent |
| 20 | + then_i_see_the_edit_parent_page |
| 21 | + |
| 22 | + when_i_change_the_relationship_of_the_parent_to_mother |
| 23 | + then_i_see_the_new_relationship_of_the_parent_of_mother |
| 24 | + |
| 25 | + when_i_click_on_change_parent |
| 26 | + and_i_change_the_relationship_of_the_parent_to_other |
| 27 | + then_i_see_the_new_relationship_of_the_parent_of_other |
| 28 | + end |
| 29 | + |
| 30 | + scenario "User edits the contact details of a parent" do |
| 31 | + when_i_visit_the_patient_page |
| 32 | + and_i_click_on_edit_child_record |
| 33 | + and_i_click_on_change_parent |
| 34 | + then_i_see_the_edit_parent_page |
| 35 | + |
| 36 | + when_i_change_the_contact_details_of_the_parent |
| 37 | + then_i_see_the_new_contact_details_of_the_parent |
| 38 | + end |
| 39 | + |
| 40 | + def given_a_patient_with_a_parent_exists |
| 41 | + organisation = create(:organisation) |
| 42 | + @nurse = create(:nurse, organisation:) |
| 43 | + |
| 44 | + @patient = create(:patient, organisation:) |
| 45 | + |
| 46 | + @parent = create(:parent) |
| 47 | + |
| 48 | + create(:parent_relationship, patient: @patient, parent: @parent) |
| 49 | + end |
| 50 | + |
| 51 | + def when_i_visit_the_patient_page |
| 52 | + sign_in @nurse |
| 53 | + visit patient_path(@patient) |
| 54 | + end |
| 55 | + |
| 56 | + def and_i_click_on_edit_child_record |
| 57 | + click_on "Edit child record" |
| 58 | + end |
| 59 | + |
| 60 | + def when_i_click_on_change_parent |
| 61 | + click_on "Change first parent or guardian" |
| 62 | + end |
| 63 | + |
| 64 | + alias_method :and_i_click_on_change_parent, :when_i_click_on_change_parent |
| 65 | + |
| 66 | + def then_i_see_the_edit_parent_page |
| 67 | + expect(page).to have_content("Details for first parent or guardian") |
| 68 | + end |
| 69 | + |
| 70 | + def when_i_change_the_name_of_the_parent |
| 71 | + fill_in "Name", with: "Selina Meyer" |
| 72 | + click_on "Continue" |
| 73 | + end |
| 74 | + |
| 75 | + def then_i_see_the_new_name_of_the_parent |
| 76 | + expect(page).to have_content("Selina Meyer") |
| 77 | + end |
| 78 | + |
| 79 | + def when_i_change_the_relationship_of_the_parent_to_mother |
| 80 | + choose "Mum" |
| 81 | + click_on "Continue" |
| 82 | + end |
| 83 | + |
| 84 | + def then_i_see_the_new_relationship_of_the_parent_of_mother |
| 85 | + expect(page).to have_content("Mum") |
| 86 | + end |
| 87 | + |
| 88 | + def and_i_change_the_relationship_of_the_parent_to_other |
| 89 | + choose "Other" |
| 90 | + fill_in "Relationship to the child", with: "Someone" |
| 91 | + click_on "Continue" |
| 92 | + end |
| 93 | + |
| 94 | + def then_i_see_the_new_relationship_of_the_parent_of_other |
| 95 | + expect(page).to have_content("Someone") |
| 96 | + end |
| 97 | + |
| 98 | + def when_i_change_the_contact_details_of_the_parent |
| 99 | + fill_in "Email address", with: "selina@meyer.com" |
| 100 | + fill_in "Phone number", with: "07700 900 000" |
| 101 | + click_on "Continue" |
| 102 | + end |
| 103 | + |
| 104 | + def then_i_see_the_new_contact_details_of_the_parent |
| 105 | + expect(page).to have_content("selina@meyer.com") |
| 106 | + expect(page).to have_content("07700 900000") |
| 107 | + end |
| 108 | +end |
0 commit comments