Skip to content

Commit

Permalink
Merge branch 'Simon-Initiative:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dtiwarATS authored Dec 12, 2024
2 parents d04ed7a + 77e9c97 commit d97c589
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
19 changes: 11 additions & 8 deletions lib/oli_web/live/delivery/student/learn_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ defmodule OliWeb.Delivery.Student.LearnLive do
>
<div class="dark:text-white text-[13px] font-semibold">
<%= parse_module_total_pages(@page_metrics.total_pages_count) <>
if parsed_minutes, do: " · #{parsed_minutes}" %>
maybe_add_separator(@page_metrics.total_pages_count, parsed_minutes) <> "#{parsed_minutes}" %>
</div>
</div>
"""
Expand Down Expand Up @@ -2426,12 +2426,15 @@ defmodule OliWeb.Delivery.Student.LearnLive do
class="hidden dark:text-white text-[13px] font-semibold pointer-events-none"
>
<%= parse_module_total_pages(@page_metrics.total_pages_count) <>
if parsed_minutes, do: " · #{parsed_minutes}" %>
maybe_add_separator(@page_metrics.total_pages_count, parsed_minutes) <> "#{parsed_minutes}" %>
</div>
</div>
"""
end

def maybe_add_separator(total_pages_count, parsed_minutes),
do: if(total_pages_count > 0 and parsed_minutes != "", do: " · ", else: "")

def video_player(assigns) do
~H"""
<div id="student_video_wrapper" phx-hook="VideoPlayer" class="hidden">
Expand Down Expand Up @@ -3051,17 +3054,17 @@ defmodule OliWeb.Delivery.Student.LearnLive do
|> Timex.Duration.to_clock()

case {clock_duration, resource_type} do
{{hours, minutes, _seconds, _milliseconds}, :module} when hours > 0 ->
{{hours, minutes, _seconds, _milliseconds}, _resource_type} when hours > 0 ->
"#{hours}h #{minutes}m"

{{_, minutes, _seconds, _milliseconds}, :module} ->
{{_, minutes, _seconds, _milliseconds}, :module} when minutes > 0 ->
"#{minutes}m"

{{hours, minutes, _seconds, _milliseconds}, :page} when hours > 0 ->
"#{hours}h #{minutes}m"

{{_, minutes, _seconds, _milliseconds}, :page} ->
{{_, minutes, _seconds, _milliseconds}, :page} when minutes > 0 ->
"#{minutes} min"

{{_, _, _seconds, _milliseconds}, _} ->
""
end
end

Expand Down
38 changes: 36 additions & 2 deletions test/oli_web/live/delivery/student/learn_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ defmodule OliWeb.Delivery.Student.ContentLiveTest do
page_5_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 5"
title: "Page 5",
duration_minutes: 0
)

page_6_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 6"
title: "Page 6",
duration_minutes: 0
)

page_7_revision =
Expand Down Expand Up @@ -2011,6 +2013,38 @@ defmodule OliWeb.Delivery.Student.ContentLiveTest do

refute render(view) =~ "Page 7"
end

test "modules do not show duration minutes if duration is 0", %{
conn: conn,
section: section,
module_3: module_3,
page_5: page_5,
page_6: page_6
} do
{:ok, view, _html} = live(conn, Utils.learn_live_path(section.slug))

view
|> element(~s{div[id="module_#{module_3.resource_id}"]})
|> render_click()

# assert that page 5 and page 6 have duration 0
assert page_5.duration_minutes == 0
assert page_6.duration_minutes == 0

# assert that module 3 contains 2 pages (page 5 and page 6)
assert has_element?(
view,
~s{div[id="module_#{module_3.resource_id}"] div[role="card badge"]},
"2 pages"
)

# assert that module 3 does not show duration minutes (since it is 0)
refute has_element?(
view,
~s{div[id="module_#{module_3.resource_id}"] div[role="card badge"]},
"0 minutes"
)
end
end

describe "student" do
Expand Down

0 comments on commit d97c589

Please sign in to comment.