Sha256: 10fe4a8867e20e9b8e4f63d33e2b4139c0742465b7ff2a40d7ea153c1047e071

Contents?: true

Size: 1.92 KB

Versions: 31

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require "decidim/dev/test/rspec_support/capybara_data_picker"

module Capybara
  module ProposalsPicker
    include DataPicker

    RSpec::Matchers.define :have_proposals_picked do |expected|
      match do |proposals_picker|
        data_picker = proposals_picker.data_picker

        expected.each do |proposal|
          expect(data_picker).to have_selector(".picker-values div input[value='#{proposal.id}']", visible: :all)
          expect(data_picker).to have_selector(:xpath, "//div[contains(@class,'picker-values')]/div/a[text()[contains(.,\"#{translated(proposal.title)}\")]]")
        end
      end
    end

    RSpec::Matchers.define :have_proposals_not_picked do |expected|
      match do |proposals_picker|
        data_picker = proposals_picker.data_picker

        expected.each do |proposal|
          expect(data_picker).not_to have_selector(".picker-values div input[value='#{proposal.id}']", visible: :all)
          expect(data_picker).not_to have_selector(:xpath, "//div[contains(@class,'picker-values')]/div/a[text()[contains(.,\"#{translated(proposal.title)}\")]]")
        end
      end
    end

    def proposals_pick(proposals_picker, proposals)
      data_picker = proposals_picker.data_picker

      expect(data_picker).to have_selector(".picker-prompt")
      data_picker.find(".picker-prompt").click

      proposals.each do |proposal|
        data_picker_choose_value(proposal.id)
      end
      data_picker_close

      expect(proposals_picker).to have_proposals_picked(proposals)
    end

    def proposals_remove(proposals_picker, proposals)
      data_picker = proposals_picker.data_picker

      proposals.each do |proposal|
        data_picker.find("a", text: proposal.title["en"]).find("span").click
      end

      expect(proposals_picker).to have_proposals_not_picked(proposals)
    end
  end
end

RSpec.configure do |config|
  config.include Capybara::ProposalsPicker, type: :system
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-proposals-0.27.9 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.8 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.7 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.6 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.10 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.9 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.5 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.8 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.4 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.3 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.7 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.5 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.2 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.1 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.4 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.0 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.3 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.0.rc2 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.27.0.rc1 lib/decidim/proposals/test/capybara_proposals_picker.rb
decidim-proposals-0.26.2 lib/decidim/proposals/test/capybara_proposals_picker.rb