PhoenixTestDatastar.Dispatcher (PhoenixTestDatastar v0.0.2)

Copy Markdown

HTTP dispatcher for Datastar requests.

Builds HTTP requests with appropriate headers and body, dispatches them through the Phoenix endpoint, parses SSE responses, and applies events to update session state (signals + DOM).

Summary

Functions

Applies a list of SSE events to the session, updating signals and DOM.

Dispatches an action and returns the updated session.

Dispatches a standard form submission (non-Datastar).

Follows a redirect, returning the updated session.

Functions

apply_events(session, events)

@spec apply_events(
  %PhoenixTestDatastar.Session{
    active_form: term(),
    conn: term(),
    csrf_token: term(),
    current_operation: term(),
    current_path: term(),
    raw_html: term(),
    signals: term(),
    stream_info: term(),
    visit_opts: term(),
    within: term()
  },
  [PhoenixTestDatastar.SSE.event()]
) :: %PhoenixTestDatastar.Session{
  active_form: term(),
  conn: term(),
  csrf_token: term(),
  current_operation: term(),
  current_path: term(),
  raw_html: term(),
  signals: term(),
  stream_info: term(),
  visit_opts: term(),
  within: term()
}

Applies a list of SSE events to the session, updating signals and DOM.

dispatch_action(session, action)

@spec dispatch_action(
  %PhoenixTestDatastar.Session{
    active_form: term(),
    conn: term(),
    csrf_token: term(),
    current_operation: term(),
    current_path: term(),
    raw_html: term(),
    signals: term(),
    stream_info: term(),
    visit_opts: term(),
    within: term()
  },
  PhoenixTestDatastar.Actions.action()
) :: %PhoenixTestDatastar.Session{
  active_form: term(),
  conn: term(),
  csrf_token: term(),
  current_operation: term(),
  current_path: term(),
  raw_html: term(),
  signals: term(),
  stream_info: term(),
  visit_opts: term(),
  within: term()
}

Dispatches an action and returns the updated session.

Takes a parsed action (from Actions.parse_one/1) and dispatches it through the endpoint, then processes the SSE response.

dispatch_form(session, method, action_url, payload)

@spec dispatch_form(
  %PhoenixTestDatastar.Session{
    active_form: term(),
    conn: term(),
    csrf_token: term(),
    current_operation: term(),
    current_path: term(),
    raw_html: term(),
    signals: term(),
    stream_info: term(),
    visit_opts: term(),
    within: term()
  },
  String.t(),
  String.t(),
  map() | String.t()
) :: %PhoenixTestDatastar.Session{
  active_form: term(),
  conn: term(),
  csrf_token: term(),
  current_operation: term(),
  current_path: term(),
  raw_html: term(),
  signals: term(),
  stream_info: term(),
  visit_opts: term(),
  within: term()
}

Dispatches a standard form submission (non-Datastar).

follow_redirect(session, path)

@spec follow_redirect(
  %PhoenixTestDatastar.Session{
    active_form: term(),
    conn: term(),
    csrf_token: term(),
    current_operation: term(),
    current_path: term(),
    raw_html: term(),
    signals: term(),
    stream_info: term(),
    visit_opts: term(),
    within: term()
  },
  String.t()
) :: %PhoenixTestDatastar.Session{
  active_form: term(),
  conn: term(),
  csrf_token: term(),
  current_operation: term(),
  current_path: term(),
  raw_html: term(),
  signals: term(),
  stream_info: term(),
  visit_opts: term(),
  within: term()
}

Follows a redirect, returning the updated session.