Sha256: 0db9a76e02fa1bac82f1f8c9ace2b76c2145a8539493e49ca20cef698b14421e

Contents?: true

Size: 1.65 KB

Versions: 51

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require_relative "../page_object"

# rubocop disable Metrics/LineLength
module Pages
  module Letters
    class Form < PageObject
      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)
        fill_in "Description", with: value
      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
# rubocop enable Metrics/LineLength

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
renalware-core-2.0.113 spec/support/pages/letters/form.rb
renalware-core-2.0.112 spec/support/pages/letters/form.rb
renalware-core-2.0.111 spec/support/pages/letters/form.rb
renalware-core-2.0.110 spec/support/pages/letters/form.rb
renalware-core-2.0.109 spec/support/pages/letters/form.rb
renalware-core-2.0.108 spec/support/pages/letters/form.rb
renalware-core-2.0.106 spec/support/pages/letters/form.rb
renalware-core-2.0.105 spec/support/pages/letters/form.rb
renalware-core-2.0.104 spec/support/pages/letters/form.rb
renalware-core-2.0.103 spec/support/pages/letters/form.rb
renalware-core-2.0.102 spec/support/pages/letters/form.rb
renalware-core-2.0.101 spec/support/pages/letters/form.rb
renalware-core-2.0.100 spec/support/pages/letters/form.rb
renalware-core-2.0.99 spec/support/pages/letters/form.rb
renalware-core-2.0.98 spec/support/pages/letters/form.rb
renalware-core-2.0.97 spec/support/pages/letters/form.rb
renalware-core-2.0.96 spec/support/pages/letters/form.rb
renalware-core-2.0.95 spec/support/pages/letters/form.rb
renalware-core-2.0.94 spec/support/pages/letters/form.rb
renalware-core-2.0.93 spec/support/pages/letters/form.rb