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.92 spec/support/pages/letters/form.rb
renalware-core-2.0.91 spec/support/pages/letters/form.rb
renalware-core-2.0.90 spec/support/pages/letters/form.rb
renalware-core-2.0.89 spec/support/pages/letters/form.rb
renalware-core-2.0.88 spec/support/pages/letters/form.rb
renalware-core-2.0.87 spec/support/pages/letters/form.rb
renalware-core-2.0.86 spec/support/pages/letters/form.rb
renalware-core-2.0.85 spec/support/pages/letters/form.rb
renalware-core-2.0.84 spec/support/pages/letters/form.rb
renalware-core-2.0.83 spec/support/pages/letters/form.rb
renalware-core-2.0.82 spec/support/pages/letters/form.rb
renalware-core-2.0.81 spec/support/pages/letters/form.rb
renalware-core-2.0.80 spec/support/pages/letters/form.rb
renalware-core-2.0.79 spec/support/pages/letters/form.rb
renalware-core-2.0.78 spec/support/pages/letters/form.rb
renalware-core-2.0.77 spec/support/pages/letters/form.rb
renalware-core-2.0.76 spec/support/pages/letters/form.rb
renalware-core-2.0.75 spec/support/pages/letters/form.rb
renalware-core-2.0.74 spec/support/pages/letters/form.rb
renalware-core-2.0.73 spec/support/pages/letters/form.rb