Skip to content

Commit

Permalink
refactor: Model field updated, more test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf committed Dec 2, 2024
1 parent 03afb18 commit 5ff3ae8
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class CourseOverviewPageFactory(wagtail_factories.PageFactory):
"""CourseOverviewPage factory class"""

heading = factory.fuzzy.FuzzyText(prefix="heading ")
sub_heading = factory.LazyFunction(lambda: RichText(f"<p>{FAKE.paragraph()}</p>"))
overview = factory.LazyFunction(lambda: RichText(f"<p>{FAKE.paragraph()}</p>"))

class Meta:
model = CourseOverviewPage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.16 on 2024-11-22 13:32
# Generated by Django 4.2.16 on 2024-11-29 10:50

import django.db.models.deletion
import wagtail.fields
Expand Down Expand Up @@ -38,7 +38,7 @@ class Migration(migrations.Migration):
),
),
(
"sub_heading",
"overview",
wagtail.fields.RichTextField(
blank=True,
help_text="A subheading to provide additional context or information.",
Expand Down
11 changes: 9 additions & 2 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,15 +2656,22 @@ class CourseOverviewPage(CourseProgramChildPage):
blank=True,
)

sub_heading = RichTextField(
overview = RichTextField(
help_text="A subheading to provide additional context or information.",
null=True,
blank=True,
)

@property
def get_overview(self):
"""Returns overview else parent description"""
return (
self.overview if self.overview else self.get_parent().specific.description
)

content_panels = [
FieldPanel("heading"),
FieldPanel("sub_heading"),
FieldPanel("overview"),
]

class Meta:
Expand Down
110 changes: 100 additions & 10 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,27 +2093,117 @@ def test_certificatepage_saved_no_signatories_external_courseware(
assert resp.status_code == 302


def test_course_overview_page():
external_course_page = ExternalCoursePageFactory.create()
assert not external_course_page.course_overview
assert CourseOverviewPage.can_create_at(external_course_page)
def _test_course_overview(page):
"""
Tests the creation and modification of a CourseOverviewPage
associated with a given page.
Args:
page: The parent page under which the CourseOverviewPage is created.
Can be one of the following types:
- `ExternalCoursePage`
- `CoursePage`
- `ProgramPage`
- `ExternalProgramPage`
"""
assert not page.course_overview
assert CourseOverviewPage.can_create_at(page)
overview_page = CourseOverviewPageFactory.create(
parent=external_course_page,
sub_heading="<p>paragraph content</p>",
parent=page,
heading="test heading",
overview="<p>paragraph content</p>",
)

# invalidate cached property
del external_course_page.child_pages
del page.child_pages

assert overview_page.get_parent() == external_course_page
assert external_course_page.course_overview == overview_page
assert overview_page.get_parent() == page
assert page.course_overview == overview_page
assert overview_page.heading == "test heading"
assert overview_page.sub_heading == "<p>paragraph content</p>"
assert overview_page.get_overview == "<p>paragraph content</p>"

# test that it can be modified
new_heading = "new test heading"
overview_page.heading = new_heading
overview_page.save()

assert overview_page.heading == new_heading


def test_course_overview_page_with_external_course_page():
"""Tests the integration of an CourseOverviewPage with a ExternalCoursePage."""
external_course_page = ExternalCoursePageFactory.create()
_test_course_overview(external_course_page)


def test_course_overview_with_course_page():
"""Tests the creation and behavior of a CourseOverviewPage associated with a CoursePage."""
course_page = CoursePageFactory.create()
_test_course_overview(course_page)


def test_course_overview_with_program_page():
"""Tests the creation and behavior of a CourseOverviewPage associated with a ProgramPage."""
program_page = ProgramPageFactory.create()
_test_course_overview(program_page)


def test_course_overview_with_external_program_page():
"""Tests the creation and behavior of a CourseOverviewPage associated with an ExternalProgramPage."""
external_program_page = ExternalProgramPageFactory.create()
_test_course_overview(external_program_page)


def test_course_overview_without_overview_and_heading():
"""Tests the behavior of a CourseOverviewPage when created without an overview or heading."""
page = ExternalCoursePageFactory.create()
assert not page.course_overview
assert CourseOverviewPage.can_create_at(page)
overview_page = CourseOverviewPageFactory.create(
parent=page,
overview=None,
heading=None,
)

# invalidate cached property
del page.child_pages

assert overview_page.heading is None
assert overview_page.get_overview == ""

# test that it can be modified
new_heading = "new heading"
new_overview = "new test overview"
overview_page.heading = new_heading
overview_page.overview = new_overview
overview_page.save()

assert overview_page.get_overview == new_overview
assert overview_page.heading == new_heading


def test_course_overview_with_course_description():
"""
Tests the behavior of a CourseOverviewPage when created
without an overview and get_overview matches with its course description.
"""
course_description = "<p>testing description</p>"
page = ExternalCoursePageFactory.create(description=course_description)
assert not page.course_overview
assert CourseOverviewPage.can_create_at(page)
overview_page = CourseOverviewPageFactory.create(
parent=page,
overview=None,
)

# invalidate cached property
del page.child_pages

assert overview_page.get_overview == course_description

# test that it can be modified
new_overview = "new test overview"
overview_page.overview = new_overview
overview_page.save()

assert overview_page.overview == new_overview
26 changes: 8 additions & 18 deletions cms/templates/partials/course-overview.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
{% load static wagtailimages_tags wagtailcore_tags %}
<div
id="courseOverview"
class="text-block {% if page.dark_theme %} dark-theme {% endif %}"
>
<div class="container section-spacing">
<div class="row justify-content-center">
<div class="col-lg-10">
{% if page.heading %}
<h1 class="text-center">{{ page.heading }}</h1>
{% endif %}

{% if page.sub_heading %}
{{ page.sub_heading|richtext }}
{% else %}
{{ page.get_parent.specific.description|richtext }}
{% endif %}
</div>
{% load static wagtailcore_tags %}
<div id="courseOverview" class="course-overview-block section-spacing">
<div class="container">
<div class="course-overview-heading">
{% if page.heading %}
<h1>{{ page.heading | safe }}</h1>
{% endif %}
{{ page.get_overview | richtext }}
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion cms/templates/partials/subnav.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</a>
<div id="subNavBar" class="collapse navbar-collapse justify-content-center">
<ul class="navbar-nav container justify-content-center">
{% if course_overview %}
{% if course_overview and course_overview.heading or course_overview.get_overview %}
<li class="nav-item px-2 d-flex align-items-center">
<a class="nav-link text-center" href="#courseOverview">Overview</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion cms/templates/product_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% include "partials/hero.html" %}
{% include "partials/metadata-tiles.html" %}
{% include "partials/subnav.html" with product=page.product %}
{% if course_overview %}
{% if course_overview and course_overview.heading or course_overview.get_overview %}
{% include "partials/course-overview.html" with page=course_overview %}
{% endif %}
{% if outcomes %}
Expand Down
18 changes: 18 additions & 0 deletions static/scss/detail/course-overview.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// sass-lint:disable mixins-before-declarations
@import "common";

.course-overview-block {
background: white url("#{$static-path}/images/dotted-bg.png") repeat-x 0 0;

.course-overview-heading {
margin: 0 auto;
max-width: 1000px;
text-align: center;
}

h1 {
max-width: 700px;
margin: 0 auto 20px;
color: $primary;
}
}
1 change: 1 addition & 0 deletions static/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@import "detail/companies-trust";
@import "detail/text-section";
@import "detail/catalog-topics";
@import "detail/course-overview";
@import "ecommerce-admin";
@import "resource";
@import "notification";
Expand Down

0 comments on commit 5ff3ae8

Please sign in to comment.