Module: Katalyst::Kpop::Matchers

Defined in:
lib/katalyst/kpop/matchers.rb,
lib/katalyst/kpop/matchers/base.rb,
lib/katalyst/kpop/matchers/title_finder.rb,
lib/katalyst/kpop/matchers/frame_matcher.rb,
lib/katalyst/kpop/matchers/modal_matcher.rb,
lib/katalyst/kpop/matchers/title_matcher.rb,
lib/katalyst/kpop/matchers/stream_matcher.rb,
lib/katalyst/kpop/matchers/capybara_parser.rb,
lib/katalyst/kpop/matchers/chained_matcher.rb,
lib/katalyst/kpop/matchers/capybara_matcher.rb,
lib/katalyst/kpop/matchers/redirect_matcher.rb,
lib/katalyst/kpop/matchers/response_matcher.rb

Defined Under Namespace

Classes: Base, CapybaraMatcher, CapybaraParser, ChainedMatcher, FrameMatcher, ModalMatcher, RedirectMatcher, ResponseMatcher, StreamMatcher, TitleFinder, TitleMatcher

Instance Method Summary collapse

Instance Method Details

#kpop_dismiss(id: "kpop") ⇒ Object

Passes if ‘response` contains a turbo response with a kpop dismiss action.

Examples:

expect(response).to kpop_dismiss


11
12
13
14
15
# File 'lib/katalyst/kpop/matchers.rb', line 11

def kpop_dismiss(id: "kpop")
  ChainedMatcher.new(ResponseMatcher,
                     CapybaraParser,
                     StreamMatcher.new(id:, action: "kpop_dismiss"))
end

#kpop_redirect_to(target, id: "kpop") ⇒ Object

Passes if ‘response` contains a turbo response with a kpop redirect to the provided `target`.

Examples:

Matching a path against a turbo response containing a kpop redirect

expect(response).to kpop_redirect_to("/path/to/resource")

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/katalyst/kpop/matchers.rb', line 23

def kpop_redirect_to(target, id: "kpop")
  raise ArgumentError, "Invalid target: nil" unless target

  ChainedMatcher.new(ResponseMatcher,
                     CapybaraParser,
                     StreamMatcher.new(id:, action: "kpop_redirect_to"),
                     RedirectMatcher.new(target))
end

#render_kpop_frame(id: "kpop", title: nil) ⇒ Object

Passes if ‘response` contains a turbo frame with a kpop modal. Supports matching on:

* id – turbo frame id
* title - modal title

Examples:

Matching turbo stream response with a Shopping Cart modal

expect(response).to render_kpop_frame(title: "Shopping Cart")


55
56
57
58
59
# File 'lib/katalyst/kpop/matchers.rb', line 55

def render_kpop_frame(id: "kpop", title: nil)
  matcher = ChainedMatcher.new(ResponseMatcher, CapybaraParser, FrameMatcher.new(id:), ModalMatcher)
  matcher << TitleFinder << TitleMatcher.new(title) if title.present?
  matcher
end

#render_kpop_stream(id: "kpop", title: nil) ⇒ Object

Passes if ‘response` contains a turbo stream response with a kpop modal. Supports matching on:

* id – kpop frame id
* title - modal title

Examples:

Matching turbo stream response with a Shopping Cart modal

expect(response).to render_kpop_stream(title: "Shopping Cart")


40
41
42
43
44
45
# File 'lib/katalyst/kpop/matchers.rb', line 40

def render_kpop_stream(id: "kpop", title: nil)
  matcher = ChainedMatcher.new(ResponseMatcher, CapybaraParser, StreamMatcher.new(id:, action: "kpop_open"),
                               ModalMatcher)
  matcher << TitleFinder << TitleMatcher.new(title) if title.present?
  matcher
end