-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC-783 Add hideClipboard functionality (#1355)
* chore : add hideClipboard functionality * Optimised images with calibre/image-actions * chore : fix ci/cd * chore : remove unsued variables in test case * chore:fix review comments * Optimised images with calibre/image-actions * chore: remove white space --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
786a755
commit d5fbb22
Showing
15 changed files
with
45,053 additions
and
33,558 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const React = require("react"); | ||
const gatsby = jest.requireActual("gatsby"); | ||
|
||
module.exports = { | ||
...gatsby, | ||
graphql: jest.fn(), | ||
Link: jest.fn().mockImplementation( | ||
// these props are invalid for an `a` tag | ||
({ | ||
activeClassName, | ||
activeStyle, | ||
getProps, | ||
innerRef, | ||
partiallyActive, | ||
ref, | ||
replace, | ||
to, | ||
...rest | ||
}) => | ||
React.createElement("a", { | ||
...rest, | ||
href: to, | ||
}) | ||
), | ||
Slice: jest.fn().mockImplementation(({ alias, ...rest }) => | ||
React.createElement("div", { | ||
...rest, | ||
"data-test-slice-alias": alias, | ||
}) | ||
), | ||
useStaticQuery: jest.fn(), | ||
}; |
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,39 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import Pre from "../src/shared/mdx/components/Pre"; | ||
import Clipboard from "clipboard"; | ||
|
||
jest.mock("clipboard"); | ||
|
||
const TextComponent = (props) => { | ||
return <div>{props.text}</div>; | ||
}; | ||
|
||
describe("Displays the correct title", () => { | ||
afterEach(() => { | ||
Clipboard.mockRestore(); | ||
}); | ||
|
||
it("renders the component with default props", () => { | ||
const { getByText, getByRole } = render( | ||
<Pre> | ||
<TextComponent text={"Testing code"}></TextComponent> | ||
</Pre> | ||
); | ||
|
||
expect(getByText("Testing code")).toBeInTheDocument(); | ||
|
||
expect(getByRole("button", { name: /copy/i })).toBeInTheDocument(); | ||
expect(Clipboard).toBeCalled(); | ||
}); | ||
|
||
it("does not render the copy button when hideClipboard prop is true", () => { | ||
const { queryByRole } = render( | ||
<Pre> | ||
<TextComponent text={"Sample code"} hideClipboard={true}></TextComponent> | ||
</Pre> | ||
); | ||
expect(queryByRole("button", { name: /copy/i })).toBeNull(); | ||
expect(Clipboard).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
const babelOptions = { | ||
presets: ["babel-preset-gatsby"], | ||
}; | ||
|
||
module.exports = require("babel-jest").default.createTransformer(babelOptions); |
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,20 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.jsx?$": `<rootDir>/jest-preprocess.js`, | ||
}, | ||
moduleNameMapper: { | ||
".+\\.(css|styl|less|sass|scss)$": `identity-obj-proxy`, | ||
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`, | ||
}, | ||
testPathIgnorePatterns: [`node_modules`, `\\.cache`, `<rootDir>.*/public`], | ||
transformIgnorePatterns: [`node_modules/(?!(gatsby|gatsby-script|gatsby-link)/)`], | ||
globals: { | ||
__PATH_PREFIX__: ``, | ||
}, | ||
testEnvironmentOptions: { | ||
url: `http://localhost`, | ||
}, | ||
setupFiles: [`<rootDir>/loadershim.js`], | ||
testEnvironment: `jsdom`, | ||
setupFilesAfterEnv: ["<rootDir>/setup-test-env.js"], | ||
}; |
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,3 @@ | ||
global.___loader = { | ||
enqueue: jest.fn(), | ||
}; |
Oops, something went wrong.