-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/preview html #209
Fix/preview html #209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,18 +167,15 @@ export default class CodeExample extends React.Component { | |
} | ||
|
||
render() { | ||
const { children, codeJSXOptions, codeTypes, theme, ...other } = this.props; | ||
const { children, codeJSXOptions, codeTypes, ...other } = this.props; | ||
|
||
let codeToShow; | ||
switch (this.state.codePreviewType) { | ||
case 'html': | ||
codeToShow = pretty( | ||
typeof children === 'string' | ||
? unescape(children) | ||
: renderToStaticMarkup({ | ||
...children, | ||
props: { ...children.props, theme }, | ||
}), | ||
: renderToStaticMarkup(children), | ||
{ | ||
ocd: true, | ||
} | ||
|
@@ -214,6 +211,7 @@ export default class CodeExample extends React.Component { | |
<Code | ||
inline={false} | ||
ref={this.codeBlockRef} | ||
data-testid={this.state.codePreviewType} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
language={ | ||
this.state.codePreviewType === 'html' | ||
? 'markup' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
|
||
import Preview from '.'; | ||
|
||
|
@@ -8,4 +8,19 @@ describe('rendering', () => { | |
const { getByText } = render(<Preview>Preview</Preview>); | ||
expect(getByText('Preview')).toBeInTheDocument(); | ||
}); | ||
|
||
it('HTML preview renders more than 1 child', () => { | ||
const { getByText, getByTestId } = render( | ||
<Preview> | ||
<p>Paragraph 1</p> | ||
<p>Paragraph 2</p> | ||
</Preview> | ||
); | ||
|
||
fireEvent.click(getByText('SHOW CODE')); | ||
|
||
fireEvent.click(getByText('HTML')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ak by si chcel specificky testovat, ci funguje zobrazenie HTML, testoval by som taketo nieco:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vid koment vyssie. ja testujem, ci mi nespadne html code example ked su tam 2 childs, preto sa aj test vola |
||
|
||
expect(getByTestId('html')).toBeInTheDocument(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ked mam test, ktory checkuje ze ci sa zrenderuje viac ako 1 child, tak by som pocital kolko sa ich zrenderovalo. Napr aj tak, ze si das test-id do renderu tu.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no lenze toto nebude fungovat kedze ten vystup je nieco taketo: <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>svg</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>icon icon--heart<span class="token punctuation">"</span></span> <span class="token attr-name">role</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>presentation<span class="token punctuation">"</span></span> <span class="token attr-name">aria-hidden</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No ale to data-testid tam niekde bude. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha rozumiem, zrejme nebude. Stale vies selectovat cez text content cize vies hladat napr. |
||
}); | ||
}); |
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.
Vyborny priestor na vyskusanie optional chaining :)
props.className?.replace(/language-/, '')
by malo spravit job.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.
pushol som do spravnej branche #210