Skip to content

Conversation

@ChristopherChudzicki
Copy link
Contributor

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5414

Description (What does it do?)

This fixes our Jest tests for NextJS branch and re-enables them on CI

How can this be tested?

  1. Run the app locally with docker compose up or yarn watch. It should look good.
  2. Tests should pass.

)
return (
totalSubtopics > 0 && (
<SubTopicsContainer>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subtopic work Carey added in #1511 seems to have been accidentally removed in #1525. (But not the test, thankfully!). This adds it back.

Comment on lines -15 to -17
await waitFor(() => {
expect(document.title).toBe("About Us | MIT Learn")
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this and some other metadata tests since the metadata is now handled by NextJS.

It probably is worth having metadata tests, but they should be added in https://github.com/mitodl/hq/issues/5410

import NotFoundPage from "./NotFoundPage"

test("The NotFoundPage loads with meta", async () => {
test.skip("The NotFoundPage loads with meta", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only test to which I added a skip, since it will be changed anyway in [ISSUE TO BE CREATED]

params: Record<string, string | number>,
): string => {
return template.replace(/:(\w+)/g, (_, key) => {
return template.replace(/\[(\w+)\]/g, (_, key) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking params as with [...] is much more convenient for use with next-router-mock... see https://github.com/mitodl/mit-open/pull/1560/files#diff-22d69d0f979fef7f8d9d0b0cd55dd7a00c6c3f4302ac7d542f79220acee4f905R18


export const LEARNINGPATH_LISTING = "/learningpaths/"
export const LEARNINGPATH_VIEW = "/learningpaths/:id"
export const LEARNINGPATH_LISTING = "/learningpaths"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NextJS by default canonicalizes removes trailing / from paths.

If we prefer to keep them, we can configure that with next.config.js (which affects the behavior of NextJS server and of the Link component). But it's slightly annoying since the jest tests aren't aware of next.config.js.


const { usePathname, useSearchParams } = nextNavigationMocks

describe("Mock Navigation", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for sanity as I debugged an issue with the mock navigation stuff.

@ChristopherChudzicki ChristopherChudzicki marked this pull request as ready for review September 13, 2024 22:36
@gumaerc gumaerc self-assigned this Sep 16, 2024
Copy link
Contributor

@gumaerc gumaerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Looks good, just one small nitpick:

@@ -1,16 +1,18 @@
import { renderTestApp, waitFor } from "../../test-utils"
import React from "react"
import { renderWithProviders, waitFor } from "../../../../test-utils"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a nitpick, but can't this just be @/test-utils instead of the relative path?

@ChristopherChudzicki ChristopherChudzicki merged commit 436b9cb into nextjs Sep 16, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 18, 2024
jonkafton pushed a commit that referenced this pull request Sep 23, 2024
jonkafton pushed a commit that referenced this pull request Sep 23, 2024
jonkafton pushed a commit that referenced this pull request Sep 24, 2024
@odlbot odlbot mentioned this pull request Oct 22, 2024
74 tasks
@rhysyngsun rhysyngsun deleted the cc/nextjs-remaining-tests branch February 7, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants