-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add versioning logic to partials DOC-1198
- Loading branch information
Showing
11 changed files
with
177 additions
and
22 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
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
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,16 @@ | ||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; | ||
import { Config } from "@docusaurus/types"; | ||
|
||
export default function GetVersions(): string[] { | ||
const { siteConfig } = useDocusaurusContext(); | ||
const cfg = siteConfig as Config; | ||
if (cfg.presets != undefined) { | ||
// Linting is disabled for next line, as there is no type for docs config. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument | ||
const versions = cfg.presets[0][1]["docs"]["versions"] as object; | ||
const versionNames: string[] = Object.keys(versions); | ||
return versionNames; | ||
} | ||
// if no presets, then default to "current" | ||
return ["current"]; | ||
} |
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,10 @@ | ||
import { useActivePluginAndVersion } from "@docusaurus/plugin-content-docs/client"; | ||
|
||
export default function GetVersion(): string { | ||
const activePlugin = useActivePluginAndVersion(); | ||
if (activePlugin != undefined && activePlugin.activeVersion != undefined) { | ||
return activePlugin.activeVersion.name; | ||
} | ||
|
||
return ""; | ||
} |
47 changes: 47 additions & 0 deletions
47
src/components/PartialsComponent/PartialsComponent-Versioned.test.tsx
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,47 @@ | ||
import React, { FunctionComponent } from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
let category = "testCat1"; | ||
let name = "nameCat1"; | ||
let propValue = "testValue1"; | ||
|
||
const Partial: React.FunctionComponent<{}> = ({}) => ( | ||
<div> | ||
<p>{category}</p> | ||
<p>{name}</p> | ||
<p>{propValue}</p> | ||
</div> | ||
); | ||
|
||
jest.mock("./PartialsImporter", () => { | ||
return jest.fn(() => { | ||
const allPartials: PartialsMap = {}; | ||
const mapKey = "version-4.3.x".concat("#").concat(category).concat("#").concat(name); | ||
allPartials[mapKey] = Partial as FunctionComponent; | ||
return allPartials; | ||
}); | ||
}); | ||
|
||
jest.mock("./GetVersion", () => { | ||
return jest.fn(() => { | ||
return "4.3.x"; | ||
}); | ||
}); | ||
|
||
import PartialsComponent from "./PartialsComponent"; | ||
import { PartialsMap } from "./PartialsImporter"; | ||
|
||
describe("Partials Component", () => { | ||
it("partial exists", () => { | ||
render(<PartialsComponent category={category} name={name} propTest={propValue} />); | ||
expect(screen.getByText(category)).toBeInTheDocument(); | ||
expect(screen.getByText(name)).toBeInTheDocument(); | ||
expect(screen.getByText(propValue)).toBeInTheDocument(); | ||
}); | ||
|
||
it("partial does not exist", () => { | ||
expect(() => render(<PartialsComponent category="unknownCat" name="unknownName" propTest={propValue} />)).toThrow( | ||
"No partial found for name unknownName in category unknownCat for version 4.3.x." | ||
); | ||
}); | ||
}); |
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