Sha256: 215c2971378780a22867d3a60735a432c67c31cd5b54666b48b733fb85647702

Contents?: true

Size: 1.99 KB

Versions: 28

Compression:

Stored size: 1.99 KB

Contents

module OpsManagerUiDrivers
  module Version16
    class JobAvailabilityZoneMappingHelper
      def initialize(product_name:, browser:)
        @product_name = product_name
        @browser = browser
      end

      SINGLETON_AVAILABILITY_ZONE_INPUT_SELECTOR = "input[name='product[singleton_availability_zone_reference]']"
      AVAILABILITY_ZONE_INPUT_SELECTOR = "input[name='product[availability_zone_references][]']"

      def assign_availability_zones!(singleton_availability_zone:, availability_zones:)
        open_form

        browser.all(AVAILABILITY_ZONE_INPUT_SELECTOR).each do |checkbox|
          checkbox.set(false)
        end

        availability_zones.each do |az_name|
          browser.check("#{az_name}")
        end

        browser.choose("#{singleton_availability_zone}")

        save_form
      end

      def singleton_availability_zone
        open_form

        selected_options = browser.all("#{SINGLETON_AVAILABILITY_ZONE_INPUT_SELECTOR}[selected='selected']").map do |radio|
          browser.find("label[for='#{radio[:id]}']").text
        end

        raise ArgumentError, 'availability_zone not selected' if selected_options.empty?
        selected_options.first
      end

      def availability_zones
        open_form

        browser.all("#{AVAILABILITY_ZONE_INPUT_SELECTOR}[checked='checked']").map do |checkbox|
          browser.find("label[for='#{checkbox[:id]}']").text
        end
      end

      private

      attr_reader :browser, :product_name

      def open_form
        browser.visit '/'
        browser.click_on "show-#{product_name}-configure-action"
        browser.click_on "show-#{product_name}-availability-zone-assignment-action"
      end

      def save_form
        browser.click_on 'Save'

        unless browser.has_css?('.flash-message.success')
          if browser.has_css?('.flash-message.error')
            raise browser.find('.flash-message.error').text
          else
            raise 'unexpected failure'
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
ops_manager_ui_drivers-1.28.1 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.28.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.27.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.26.1 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.26.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.25.1 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.25.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.24.4 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.24.3 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.24.2 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.24.1 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.24.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.23.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.22.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.21.1 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.21.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.20.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.19.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.18.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.17.0 lib/ops_manager_ui_drivers/version16/job_availability_zone_mapping_helper.rb