Skip to content

Commit

Permalink
Showing Course rather than Courses (or program/s) when there is only …
Browse files Browse the repository at this point in the history
…1 to display (#2139)

* test update

* add comment description
  • Loading branch information
JenniWhitman authored Mar 27, 2024
1 parent a570ff9 commit ef7a1a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
28 changes: 20 additions & 8 deletions frontend/public/src/containers/pages/CatalogPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,25 @@ export class CatalogPage extends React.Component<Props> {
} else return 0
}

/**
* Returns the html for the catalog count based on the selected tab, either Courses or Programs.
* This return is singular or plural based on the count.
* @returns {Element}
*/
renderCatalogCount() {
const count =
this.state.tabSelected === PROGRAMS_TAB
? this.renderNumberOfCatalogPrograms()
: this.renderNumberOfCatalogCourses()
const tab = this.state.tabSelected
return (
<h2 className="catalog-count">
{/* Hidden on small screens. */}
{count} {count > 1 ? tab : tab.slice(0, -1)}
</h2>
)
}

/**
* Renders a single course catalog card.
* @param {CourseDetailWithRuns} course The course instance used to populate the card.
Expand Down Expand Up @@ -793,14 +812,7 @@ export class CatalogPage extends React.Component<Props> {
timeout={300}
classNames="count"
>
<h2>
{/* Hidden on small screens. */}
{/* Could add logic to display only "course" if only 1 course is showing. */}
{this.state.tabSelected === PROGRAMS_TAB
? this.renderNumberOfCatalogPrograms()
: this.renderNumberOfCatalogCourses()}{" "}
{this.state.tabSelected}
</h2>
{this.renderCatalogCount()}
</CSSTransition>
</TransitionGroup>
</div>
Expand Down
32 changes: 32 additions & 0 deletions frontend/public/src/containers/pages/CatalogPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,36 @@ describe("CatalogPage", function() {
JSON.stringify([displayedProgram, newProgram])
)
})

it("renderCatalogCount is plural for more than one course", async () => {
const { inner } = await renderPage()
inner.setState({ tabSelected: "courses" })
inner.setState({ selectedDepartment: "All Departments" })
inner.setState({ allCoursesCount: 2 })
expect(inner.find("h2.catalog-count").text()).equals("2 courses")
})

it("renderCatalogCount is plural for more than one program", async () => {
const { inner } = await renderPage()
inner.setState({ tabSelected: "programs" })
inner.setState({ selectedDepartment: "All Departments" })
inner.setState({ allProgramsCount: 2 })
expect(inner.find("h2.catalog-count").text()).equals("2 programs")
})

it("renderCatalogCount is singular for one course", async () => {
const { inner } = await renderPage()
inner.setState({ tabSelected: "courses" })
inner.setState({ selectedDepartment: "All Departments" })
inner.setState({ allCoursesCount: 1 })
expect(inner.find("h2.catalog-count").text()).equals("1 course")
})

it("renderCatalogCount is singular for one program", async () => {
const { inner } = await renderPage()
inner.setState({ tabSelected: "programs" })
inner.setState({ selectedDepartment: "All Departments" })
inner.setState({ allProgramsCount: 1 })
expect(inner.find("h2.catalog-count").text()).equals("1 program")
})
})

0 comments on commit ef7a1a1

Please sign in to comment.