Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav committed Aug 7, 2024
1 parent 26525dd commit 27aa86b
Showing 1 changed file with 77 additions and 37 deletions.
114 changes: 77 additions & 37 deletions frontend/public/src/components/CourseProductDetailEnroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ describe("CourseProductDetailEnrollShallowRender", () => {
await enrollBtn.prop("onClick")()

const modal = inner.find(".upgrade-enrollment-modal")
const selectorControl = modal.find(".date-selector-button-bar").at(0)
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()

assert.equal(inner.find("input[type='hidden']").at(0).prop("value"), courseRun.products[0].id)


const flexiblePricingLink = modal.find(".financial-assistance-link").at(0)
if (flexPriceApproved) {
Expand Down Expand Up @@ -456,10 +467,16 @@ describe("CourseProductDetailEnrollShallowRender", () => {
enrollBtn.prop("onClick")()

const modal = inner.find(".upgrade-enrollment-modal")
const upgradeForm = modal.find("form").at(0)
assert.isTrue(upgradeForm.exists())
const selectorControl = modal.find(".date-selector-button-bar").at(0)
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()

assert.equal(upgradeForm.find("input[type='hidden']").prop("value"), "1")
assert.equal(inner.find("input[type='hidden']").at(0).prop("value"), "1")

assert.equal(inner.find("#certificate-price-info").at(0).text(), "$9.00")
})
Expand Down Expand Up @@ -494,10 +511,16 @@ describe("CourseProductDetailEnrollShallowRender", () => {
await enrollBtn.prop("onClick")()

const modal = inner.find(".upgrade-enrollment-modal")
const upgradeForm = modal.find("form").at(0)
assert.isTrue(upgradeForm.exists())
const selectorControl = modal.find(".date-selector-button-bar").at(0)
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()

assert.equal(upgradeForm.find("input[type='hidden']").prop("value"), "1")
assert.equal(inner.find("input[type='hidden']").at(0).prop("value"), "1")

assert.equal(
inner.find("#certificate-price-info").at(0).text().at(1),
Expand Down Expand Up @@ -539,12 +562,33 @@ describe("CourseProductDetailEnrollShallowRender", () => {
const upgradeForm = modal.find("form").at(0)
assert.isTrue(upgradeForm.exists())

assert.equal(upgradeForm.find("input[type='hidden']").prop("value"), "1")

const selectorControl = modal.find(".date-selector-button-bar").at(0)
assert.isTrue(selectorControl.exists())
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(
upgradeForm.find("button.btn-upgrade").at(0).prop("disabled")
)
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()
assert.isFalse(getDisabledProp(inner, "button.enroll-now-free"))
assert.isFalse(getDisabledProp(inner, "button.btn-upgrade"))
assert.equal(inner.find("input[type='hidden']").at(0).prop("value"), "1")
assert.equal(
inner.find("#certificate-price-info").at(0).text().at(1),
"9"
)

// check if default selected it resets back
modal
.find("select.form-control")
.simulate("change", { target: { value: "default" } })
inner.update()
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
assert.isTrue(getDisabledProp(inner, "button.btn-upgrade"))
})
})

Expand Down Expand Up @@ -604,10 +648,10 @@ describe("CourseProductDetailEnrollShallowRender", () => {
await enrollBtn.prop("onClick")()
})
;[
["does not show", "one", false],
["shows", "multiple", true]
].forEach(([showsQualifier, runsQualifier, multiples]) => {
it(`${showsQualifier} the course run selector for a course with ${runsQualifier} active run${
["one", false],
["multiple", true]
].forEach(([runsQualifier, multiples]) => {
it(`shows the course run selector for a course with ${runsQualifier} active run${
multiples ? "s" : ""
} and enables enroll buttons on selection`, async () => {
const courseRuns = [courseRun]
Expand All @@ -632,35 +676,31 @@ describe("CourseProductDetailEnrollShallowRender", () => {
assert.isTrue(upgradeForm.exists())

const selectorControl = modal.find(".date-selector-button-bar").at(0)
assert.isTrue(selectorControl.exists())
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(
upgradeForm.find("button.btn-upgrade").at(0).prop("disabled")
)
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()
assert.isFalse(getDisabledProp(inner, "button.enroll-now-free"))
assert.isFalse(getDisabledProp(inner, "button.btn-upgrade"))
// check if default selected it resets back
modal
.find("select.form-control")
.simulate("change", { target: { value: "default" } })
inner.update()
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
assert.isTrue(getDisabledProp(inner, "button.btn-upgrade"))

if (multiples) {
assert.isTrue(selectorControl.exists())
const selectorControlItems = selectorControl.find("option")
assert.isTrue(selectorControlItems.length === 3)
assert.isTrue(selectorControlItems.at(0).text() === "Please Select")
assert.isTrue(
upgradeForm.find("button.btn-upgrade").at(0).prop("disabled")
)
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
modal
.find("select.form-control")
.simulate("change", { target: { value: courseRun["id"] } })
inner.update()
assert.isFalse(getDisabledProp(inner, "button.enroll-now-free"))
assert.isFalse(getDisabledProp(inner, "button.btn-upgrade"))
// check if default selected it resets back
modal
.find("select.form-control")
.simulate("change", { target: { value: "default" } })
inner.update()
assert.isTrue(getDisabledProp(inner, "button.enroll-now-free"))
assert.isTrue(getDisabledProp(inner, "button.btn-upgrade"))
} else {
assert.isFalse(selectorControl.exists())
assert.isFalse(getDisabledProp(inner, "button.enroll-now-free"))
assert.isFalse(
upgradeForm.find("button.btn-upgrade").at(0).prop("disabled")
)
assert.isTrue(selectorControlItems.length === 2)
}
})
})
Expand Down

0 comments on commit 27aa86b

Please sign in to comment.