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 23, 2024
2 parents d0f482a + 65364df commit 15c680d
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/oli/publishing/delivery_resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Oli.Publishing.DeliveryResolver do
from([sr, s, _spp, _pr, rev] in section_resource_revisions(section_slug),
where: rev.resource_type_id == 1 and rev.graded == true,
select: {rev, sr},
order_by: [asc: sr.numbering_level, asc: sr.numbering_index]
order_by: sr.numbering_index
)
|> Repo.all()
end
Expand Down
11 changes: 9 additions & 2 deletions lib/oli_web/live/sections/assessment_settings/settings_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,11 @@ defmodule OliWeb.Sections.AssessmentSettings.SettingsTable do
end

defp sort_by(assessments, sort_by, sort_order) do
to_unix = fn
nil -> 0
datetime -> DateTime.to_unix(datetime)
end

case sort_by do
:late_policy ->
Enum.sort_by(
Expand All @@ -1011,12 +1016,14 @@ defmodule OliWeb.Sections.AssessmentSettings.SettingsTable do
)

:available_date ->
Enum.sort_by(assessments, fn a -> a.start_date end, sort_order)
Enum.sort_by(assessments, fn a -> to_unix.(a.start_date) end, sort_order)

:due_date ->
Enum.sort_by(
assessments,
fn a -> if a.scheduling_type == :due_by, do: a.end_date, else: nil end,
fn a ->
if a.scheduling_type == :due_by, do: to_unix.(a.end_date), else: 0
end,
sort_order
)

Expand Down
155 changes: 155 additions & 0 deletions test/oli/publishing/delivery_resolver_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Oli.Publishing.DeliveryResolverTest do

alias Oli.Publishing.DeliveryResolver
alias Oli.Resources.ResourceType
alias Oli.Delivery.Sections

describe "delivery resolution" do
setup do
Expand Down Expand Up @@ -270,4 +271,158 @@ defmodule Oli.Publishing.DeliveryResolverTest do
[]
end
end

describe "graded_pages_revisions_and_section_resources/1" do
setup [:create_elixir_project]

test "returns graded pages in order", %{
section: section
} do
pages = DeliveryResolver.graded_pages_revisions_and_section_resources(section.slug)

assert length(pages) == 3

assert Enum.map(pages, fn {rev, _} -> rev.title end) == [
"Page 1",
"Page 2",
"Page 4"
]
end
end

defp create_elixir_project(_) do
author = insert(:author)
project = insert(:project, authors: [author])

# revisions...

## pages...
page_1_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 1",
graded: true
)

page_2_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 2",
graded: true
)

page_3_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 3"
)

page_4_revision =
insert(:revision,
resource_type_id: ResourceType.get_id_by_type("page"),
title: "Page 4",
graded: true
)

## modules...
module_1_revision =
insert(:revision, %{
resource_type_id: Oli.Resources.ResourceType.get_id_by_type("container"),
children: [
page_1_revision.resource_id,
page_2_revision.resource_id
],
title: "Module 1"
})

module_2_revision =
insert(:revision, %{
resource_type_id: Oli.Resources.ResourceType.get_id_by_type("container"),
children: [page_3_revision.resource_id],
title: "Module 2"
})

## units...
unit_1_revision =
insert(:revision, %{
resource_type_id: Oli.Resources.ResourceType.get_id_by_type("container"),
children: [
module_1_revision.resource_id,
module_2_revision.resource_id,
page_4_revision.resource_id
],
title: "Unit 1"
})

## root container...
container_revision =
insert(:revision, %{
resource_type_id: Oli.Resources.ResourceType.get_id_by_type("container"),
children: [
unit_1_revision.resource_id
],
title: "Root Container"
})

all_revisions =
[
page_1_revision,
page_2_revision,
page_3_revision,
page_4_revision,
module_1_revision,
module_2_revision,
unit_1_revision,
container_revision
]

# asociate resources to project
Enum.each(all_revisions, fn revision ->
insert(:project_resource, %{
project_id: project.id,
resource_id: revision.resource_id
})
end)

# publish project
publication =
insert(:publication, %{project: project, root_resource_id: container_revision.resource_id})

# publish resources
Enum.each(all_revisions, fn revision ->
insert(:published_resource, %{
publication: publication,
resource: revision.resource,
revision: revision,
author: author
})
end)

# create section...
section =
insert(:section,
base_project: project,
title: "The best course ever!",
start_date: ~U[2023-10-30 20:00:00Z],
analytics_version: :v2
)

{:ok, section} = Sections.create_section_resources(section, publication)
{:ok, _} = Sections.rebuild_contained_pages(section)
{:ok, _} = Sections.rebuild_contained_objectives(section)

%{
author: author,
section: section,
project: project,
publication: publication,
page_1: page_1_revision,
page_2: page_2_revision,
page_3: page_3_revision,
page_4: page_4_revision,
module_1: module_1_revision,
module_2: module_2_revision,
unit_1: unit_1_revision
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -1152,11 +1152,11 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a0, a1, a2, a3, a4] = table_as_list_of_maps(view, :assessments)

assert has_element?(view, "h4", "Scored Activities")
assert a0.title == "Orphaned Page"
assert a1.title == "Module 1: IntroductionPage 1"
assert a2.title == "Module 1: IntroductionPage 2"
assert a3.title == "Module 2: BasicsPage 3"
assert a4.title == "Module 2: BasicsPage 4"
assert a0.title == "Module 1: IntroductionPage 1"
assert a1.title == "Module 1: IntroductionPage 2"
assert a2.title == "Module 2: BasicsPage 3"
assert a3.title == "Module 2: BasicsPage 4"
assert a4.title == "Orphaned Page"
end

# NON-DETERMINISTIC: https://eliterate.atlassian.net/browse/TRIAGE-4 Fix or remove
Expand Down Expand Up @@ -1222,43 +1222,42 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
section: section
} do
{:ok, view, _html} = live(conn, live_view_scored_activities_route(section.slug))
[a0, _a1, _a2, _a3, a4] = table_as_list_of_maps(view, :assessments)

assert view
|> element("tr:first-child > td:first-child > div")
|> render() =~ a0.order
|> render() =~ "1"

assert view
|> element("tr:first-child > td:nth-child(2) > div")
|> render() =~ a0.title
|> render() =~ "Page 1"

assert view
|> element("tr:last-child > td:first-child > div")
|> render() =~ a4.order
|> render() =~ "5"

assert view
|> element("tr:last-child > td:nth-child(2) > div > div")
|> render() =~ "Page 4"
|> render() =~ "Orphaned Page"

view
|> element("th[phx-value-sort_by=order]")
|> render_click()

assert view
|> element("tr:first-child > td:first-child > div")
|> render() =~ a4.order
|> render() =~ "5"

assert view
|> element("tr:first-child > td:nth-child(2) > div > div > a")
|> render() =~ "Page 4"
|> render() =~ "Orphaned Page"

assert view
|> element("tr:last-child > td:first-child > div")
|> render() =~ a0.order
|> render() =~ "1"

assert view
|> element("tr:last-child > td:nth-child(2) > div")
|> render() =~ a0.title
|> render() =~ "Page 1"
end

test "displays custom labels", %{
Expand All @@ -1275,11 +1274,11 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a0, a1, a2, a3, a4] = table_as_list_of_maps(view, :assessments)

assert has_element?(view, "h4", "Scored Activities")
assert a0.title == "Orphaned Page"
assert a1.title == "Chapter 1: IntroductionPage 1"
assert a2.title == "Chapter 1: IntroductionPage 2"
assert a3.title == "Chapter 2: BasicsPage 3"
assert a4.title == "Chapter 2: BasicsPage 4"
assert a0.title == "Chapter 1: IntroductionPage 1"
assert a1.title == "Chapter 1: IntroductionPage 2"
assert a2.title == "Chapter 2: BasicsPage 3"
assert a3.title == "Chapter 2: BasicsPage 4"
assert a4.title == "Orphaned Page"
end

test "patches url to see activity details when a row is clicked", %{
Expand Down Expand Up @@ -2320,11 +2319,11 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do

[a0, a1, a2, a3, a4] = table_as_list_of_maps(view, :assessments)

assert a0.title == "Orphaned Page"
assert a1.title == "Module 1: IntroductionPage 1"
assert a2.title == "Module 1: IntroductionPage 2"
assert a3.title == "Module 2: BasicsPage 3"
assert a4.title == "Module 2: BasicsPage 4"
assert a0.title == "Module 1: IntroductionPage 1"
assert a1.title == "Module 1: IntroductionPage 2"
assert a2.title == "Module 2: BasicsPage 3"
assert a3.title == "Module 2: BasicsPage 4"
assert a4.title == "Orphaned Page"

# It does not display pagination options
refute has_element?(view, "nav[aria-label=\"Paging\"]")
Expand All @@ -2347,8 +2346,8 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a0, a1] = table_as_list_of_maps(view, :assessments)

# Page 1
assert a0.title == "Orphaned Page"
assert a1.title == "Module 1: IntroductionPage 1"
assert a0.title == "Module 1: IntroductionPage 1"
assert a1.title == "Module 1: IntroductionPage 2"
end

test "change page size works as expected", %{
Expand All @@ -2368,8 +2367,8 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a0, a1] = table_as_list_of_maps(view, :assessments)

# Page 1
assert a0.title == "Orphaned Page"
assert a1.title == "Module 1: IntroductionPage 1"
assert a0.title == "Module 1: IntroductionPage 1"
assert a1.title == "Module 1: IntroductionPage 2"

# Assert that the pagination options are displayed
assert has_element?(view, "nav[aria-label=\"Paging\"]")
Expand All @@ -2382,8 +2381,8 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a2, a3] = table_as_list_of_maps(view, :assessments)

# Page 2
assert a2.title == "Module 1: IntroductionPage 2"
assert a3.title == "Module 2: BasicsPage 3"
assert a2.title == "Module 2: BasicsPage 3"
assert a3.title == "Module 2: BasicsPage 4"
end

test "keeps showing the same elements when changing the page size", %{
Expand All @@ -2402,8 +2401,8 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a2, a3] = table_as_list_of_maps(view, :assessments)

# Page 2
assert a2.title == "Module 1: IntroductionPage 2"
assert a3.title == "Module 2: BasicsPage 3"
assert a2.title == "Module 2: BasicsPage 3"
assert a3.title == "Module 2: BasicsPage 4"

# Change page size from 2 to 1
view
Expand All @@ -2413,7 +2412,7 @@ defmodule OliWeb.Delivery.InstructorDashboard.ScoredActivitiesTabTest do
[a2] = table_as_list_of_maps(view, :assessments)

# Page 3. It keeps showing the same element.
assert a2.title == "Module 1: IntroductionPage 2"
assert a2.title == "Module 2: BasicsPage 3"
end
end
end
Loading

0 comments on commit 15c680d

Please sign in to comment.