Skip to content

Commit

Permalink
Merge pull request #67 from camino-school/report-card-tests
Browse files Browse the repository at this point in the history
Report card tests
  • Loading branch information
endoooo authored Feb 29, 2024
2 parents 02b45b0 + ad018d8 commit f9f0238
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 != []}>
Expand Down
5 changes: 4 additions & 1 deletion lib/lanttern_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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"<h1 .+>\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
Original file line number Diff line number Diff line change
@@ -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"<h1 .+>\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
Original file line number Diff line number Diff line change
@@ -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"<h1 .+>\s*Student ABC\s*<\/h1>"
assert response =~ ~r"<h2 .+>\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

0 comments on commit f9f0238

Please sign in to comment.