Skip to content

Commit

Permalink
[BUG FIX] Fix bug + add tests (Simon-Initiative#3512)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicocirio committed May 10, 2023
1 parent 3b9d58f commit 57f32ee
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
41 changes: 29 additions & 12 deletions lib/oli_web/live/grades/gradebook_table_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,53 @@ defmodule OliWeb.Grades.GradebookTableModel do
end

def render_grade_score(assigns, row, _) do
perc = row.score / row.out_of * 100
perc = score(row.score) / out_of_score(row.out_of) * 100
has_score? = row.score != nil

~F"""
<a
class={"ml-8 #{if perc < 40, do: "text-red-500", else: "text-black"}"}
data-score-check={if perc < 40, do: "false", else: "true"}
class={"ml-8 #{if has_score? and perc < 40, do: "text-red-500", else: "text-black"}"}
data-score-check={if has_score? and perc < 40, do: "false", else: "true"}
href={Routes.live_path(OliWeb.Endpoint, OliWeb.Progress.StudentResourceView, assigns.section_slug, assigns.student_id, row.resource_id)}
>
{#if has_score?}
{row.score}/{row.out_of}
{#else}
Not Finished
{/if}
</a>
"""
end

def render_student(assigns, row, _) do
resource_accesses_approved =
disapproved_count =
Map.values(row)
|> Enum.filter(fn elem ->
is_map(elem) and Map.has_key?(elem, :score) and elem.score / elem.out_of * 100 < 40
|> Enum.count(fn elem ->
is_resource_access?(elem) and has_score?(elem) and
score(elem.score) / out_of_score(elem.out_of) * 100 < 40
end)
|> length()

~F"""
<div class="ml-8" data-score-check={if resource_accesses_approved > 0, do: "false", else: "true"}>
<div class="ml-8" data-score-check={if disapproved_count > 0, do: "false", else: "true"}>
{OliWeb.Common.Utils.name(row.user)}
</div>
"""
end

defp is_resource_access?(%Oli.Delivery.Attempts.Core.ResourceAccess{}), do: true
defp is_resource_access?(_), do: false

defp has_score?(%Oli.Delivery.Attempts.Core.ResourceAccess{score: nil}), do: false
defp has_score?(%Oli.Delivery.Attempts.Core.ResourceAccess{}), do: true

defp out_of_score(nil), do: 1
defp out_of_score(0), do: 1
defp out_of_score(0.0), do: 1
defp out_of_score(number), do: number

defp score(nil), do: 0
defp score(number), do: number

def render_score(assigns, row, %ColumnSpec{name: resource_id}) do
case Map.get(row, resource_id) do
# Indicates that this student has never visited this resource
Expand Down Expand Up @@ -161,12 +180,10 @@ defmodule OliWeb.Grades.GradebookTableModel do
out_of: out_of
}
) do
link_type = "bg-white text-red-500"

if out_of == 0 or out_of == 0.0 do
~F"""
<a class={link_type} href={Routes.live_path(OliWeb.Endpoint, OliWeb.Progress.StudentResourceView, row.section.slug, row.id, resource_id)}>
<span>{score}/{out_of} 0%</span>
<a class="text-red-500" href={Routes.live_path(OliWeb.Endpoint, OliWeb.Progress.StudentResourceView, row.section.slug, row.id, resource_id)}>
<span>{score}/{out_of}</span>
</a>
"""
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ defmodule OliWeb.Delivery.InstructorDashboard.QuizScoreTabTest do
assert has_element?(view, "h6", "There are no quiz scores to show")
end

test "loads correctly when a student has not yet finished a quiz", %{
conn: conn,
section: section,
instructor: instructor,
student_with_gating_condition: student,
graded_page_1: graded_page_1
} do
insert(:resource_access,
user: student,
section: section,
resource: graded_page_1.resource,
score: nil,
out_of: nil
)

Sections.enroll(instructor.id, section.id, [ContextRoles.get_role(:context_instructor)])

{:ok, view, _html} = live(conn, live_view_quiz_scores_route(section.slug))

assert has_element?(view, "h4", "Quiz Scores")
end

test "applies searching", %{
conn: conn,
section: section,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ defmodule OliWeb.Delivery.StudentDashboard.Components.QuizzScoresTabTest do
assert has_element?(view, "h6", "There are no quiz scores to show")
end

test "gets rendered correctly for a student that has not yet finished a quizz", %{
conn: conn,
section: section,
instructor: instructor,
student_with_gating_condition: student,
graded_page_1: graded_page_1
} do
insert(:resource_access,
user: student,
section: section,
resource: graded_page_1.resource,
score: nil,
out_of: nil
)

Sections.enroll(instructor.id, section.id, [ContextRoles.get_role(:context_instructor)])

{:ok, view, _html} =
live(conn, live_view_students_dashboard_route(section.slug, student.id, :quizz_scores))

assert has_element?(view, "a", "Not Finished")
end

test "applies searching", %{
conn: conn,
section: section,
Expand Down

0 comments on commit 57f32ee

Please sign in to comment.