defmodule FirehoseWeb.PageControllerTest do
  use FirehoseWeb.ConnCase

  describe "GET /" do
    test "renders the homepage", %{conn: conn} do
      body = conn |> get(~p"/") |> html_response(200)
      assert body =~ "Drinking from the firehose"
      assert body =~ "Willem van den Ende"
    end

    test "shows navigation links", %{conn: conn} do
      body = conn |> get(~p"/") |> html_response(200)
      assert body =~ ~s|/blog/engineering|
      assert body =~ ~s|/blog/releases|
      assert body =~ ~s|/contact|
    end

    test "does not show dashboard link when unauthenticated", %{conn: conn} do
      body = conn |> get(~p"/") |> html_response(200)
      refute body =~ ~s|/editor/dashboard|
    end
  end

  describe "GET / when authenticated" do
    setup :register_and_log_in_user

    test "shows dashboard link in navigation", %{conn: conn} do
      body = conn |> get(~p"/") |> html_response(200)
      assert body =~ ~s|/editor/dashboard|
    end
  end
end
