Sha256: 3d6d65e2cb28fae3f13a57c54616bd7053afc572b5cd16fe2ad5e751871be475

Contents?: true

Size: 1.99 KB

Versions: 12

Compression:

Stored size: 1.99 KB

Contents

module OpsManagerUiDrivers
  module Version17
    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

12 entries across 12 versions & 1 rubygems

Version Path
ops_manager_ui_drivers-1.20.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.19.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.18.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.17.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.16.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.15.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.14.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.13.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.12.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.11.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.10.0 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb
ops_manager_ui_drivers-1.9.5 lib/ops_manager_ui_drivers/version17/job_availability_zone_mapping_helper.rb