-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route different content types to correct edit pages (#2169)
* Reroute content * Reverting changes to Root.tsx and urls.py * Revert change to ResourceLinkMarkdownSyntax * Update rerouting * Undo changes to App.tsx * Making routing work * Adding URL test * Adding test for GenericContentReroutePage
- Loading branch information
Showing
6 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { makeWebsiteDetail } from "../util/factories/websites" | ||
import { useWebsiteContent } from "../hooks/websites" | ||
import { IntegrationTestHelper } from "../testing_utils" | ||
import GenericContentReroutePage from "./GenericContentReroutePage" | ||
import { waitFor } from "@testing-library/react" | ||
import React from "react" | ||
|
||
jest.mock("../hooks/websites") | ||
|
||
describe("GenericContentReroutePage", () => { | ||
const mockWebsite = makeWebsiteDetail({ | ||
name: "test-site", | ||
uuid: "website-uuid", | ||
title: "Test Site", | ||
}) | ||
|
||
const helper = new IntegrationTestHelper() | ||
helper.mockGetWebsiteDetail(mockWebsite) | ||
|
||
const testCases = [ | ||
{ | ||
type: "page", | ||
expectedPath: "/sites/test-site/type/page/edit/test-uuid/", | ||
}, | ||
{ | ||
type: "video_gallery", | ||
expectedPath: "/sites/test-site/type/video_gallery/edit/test-uuid/", | ||
}, | ||
{ | ||
type: "external_resource", | ||
expectedPath: "/sites/test-site/type/external_resource/edit/test-uuid/", | ||
}, | ||
] | ||
|
||
testCases.forEach(({ type, expectedPath }) => { | ||
it(`reroutes to the correct page based on content type: ${type}`, async () => { | ||
const mockResource = { | ||
type, | ||
text_id: "test-uuid", | ||
} | ||
|
||
;(useWebsiteContent as jest.Mock).mockReturnValue([mockResource]) | ||
|
||
const [_, { history }] = helper.renderWithWebsite( | ||
<GenericContentReroutePage />, | ||
mockWebsite, | ||
) | ||
|
||
await waitFor(() => { | ||
expect(history.location.pathname).toBe(expectedPath) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useParams, useHistory } from "react-router" | ||
import { useWebsiteContent } from "../hooks/websites" | ||
import { useEffect } from "react" | ||
import { siteContentDetailUrl } from "../lib/urls" | ||
import { useWebsite } from "../context/Website" | ||
/** | ||
* A page to be served at /content/:uuid that fetches the resource and reroutes | ||
* the user to the appropriate page, i.e., | ||
* /type/pages/:uuid | ||
* /type/resources/:uuid | ||
* /type/video-galleries/:uuid | ||
* etc. | ||
**/ | ||
const GenericContentReroutePage = () => { | ||
const { uuid } = useParams<{ uuid: string }>() | ||
const history = useHistory() | ||
const website = useWebsite() | ||
const [resource] = useWebsiteContent(uuid) | ||
useEffect(() => { | ||
if (!resource?.type) return | ||
history.replace({ | ||
pathname: siteContentDetailUrl.param({ | ||
contentType: resource.type, | ||
name: website.name, | ||
uuid: resource.text_id, | ||
}).pathname, | ||
}) | ||
}, [uuid, history, resource?.type, resource?.text_id, website.name]) | ||
|
||
return null | ||
} | ||
|
||
export default GenericContentReroutePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters