Sha256: a81460d497fbb3442e1d5905b5b8ce70e6a47fdcfb2e885fe3cf9fe5fa0d8b41

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require_relative "broadcaster_test_case"

class StimulusReflex::PageBroadcasterTest < StimulusReflex::BroadcasterTestCase
  test "returns if the response html is empty" do
    broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)
    broadcaster.broadcast(["#foo"], {some: :data})
    # TODO: figure out how to refute_broadcast_on
  end

  test "performs a page morph on body" do
    class << @reflex.controller.response
      def body
        "<html><head></head><body>New Content</body></html>"
      end
    end

    broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)

    expected = {
      "cableReady" => true,
      "operations" => {
        "morph" => [
          {
            "selector" => "body",
            "html" => "New Content",
            "childrenOnly" => true,
            "permanentAttributeName" => nil,
            "stimulusReflex" => {
              "some" => :data,
              "morph" => :page
            }
          }
        ]
      }
    }

    assert_broadcast_on @reflex.stream_name, expected do
      broadcaster.broadcast(["body"], {some: :data})
    end
  end

  test "performs a page morph given an array of reflex root selectors" do
    class << @reflex.controller.response
      def body
        "<html><head></head><body><div id=\"foo\">New Content</div></body></html>"
      end
    end

    broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)

    expected = {
      "cableReady" => true,
      "operations" => {
        "morph" => [
          {
            "selector" => "#foo",
            "html" => "New Content",
            "childrenOnly" => true,
            "permanentAttributeName" => nil,
            "stimulusReflex" => {
              "some" => :data,
              "morph" => :page
            }
          }
        ]
      }
    }

    assert_broadcast_on @reflex.stream_name, expected do
      broadcaster.broadcast(["#foo"], {some: :data})
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stimulus_reflex-3.4.2 test/broadcasters/page_broadcaster_test.rb
stimulus_reflex-3.4.1 test/broadcasters/page_broadcaster_test.rb
stimulus_reflex-3.4.0 test/broadcasters/page_broadcaster_test.rb
stimulus_reflex-3.4.0.pre9 test/broadcasters/page_broadcaster_test.rb