Skip to content

Commit

Permalink
[MER-4105] Remove any reference to autosubmit on assessment terms dis…
Browse files Browse the repository at this point in the history
…played to student (#5294)
  • Loading branch information
Francisco-Castro authored Dec 9, 2024
1 parent 5e908e2 commit b04f7bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 256 deletions.
128 changes: 2 additions & 126 deletions lib/oli_web/live/delivery/student/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,6 @@ defmodule OliWeb.Delivery.Student.Utils do
<.page_due_term effective_settings={@effective_settings} ctx={@ctx} />
</li>
<.maybe_add_time_limit_term effective_settings={@effective_settings} />
<li
:if={
@effective_settings.end_date != nil and @effective_settings.scheduling_type == :due_by and
!@is_adaptive and
(@effective_settings.late_submit == :disallow or
(@effective_settings.late_submit == :allow and @effective_settings.time_limit > 0))
}
id="page_submission_terms"
>
<.page_submission_term effective_settings={@effective_settings} ctx={@ctx} />
</li>
<li :if={@effective_settings.end_date != nil} id="page_scoring_terms">
<%= page_scoring_term(@effective_settings.scoring_strategy_id) %>
</li>
Expand All @@ -212,18 +201,10 @@ defmodule OliWeb.Delivery.Student.Utils do

defp maybe_add_time_limit_term(%{effective_settings: %{time_limit: time_limit}} = assigns)
when time_limit > 0 do
minute_label =
case time_limit do
1 -> "minute"
_ -> "minutes"
end

assigns = assign(assigns, minute_label: minute_label)

~H"""
<li id="page_time_limit_term">
You have <b><%= @effective_settings.time_limit %> <%= @minute_label %></b>
to complete the assessment. If you exceed this time, it will be marked as late.
You have <b><%= parse_minutes(@effective_settings.time_limit) %></b>
to complete the assessment from the time you begin. If you exceed this time, it will be marked as late.
</li>
"""
end
Expand Down Expand Up @@ -266,111 +247,6 @@ defmodule OliWeb.Delivery.Student.Utils do
defp scheduling_type(:due_by), do: "due on"
defp scheduling_type(_scheduling_type), do: "suggested by"

defp page_submission_term(%{effective_settings: %{time_limit: 0, grace_period: 0}} = assigns) do
~H"""
<div>
<span>
Your work will automatically be submitted at
</span>
<span class="font-bold">
<%= FormatDateTime.to_formatted_datetime(
@effective_settings.end_date,
@ctx,
"{h12}:{m}{am} on {WDshort} {Mshort} {D}, {YYYY}."
) %>
</span>
</div>
"""
end

defp page_submission_term(
%{effective_settings: %{time_limit: 0, grace_period: grace_period}} = assigns
)
when grace_period > 0 do
~H"""
<div>
<span>
Your work will automatically be submitted at
</span>
<span class="font-bold">
<%= Timex.shift(@effective_settings.end_date, minutes: @effective_settings.grace_period)
|> FormatDateTime.to_formatted_datetime(
@ctx,
"{h12}:{m}{am} on {WDshort} {Mshort} {D}, {YYYY}."
) %>
</span>
</div>
"""
end

defp page_submission_term(
%{effective_settings: %{time_limit: time_limit, grace_period: 0}} = assigns
)
when time_limit > 0 do
~H"""
<div>
<span>
Your work will automatically be submitted
</span>
<span class="font-bold">
<%= parse_minutes(@effective_settings.time_limit) %>
</span>
<span>
after you click the Begin button
</span>
</div>
"""
end

defp page_submission_term(
%{
effective_settings: %{
time_limit: time_limit,
grace_period: grace_period,
end_date: end_date
}
} = assigns
)
when time_limit > 0 and grace_period > 0 do
# when we have both time limit and grace period,
# the end date time that comes first is the one that should be considered.
# For calculating the start_date_with_time_limit we assume the student is about to begin the attempt
now = Oli.DateTime.utc_now()
start_date_with_time_limit = Timex.shift(now, minutes: time_limit)
end_date_with_grace_period = Timex.shift(end_date, minutes: grace_period)

if DateTime.compare(start_date_with_time_limit, end_date_with_grace_period) == :lt do
~H"""
<div>
<span>
Your work will automatically be submitted
</span>
<span class="font-bold">
<%= parse_minutes(@effective_settings.time_limit) %>
</span>
<span>
after you click the Begin button
</span>
</div>
"""
else
~H"""
<div>
<span>
Your work will automatically be submitted at
</span>
<span class="font-bold">
<%= Timex.shift(@effective_settings.end_date, minutes: @effective_settings.grace_period)
|> FormatDateTime.to_formatted_datetime(
@ctx,
"{h12}:{m}{am} on {WDshort} {Mshort} {D}, {YYYY}."
) %>
</span>
</div>
"""
end
end

@doc """
Parses the minutes into a human-readable format.
Expand Down
158 changes: 28 additions & 130 deletions test/oli_web/live/delivery/student/prologue_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,169 +1063,67 @@ defmodule OliWeb.Delivery.Student.PrologueLiveTest do
section: section,
page_5: page_5
} do
Sections.enroll(user.id, section.id, [ContextRoles.get_role(:context_learner)])
Sections.mark_section_visited_for_student(section, user)
enroll_and_mark_visited(user, section)

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_5.slug))

assert view |> element("#page_terms") |> render() =~
"This assignment is <b>not yet scheduled.</b>"
end

test "page terms are shown correctly when page is scheduled",
%{
conn: conn,
user: user,
section: section,
page_2: page_2,
graded_adaptive_page_revision: graded_adaptive_page
} do
Sections.enroll(user.id, section.id, [ContextRoles.get_role(:context_learner)])
Sections.mark_section_visited_for_student(section, user)

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))

assert view
|> element("#page_due_terms")
|> render() =~
"This assignment was due on"
test "page terms render the due date when is set", ctx do
%{conn: conn, user: user, section: section, page_2: page_2} = ctx

assert view
|> element("#page_due_terms")
|> render() =~
"Tue Nov 14, 2023 by 8:00pm."

assert view
|> element("#page_submission_terms")
|> render() =~
"Your work will automatically be submitted at"

assert view
|> element("#page_submission_terms")
|> render() =~
"8:00pm on Tue Nov 14, 2023"

assert view
|> element("#page_scoring_terms")
|> render() =~
"Your overall score for this assignment will be the score of your best attempt."

Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{
scoring_strategy_id: 1,
time_limit: 90
})
enroll_and_mark_visited(user, section)

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))

assert view
|> element("#page_submission_terms")
|> render() =~
"Your work will automatically be submitted"

assert view
|> element("#page_submission_terms")
|> render() =~
"1 hour and 30 minutes"

assert view
|> element("#page_submission_terms")
|> render() =~
"after you click the Begin button"
assert view |> element("#page_due_terms") |> render() =~ "This assignment was due on"

assert view
|> element("#page_scoring_terms")
|> render() =~
"Your overall score for this assignment will be the average score of your attempts."

# submission terms shouln't be visible when scheduling type is read_by
Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{
scheduling_type: :read_by
})

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))

refute has_element?(view, "#page_submission_terms")
assert view |> element("#page_due_terms") |> render() =~ "Tue Nov 14, 2023 by 8:00pm."
end

# submission terms shouldn't be visible when late submit is allowed and time_limit = 0
Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{
scheduling_type: :due_by,
late_submit: :allow,
time_limit: 0
})
test "page terms are shown correctly when page is scheduled", ctx do
%{conn: conn, user: user, section: section, page_2: page_2} = ctx

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))
enroll_and_mark_visited(user, section)

refute has_element?(view, "#page_submission_terms")
params = %{scoring_strategy_id: 1}

# submission terms should be visible when late submit is allowed and time limit > 0
Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{
scheduling_type: :due_by,
late_submit: :allow,
time_limit: 33
})
get_and_update_section_resource(section.id, page_2.resource_id, params)

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))

assert view
|> element("#page_submission_terms")
|> render() =~
"Your work will automatically be submitted"

assert view
|> element("#page_submission_terms")
|> render() =~
"33 minutes"

assert view
|> element("#page_submission_terms")
|> render() =~
"after you click the Begin button"

# submission terms shouln't be visible in prologue for adaptive pages
Sections.get_section_resource(section.id, graded_adaptive_page.resource_id)
|> Sections.update_section_resource(%{
start_date: ~U[2023-11-10 20:00:00Z],
end_date: ~U[2023-11-14 20:00:00Z],
late_submit: :disallow,
scheduling_type: :due_by
})

{:ok, view, _html} =
live(conn, Utils.prologue_live_path(section.slug, graded_adaptive_page.slug))

refute has_element?(view, "#page_submission_terms")
assert view |> element("#page_scoring_terms") |> render() =~
"Your overall score for this assignment will be the average score of your attempts."
end

test "page terms display a time limit message", ctx do
test "page terms render a time limit message", ctx do
%{conn: conn, user: user, section: section, page_2: page_2} = ctx

Sections.enroll(user.id, section.id, [ContextRoles.get_role(:context_learner)])
Sections.mark_section_visited_for_student(section, user)
enroll_and_mark_visited(user, section)

params = %{time_limit: 1}

# Singular case
Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{time_limit: 1})
get_and_update_section_resource(section.id, page_2.resource_id, params)

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))

assert view |> element("#page_due_terms") |> render() =~
"This assignment was due on"

assert view |> element("#page_time_limit_term") |> render() =~
"You have <b>1 minute</b>\n to complete the assessment. If you exceed this time, it will be marked as late."

# Plural case
Sections.get_section_resource(section.id, page_2.resource_id)
|> Sections.update_section_resource(%{time_limit: 2})
"<li id=\"page_time_limit_term\">\n You have <b>1 minute</b>\n to complete the assessment from the time you begin. If you exceed this time, it will be marked as late.\n</li>"
end

{:ok, view, _html} = live(conn, Utils.prologue_live_path(section.slug, page_2.slug))
defp enroll_and_mark_visited(user, section) do
Sections.enroll(user.id, section.id, [ContextRoles.get_role(:context_learner)])
Sections.mark_section_visited_for_student(section, user)
end

assert view |> element("#page_time_limit_term") |> render() =~
"You have <b>2 minutes</b>\n to complete the assessment. If you exceed this time, it will be marked as late."
defp get_and_update_section_resource(section_id, resource_id, updated_params) do
Sections.get_section_resource(section_id, resource_id)
|> Sections.update_section_resource(updated_params)
end
end

Expand Down

0 comments on commit b04f7bd

Please sign in to comment.