Sha256: c50a7d4f0fce7b227dbb6144439b550056070e6252ff89c401d5a544c015c232

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

module Turbo
  module TestAssertions
    extend ActiveSupport::Concern

    included do
      # FIXME: Should happen in Rails at a different level
      delegate :dom_id, :dom_class, to: ActionView::RecordIdentifier
    end

    def assert_turbo_stream(action:, target: nil, targets: nil, status: :ok, &block)
      assert_response status
      assert_equal Mime[:turbo_stream], response.media_type
      selector =  %(turbo-stream[action="#{action}"])
      selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target
      selector << %([targets="#{targets}"]) if targets
      assert_select selector, count: 1, &block
    end

    def assert_no_turbo_stream(action:, target: nil, targets: nil)
      assert_equal Mime[:turbo_stream], response.media_type
      selector =  %(turbo-stream[action="#{action}"])
      selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target
      selector << %([targets="#{targets}"]) if targets
      assert_select selector, count: 0
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
turbo-rails-1.4.0 lib/turbo/test_assertions.rb
turbo-rails-1.3.3 lib/turbo/test_assertions.rb
turbo-rails-1.3.2 lib/turbo/test_assertions.rb
turbo-rails-1.3.1 lib/turbo/test_assertions.rb
turbo-rails-1.3.0 lib/turbo/test_assertions.rb
turbo-rails-1.1.1 lib/turbo/test_assertions.rb
turbo-rails-1.1.0 lib/turbo/test_assertions.rb