Skip to content

Commit

Permalink
Renaming enroll now button for archived courses (#2226)
Browse files Browse the repository at this point in the history
* Renaming enroll now button for archived courses

* lint

* format

* test
  • Loading branch information
annagav authored May 30, 2024
1 parent 8356272 commit 9f94faf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
9 changes: 2 additions & 7 deletions frontend/public/src/components/CourseInfoBox.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from "react"
import {
formatPrettyDate,
emptyOrNil,
getFlexiblePriceForProduct,
formatLocalePrice,
parseDateString,
formatPrettyShortDate
} from "../lib/util"
import { getFirstRelevantRun } from "../lib/courseApi"
import { getFirstRelevantRun, isRunArchived } from "../lib/courseApi"
import moment from "moment-timezone"

import type { BaseCourseRun } from "../flow/courseTypes"
Expand Down Expand Up @@ -166,11 +165,7 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
const course = courses[0]
const run = getFirstRelevantRun(course, courseRuns)
const product = run && run.products.length > 0 && run.products[0]
const isArchived = run
? moment().isAfter(run.end_date) &&
(moment().isBefore(run.enrollment_end) ||
emptyOrNil(run.enrollment_end))
: false
const isArchived = isRunArchived(run)

const startDates = []
const moreEnrollableCourseRuns = courseRuns && courseRuns.length > 1
Expand Down
3 changes: 2 additions & 1 deletion frontend/public/src/components/CourseProductDetailEnroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { formatPrettyDate, emptyOrNil } from "../lib/util"
import moment from "moment-timezone"
import {
getFirstRelevantRun,
isRunArchived,
isEnrollmentFuture,
isFinancialAssistanceAvailable
} from "../lib/courseApi"
Expand Down Expand Up @@ -481,7 +482,7 @@ export class CourseProductDetailEnroll extends React.Component<
className="btn btn-primary btn-enrollment-button btn-gradient-red highlight enroll-now"
disabled={!run.is_enrollable}
>
Enroll now
{isRunArchived(run) ? "Access Course Materials" : "Enroll Now"}
</button>
</form>
)}
Expand Down
53 changes: 49 additions & 4 deletions frontend/public/src/components/CourseProductDetailEnroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ describe("CourseProductDetailEnrollShallowRender", () => {
.find(".enroll-now")
.at(0)
.text(),
"Enroll now"
"Enroll Now"
)
})

it("checks for enroll now button should not appear if enrollment start in future", async () => {
it("checks for enroll now button should appear disabled if enrollment start in future", async () => {
const courseRun = makeCourseRunDetail()
courseRun["is_enrollable"] = false
const { inner } = await renderPage(
Expand Down Expand Up @@ -170,7 +170,52 @@ describe("CourseProductDetailEnrollShallowRender", () => {
.find(".enroll-now")
.at(0)
.text(),
"Enroll now"
"Enroll Now"
)
})

it("checks for access course materials button should appear if course is archived", async () => {
const courseRun = {
...makeCourseRunDetail(),
enrollment_end: null,
enrollment_start: moment()
.subtract(1, "years")
.toISOString(),
start_date: moment()
.subtract(10, "months")
.toISOString(),
end_date: moment()
.subtract(7, "months")
.toISOString(),
upgrade_deadline: null
}
const { inner } = await renderPage(
{
entities: {
courseRuns: [courseRun]
},
queries: {
courseRuns: {
isPending: false,
status: 200
}
}
},
{}
)

assert.equal(
inner
.find(".enroll-now")
.at(0)
.text(),
"Access Course Materials"
)
assert.isFalse(
inner
.find(".enroll-now")
.at(0)
.prop("disabled")
)
})

Expand All @@ -196,7 +241,7 @@ describe("CourseProductDetailEnrollShallowRender", () => {
.find("form > button.enroll-now")
.at(0)
.text(),
"Enroll now"
"Enroll Now"
)
})
;[
Expand Down
14 changes: 13 additions & 1 deletion frontend/public/src/lib/courseApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import React from "react"
import moment from "moment"
import { isNil } from "ramda"

import { notNil, parseDateString, formatPrettyDateTimeAmPmTz } from "./util"
import {
notNil,
parseDateString,
formatPrettyDateTimeAmPmTz,
emptyOrNil
} from "./util"

import { NODETYPE_OPERATOR, NODETYPE_COURSE, NODEOPER_ALL } from "../constants"

Expand Down Expand Up @@ -210,6 +215,13 @@ export const learnerProgramIsCompleted = (learnerRecord: LearnerRecord) => {

return requirementsDone && electivesDone
}
export const isRunArchived = (run: CourseRunDetail) => {
return run
? moment().isAfter(run.end_date) &&
(moment().isBefore(run.enrollment_end) ||
emptyOrNil(run.enrollment_end))
: false
}

export const getFirstRelevantRun = (
course: CourseDetail,
Expand Down

0 comments on commit 9f94faf

Please sign in to comment.