-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1114 from tomrule007/bugfix/codepen-mdx-errors
Bugfix/codepen mdx errors
- Loading branch information
Showing
5 changed files
with
130 additions
and
122 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,63 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
import CodePen from './CodePen' | ||
describe('CodePen component', () => { | ||
test('should render a single iframe element', () => { | ||
const { container } = render( | ||
<CodePen id="SOME_TEST" height="500" defaultTab="js" showResult={true} /> | ||
) | ||
expect(container.children.length).toBe(1) | ||
expect(container.children[0].tagName).toBe('IFRAME') | ||
}) | ||
|
||
test('should render correct src value containing prop values', () => { | ||
const { container } = render( | ||
<CodePen | ||
id="SOME_TEST" | ||
height="1000" | ||
defaultTab="html" | ||
showResult={false} | ||
theme="dark" | ||
/> | ||
) | ||
expect(container.children[0]).toHaveAttribute( | ||
'src', | ||
'https://codepen.io/c0d3codepen/embed/SOME_TEST?theme-id=dark&default-tab=html' | ||
) | ||
}) | ||
|
||
test("should render default height and style of 300 and {width: '100%'}", () => { | ||
const { container } = render(<CodePen id="SOME_TEST" defaultTab="html" />) | ||
const iframe = container.children[0] | ||
expect(iframe).toHaveAttribute('style', 'width: 100%;') | ||
expect(iframe).toHaveAttribute('height', '300') | ||
}) | ||
|
||
test('should render light theme and result tab only by default', () => { | ||
const { container } = render(<CodePen id="SOME_TEST" />) | ||
expect(container.children[0]).toHaveAttribute( | ||
'src', | ||
'https://codepen.io/c0d3codepen/embed/SOME_TEST?theme-id=light&default-tab=result' | ||
) | ||
}) | ||
|
||
test('should render selected tab, "html", and include result tab by default', () => { | ||
const { container } = render(<CodePen id="SOME_TEST" defaultTab="html" />) | ||
expect(container.children[0]).toHaveAttribute( | ||
'src', | ||
'https://codepen.io/c0d3codepen/embed/SOME_TEST?theme-id=light&default-tab=html%2Cresult' | ||
) | ||
}) | ||
test('should match screenshot', () => { | ||
const { container } = render( | ||
<CodePen | ||
id="SOME_OTHER_TEST" | ||
height={3001} | ||
style={{ maxWidth: '700px' }} | ||
defaultTab="css" | ||
/> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
}) |
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,43 @@ | ||
import React from 'react' | ||
import CSS from 'csstype' | ||
|
||
type Props = { | ||
id: string | ||
style?: CSS.Properties | ||
height?: number | ||
defaultTab?: 'js' | 'css' | 'html' | 'result' | ||
showResult?: boolean | ||
theme?: 'light' | 'dark' | ||
} | ||
|
||
const CodePen: React.FC<Props> = ({ | ||
id, | ||
height = 300, | ||
style = { width: '100%' }, | ||
defaultTab = 'result', | ||
showResult = true, | ||
theme = 'light' | ||
}) => { | ||
// User can select one of 3 tabs for left hand side: js / css / html | ||
// or pick 'result' to display full width result. selecting 'result' will | ||
// override 'showResults = false' as you must display some tab. | ||
// showResults true will display results on right hand side. | ||
const tabString = | ||
defaultTab === 'result' | ||
? 'result' | ||
: `${defaultTab}${showResult ? '%2Cresult' : ''}` // %2C is URL encoded comma character | ||
|
||
return ( | ||
<iframe | ||
height={height} | ||
style={style} | ||
scrolling="no" | ||
src={`https://codepen.io/c0d3codepen/embed/${id}?theme-id=${theme}&default-tab=${tabString}`} | ||
frameBorder="no" | ||
loading="lazy" | ||
allowFullScreen={true} | ||
/> | ||
) | ||
} | ||
|
||
export default CodePen |
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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CodePen component should match screenshot 1`] = ` | ||
<div> | ||
<iframe | ||
allowfullscreen="" | ||
frameborder="no" | ||
height="3001" | ||
loading="lazy" | ||
scrolling="no" | ||
src="https://codepen.io/c0d3codepen/embed/SOME_OTHER_TEST?theme-id=light&default-tab=css%2Cresult" | ||
style="max-width: 700px;" | ||
/> | ||
</div> | ||
`; |
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
8e0c173
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: