exmr/test/exmr_web/live/exam_live_test.exs

114 lines
3.3 KiB
Elixir
Raw Normal View History

2024-11-14 23:33:29 +02:00
defmodule ExmrWeb.ExamLiveTest do
use ExmrWeb.ConnCase
import Phoenix.LiveViewTest
import Exmr.ExamsFixtures
@create_attrs %{date: "2024-11-13", description: "some description", subject: "some subject"}
@update_attrs %{date: "2024-11-14", description: "some updated description", subject: "some updated subject"}
@invalid_attrs %{date: nil, description: nil, subject: nil}
defp create_exam(_) do
exam = exam_fixture()
%{exam: exam}
end
describe "Index" do
setup [:create_exam]
test "lists all exams", %{conn: conn, exam: exam} do
{:ok, _index_live, html} = live(conn, ~p"/exams")
assert html =~ "Listing Exams"
assert html =~ exam.description
end
test "saves new exam", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/exams")
assert index_live |> element("a", "New Exam") |> render_click() =~
"New Exam"
assert_patch(index_live, ~p"/exams/new")
assert index_live
|> form("#exam-form", exam: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert index_live
|> form("#exam-form", exam: @create_attrs)
|> render_submit()
assert_patch(index_live, ~p"/exams")
html = render(index_live)
assert html =~ "Exam created successfully"
assert html =~ "some description"
end
test "updates exam in listing", %{conn: conn, exam: exam} do
{:ok, index_live, _html} = live(conn, ~p"/exams")
assert index_live |> element("#exams-#{exam.id} a", "Edit") |> render_click() =~
"Edit Exam"
assert_patch(index_live, ~p"/exams/#{exam}/edit")
assert index_live
|> form("#exam-form", exam: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert index_live
|> form("#exam-form", exam: @update_attrs)
|> render_submit()
assert_patch(index_live, ~p"/exams")
html = render(index_live)
assert html =~ "Exam updated successfully"
assert html =~ "some updated description"
end
test "deletes exam in listing", %{conn: conn, exam: exam} do
{:ok, index_live, _html} = live(conn, ~p"/exams")
assert index_live |> element("#exams-#{exam.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#exams-#{exam.id}")
end
end
describe "Show" do
setup [:create_exam]
test "displays exam", %{conn: conn, exam: exam} do
{:ok, _show_live, html} = live(conn, ~p"/exams/#{exam}")
assert html =~ "Show Exam"
assert html =~ exam.description
end
test "updates exam within modal", %{conn: conn, exam: exam} do
{:ok, show_live, _html} = live(conn, ~p"/exams/#{exam}")
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Exam"
assert_patch(show_live, ~p"/exams/#{exam}/show/edit")
assert show_live
|> form("#exam-form", exam: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert show_live
|> form("#exam-form", exam: @update_attrs)
|> render_submit()
assert_patch(show_live, ~p"/exams/#{exam}")
html = render(show_live)
assert html =~ "Exam updated successfully"
assert html =~ "some updated description"
end
end
end