From 8c49bb25d9192d03253f23c491b5da82d35a2730 Mon Sep 17 00:00:00 2001 From: endoooo Date: Wed, 28 Feb 2024 16:59:46 -0300 Subject: [PATCH 1/2] test: added some report card live tests --- .../report_cards/id/report_card_live_test.exs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/lanttern_web/live/pages/report_cards/id/report_card_live_test.exs diff --git a/test/lanttern_web/live/pages/report_cards/id/report_card_live_test.exs b/test/lanttern_web/live/pages/report_cards/id/report_card_live_test.exs new file mode 100644 index 00000000..13a12ea7 --- /dev/null +++ b/test/lanttern_web/live/pages/report_cards/id/report_card_live_test.exs @@ -0,0 +1,83 @@ +defmodule LantternWeb.ReportCardLiveTest do + use LantternWeb.ConnCase + + import Lanttern.ReportingFixtures + + alias Lanttern.LearningContextFixtures + alias Lanttern.SchoolsFixtures + alias Lanttern.TaxonomyFixtures + + @live_view_path_base "/report_cards" + + setup [:register_and_log_in_user] + + describe "Report card live view basic navigation" do + test "disconnected and connected mount", %{conn: conn} do + report_card = report_card_fixture(%{name: "Some report card name abc"}) + + conn = get(conn, "#{@live_view_path_base}/#{report_card.id}") + + assert html_response(conn, 200) =~ ~r"

\s*Some report card name abc\s*<\/h1>" + + {:ok, _view, _html} = live(conn) + end + + test "list students and students report cards", %{conn: conn} do + cycle_2024 = + SchoolsFixtures.cycle_fixture(%{ + start_at: ~D[2024-01-01], + end_at: ~D[2024-12-31], + name: "Cycle 2024" + }) + + report_card = + report_card_fixture(%{school_cycle_id: cycle_2024.id, name: "Some report card name abc"}) + + student_a = SchoolsFixtures.student_fixture(%{name: "Student AAA"}) + _student_b = SchoolsFixtures.student_fixture(%{name: "Student BBB"}) + + student_a_report_card = + student_report_card_fixture(%{report_card_id: report_card.id, student_id: student_a.id}) + + {:ok, view, _html} = live(conn, "#{@live_view_path_base}/#{report_card.id}") + + assert view |> has_element?("h1", report_card.name) + assert view |> has_element?("span", "Cycle: Cycle 2024") + assert view |> has_element?("span", "Student AAA") + assert view |> has_element?("span", "Student BBB") + + view + |> element("a", "Preview") + |> render_click() + + assert_redirect(view, "/student_report_card/#{student_a_report_card.id}") + end + + test "list strand reports", %{conn: conn} do + report_card = report_card_fixture() + + subject = TaxonomyFixtures.subject_fixture(%{name: "Some subject SSS"}) + year = TaxonomyFixtures.year_fixture(%{name: "Some year YYY"}) + + strand = + LearningContextFixtures.strand_fixture(%{ + name: "Strand for report ABC", + type: "Some type XYZ", + subjects_ids: [subject.id], + years_ids: [year.id] + }) + + strand_report = + strand_report_fixture(%{report_card_id: report_card.id, strand_id: strand.id}) + + {:ok, view, _html} = live(conn, "#{@live_view_path_base}/#{report_card.id}?tab=strands") + + assert view + |> has_element?("#strands_reports-#{strand_report.id} h5", "Strand for report ABC") + + assert view |> has_element?("#strands_reports-#{strand_report.id} p", "Some type XYZ") + assert view |> has_element?("#strands_reports-#{strand_report.id} span", subject.name) + assert view |> has_element?("#strands_reports-#{strand_report.id} span", year.name) + end + end +end From ad018d8f762d14f407b9b0d97720803c9c057b59 Mon Sep 17 00:00:00 2001 From: endoooo Date: Thu, 29 Feb 2024 03:21:12 -0300 Subject: [PATCH 2/2] test: added tests for student report card live view --- .../student_strand_report_live.ex | 0 .../student_strand_report_live.html.heex | 0 .../id/student_report_card_live.html.heex | 2 +- lib/lanttern_web/router.ex | 5 +- .../student_strand_report_live_test.exs | 92 +++++++++++++++++++ .../id/student_report_card_live_test.exs | 86 +++++++++++++++++ 6 files changed, 183 insertions(+), 2 deletions(-) rename lib/lanttern_web/live/pages/student_report_card/id/{strand/strand_id => strand_report/strand_report_id}/student_strand_report_live.ex (100%) rename lib/lanttern_web/live/pages/student_report_card/id/{strand/strand_id => strand_report/strand_report_id}/student_strand_report_live.html.heex (100%) create mode 100644 test/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live_test.exs create mode 100644 test/lanttern_web/live/pages/student_report_card/id/student_report_card_live_test.exs diff --git a/lib/lanttern_web/live/pages/student_report_card/id/strand/strand_id/student_strand_report_live.ex b/lib/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live.ex similarity index 100% rename from lib/lanttern_web/live/pages/student_report_card/id/strand/strand_id/student_strand_report_live.ex rename to lib/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live.ex diff --git a/lib/lanttern_web/live/pages/student_report_card/id/strand/strand_id/student_strand_report_live.html.heex b/lib/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live.html.heex similarity index 100% rename from lib/lanttern_web/live/pages/student_report_card/id/strand/strand_id/student_strand_report_live.html.heex rename to lib/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live.html.heex diff --git a/lib/lanttern_web/live/pages/student_report_card/id/student_report_card_live.html.heex b/lib/lanttern_web/live/pages/student_report_card/id/student_report_card_live.html.heex index fe96876f..65363f12 100644 --- a/lib/lanttern_web/live/pages/student_report_card/id/student_report_card_live.html.heex +++ b/lib/lanttern_web/live/pages/student_report_card/id/student_report_card_live.html.heex @@ -24,7 +24,7 @@ :for={{dom_id, {strand_report, entries}} <- @streams.strand_reports_and_entries} id={dom_id} strand={strand_report.strand} - navigate={~p"/student_report_card/#{@student_report_card}/strand/#{strand_report}"} + navigate={~p"/student_report_card/#{@student_report_card}/strand_report/#{strand_report}"} hide_description > <:bottom_content :if={entries != []}> diff --git a/lib/lanttern_web/router.ex b/lib/lanttern_web/router.ex index e0cdd9b7..c30f755a 100644 --- a/lib/lanttern_web/router.ex +++ b/lib/lanttern_web/router.ex @@ -101,7 +101,10 @@ defmodule LantternWeb.Router do live "/report_cards/:id/edit", ReportCardLive, :edit live "/student_report_card/:id", StudentReportCardLive, :show - live "/student_report_card/:id/strand/:strand_report_id", StudentStrandReportLive, :show + + live "/student_report_card/:id/strand_report/:strand_report_id", + StudentStrandReportLive, + :show end end diff --git a/test/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live_test.exs b/test/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live_test.exs new file mode 100644 index 00000000..90f955e1 --- /dev/null +++ b/test/lanttern_web/live/pages/student_report_card/id/strand_report/strand_report_id/student_strand_report_live_test.exs @@ -0,0 +1,92 @@ +defmodule LantternWeb.StudentStrandReportLiveTest do + use LantternWeb.ConnCase + + import Lanttern.ReportingFixtures + + alias Lanttern.LearningContextFixtures + alias Lanttern.SchoolsFixtures + alias Lanttern.TaxonomyFixtures + + @live_view_path_base "/student_report_card" + + setup [:register_and_log_in_user] + + describe "Student strand report live view basic navigation" do + test "disconnected and connected mount", %{conn: conn} do + student = SchoolsFixtures.student_fixture(%{name: "Student ABC"}) + report_card = report_card_fixture(%{name: "Some report card name abc"}) + + student_report_card = + student_report_card_fixture(%{report_card_id: report_card.id, student_id: student.id}) + + strand = LearningContextFixtures.strand_fixture(%{name: "Some strand name for report"}) + + strand_report = + strand_report_fixture(%{report_card_id: report_card.id, strand_id: strand.id}) + + conn = + get( + conn, + "#{@live_view_path_base}/#{student_report_card.id}/strand_report/#{strand_report.id}" + ) + + response = html_response(conn, 200) + assert response =~ ~r"

\s*Some strand name for report\s*<\/h1>" + + {:ok, _view, _html} = live(conn) + end + + test "display student strand report correctly", %{conn: conn} do + cycle = SchoolsFixtures.cycle_fixture(%{name: "Cycle 2024"}) + student = SchoolsFixtures.student_fixture(%{name: "Student ABC"}) + + report_card = + report_card_fixture(%{school_cycle_id: cycle.id, name: "Some report card name abc"}) + + student_report_card = + student_report_card_fixture(%{ + report_card_id: report_card.id, + student_id: student.id, + comment: "student abc comment", + footnote: "student abc footnote" + }) + + subject = TaxonomyFixtures.subject_fixture(%{name: "Some subject SSS"}) + year = TaxonomyFixtures.year_fixture(%{name: "Some year YYY"}) + + strand = + LearningContextFixtures.strand_fixture(%{ + name: "Strand for report ABC", + type: "Some type XYZ", + subjects_ids: [subject.id], + years_ids: [year.id] + }) + + strand_report = + strand_report_fixture(%{ + report_card_id: report_card.id, + strand_id: strand.id, + description: "Some description for strand report" + }) + + {:ok, view, _html} = + live( + conn, + "#{@live_view_path_base}/#{student_report_card.id}/strand_report/#{strand_report.id}" + ) + + assert view |> has_element?("a", "Student ABC") + assert view |> has_element?("a", "Some report card name abc") + assert view |> has_element?("p", "student abc footnote") + + # strand report card + assert view + |> has_element?("h1", "Strand for report ABC") + + assert view |> has_element?("p", "Some type XYZ") + assert view |> has_element?("span", "Some subject SSS") + assert view |> has_element?("span", "Some year YYY") + assert view |> has_element?("p", "Some description for strand report") + end + end +end diff --git a/test/lanttern_web/live/pages/student_report_card/id/student_report_card_live_test.exs b/test/lanttern_web/live/pages/student_report_card/id/student_report_card_live_test.exs new file mode 100644 index 00000000..46c38695 --- /dev/null +++ b/test/lanttern_web/live/pages/student_report_card/id/student_report_card_live_test.exs @@ -0,0 +1,86 @@ +defmodule LantternWeb.StudentReportCardLiveTest do + use LantternWeb.ConnCase + + import Lanttern.ReportingFixtures + + alias Lanttern.LearningContextFixtures + alias Lanttern.SchoolsFixtures + alias Lanttern.TaxonomyFixtures + + @live_view_path_base "/student_report_card" + + setup [:register_and_log_in_user] + + describe "Student report card live view basic navigation" do + test "disconnected and connected mount", %{conn: conn} do + student = SchoolsFixtures.student_fixture(%{name: "Student ABC"}) + report_card = report_card_fixture(%{name: "Some report card name abc"}) + + student_report_card = + student_report_card_fixture(%{report_card_id: report_card.id, student_id: student.id}) + + conn = get(conn, "#{@live_view_path_base}/#{student_report_card.id}") + + response = html_response(conn, 200) + assert response =~ ~r"

\s*Student ABC\s*<\/h1>" + assert response =~ ~r"

\s*Some report card name abc\s*<\/h2>" + + {:ok, _view, _html} = live(conn) + end + + test "display student report card correctly", %{conn: conn} do + cycle = SchoolsFixtures.cycle_fixture(%{name: "Cycle 2024"}) + student = SchoolsFixtures.student_fixture(%{name: "Student ABC"}) + + report_card = + report_card_fixture(%{school_cycle_id: cycle.id, name: "Some report card name abc"}) + + student_report_card = + student_report_card_fixture(%{ + report_card_id: report_card.id, + student_id: student.id, + comment: "student abc comment", + footnote: "student abc footnote" + }) + + subject = TaxonomyFixtures.subject_fixture(%{name: "Some subject SSS"}) + year = TaxonomyFixtures.year_fixture(%{name: "Some year YYY"}) + + strand = + LearningContextFixtures.strand_fixture(%{ + name: "Strand for report ABC", + type: "Some type XYZ", + subjects_ids: [subject.id], + years_ids: [year.id] + }) + + strand_report = + strand_report_fixture(%{report_card_id: report_card.id, strand_id: strand.id}) + + {:ok, view, _html} = live(conn, "#{@live_view_path_base}/#{student_report_card.id}") + + assert view |> has_element?("h1", "Student ABC") + assert view |> has_element?("h2", "Some report card name abc") + assert view |> has_element?("p", "student abc comment") + assert view |> has_element?("p", "student abc footnote") + + # strand report card + assert view + |> has_element?("#strand-report-#{strand_report.id} h5", "Strand for report ABC") + + assert view |> has_element?("#strand-report-#{strand_report.id} p", "Some type XYZ") + assert view |> has_element?("#strand-report-#{strand_report.id} span", "Some subject SSS") + assert view |> has_element?("#strand-report-#{strand_report.id} span", "Some year YYY") + + # navigation to details + view + |> element("#strand-report-#{strand_report.id} a", "Strand for report ABC") + |> render_click() + + assert_redirect( + view, + "#{@live_view_path_base}/#{student_report_card.id}/strand_report/#{strand_report.id}" + ) + end + end +end