Sha256: fc0446c9564ac04cdeb487ae29589ad9e40112ce8574d1060b92fcbe7d8f2e91

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require "rails_helper"
require_relative "../page_object"
require "capybara-select-2"
module Pages
  module Letters
    class Form < PageObject
      include CapybaraSelect2

      PERSON_ROLE_TO_RADIO_ID_MAP = {
        patient: :letter_main_recipient_attributes_person_role_patient,
        primary_care_physician:
          :letter_main_recipient_attributes_person_role_primary_care_physician,
        gp: :letter_main_recipient_attributes_person_role_primary_care_physician,
        contact: :letter_main_recipient_attributes_person_role_contact
      }.freeze

      def issued_on=(date)
        fill_in "Date", with: I18n.l(date)
      end

      def letterhead=(letterhead)
        select letterhead, from: "Letterhead"
      end

      def author=(user)
        select user.to_s, from: "Author"
      end

      def description=(value)
        select2 value, css: ".letter_description"
      end

      def main_recipient=(main_recipient_role)
        within ".letter_main_recipient_person_role" do
          radio_id = map_main_recipient_to_radio_id(main_recipient_role)
          choose(radio_id)
        end
      end

      # If using :contact as main_recipient then we need to select which recipient to use
      # from the contacts dropdown
      def main_recipient_contact_name=(name)
        select name, from: "letter_main_recipient_attributes_addressee_id"
      end

      def submit
        within ".top" do
          click_on "Create"
        end
      end

      private

      def map_main_recipient_to_radio_id(main_recipient_type)
        PERSON_ROLE_TO_RADIO_ID_MAP.fetch(
          main_recipient_type.to_s.downcase.to_sym
        )
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
renalware-core-2.0.153 spec/support/pages/letters/form.rb
renalware-core-2.0.152 spec/support/pages/letters/form.rb
renalware-core-2.0.151 spec/support/pages/letters/form.rb
renalware-core-2.0.149 spec/support/pages/letters/form.rb
renalware-core-2.0.148 spec/support/pages/letters/form.rb
renalware-core-2.0.147 spec/support/pages/letters/form.rb
renalware-core-2.0.146 spec/support/pages/letters/form.rb
renalware-core-2.0.145 spec/support/pages/letters/form.rb
renalware-core-2.0.144 spec/support/pages/letters/form.rb
renalware-core-2.0.143 spec/support/pages/letters/form.rb
renalware-core-2.0.142 spec/support/pages/letters/form.rb
renalware-core-2.0.141 spec/support/pages/letters/form.rb
renalware-core-2.0.140 spec/support/pages/letters/form.rb
renalware-core-2.0.139 spec/support/pages/letters/form.rb
renalware-core-2.0.138 spec/support/pages/letters/form.rb
renalware-core-2.0.137 spec/support/pages/letters/form.rb