Sha256: b7fb689918f33ac4d9ce495f92083516f9de4260c79a0d65e61bfee3f4b125d6

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'capybara/dsl'

module Balboa
  module Interactor
    module Command
      class FillPunchCommand
        include Capybara::DSL

        def initialize(options)
          @options = options
        end

        def execute(date)
          visit_new_punch_path

          fill_first_shift(date)

          visit_new_punch_path

          fill_second_shift(date)
        end

        private

        def visit_new_punch_path
          visit('/punches/new')
        end

        def fill_first_shift(date)
          fill_form(date, @options['start_at'], @options['lunch_at'])

          confirm
        end

        def fill_second_shift(date)
          fill_form(date, @options['restart_at'], @options['leave_at'])

          confirm
        end

        def fill_form(date, start_time, finish_time)
          fill_in 'punch[from_time]', with: start_time
          fill_in 'punch[to_time]', with: finish_time
          fill_in 'punch[when_day]', with: date.to_s
          select @options['project'], from: 'punch[project_id]'
        end

        def confirm
          click_button 'Criar Punch'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
balboa-0.1.2 lib/balboa/interactor/command/fill_punch_command.rb