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.72 spec/support/pages/letters/form.rb
renalware-core-2.0.71 spec/support/pages/letters/form.rb
renalware-core-2.0.70 spec/support/pages/letters/form.rb
renalware-core-2.0.69 spec/support/pages/letters/form.rb
renalware-core-2.0.68 spec/support/pages/letters/form.rb
renalware-core-2.0.67 spec/support/pages/letters/form.rb
renalware-core-2.0.64 spec/support/pages/letters/form.rb
renalware-core-2.0.63 spec/support/pages/letters/form.rb
renalware-core-2.0.62 spec/support/pages/letters/form.rb
renalware-core-2.0.61 spec/support/pages/letters/form.rb
renalware-core-2.0.60 spec/support/pages/letters/form.rb