Skip to content
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

Merged
merged 4 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/styleguide/src/components/MDX/MDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const MDXComponents = {
a: props => <Link {...props} />,
inlineCode: props => <Code {...props} />,
code: props => (
<CodeBlock language={props.className.replace(/language-/, '')} {...props} />
<CodeBlock
language={props.className && props.className.replace(/language-/, '')}

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.

Copy link
Author

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

{...props}
/>
),
};

Expand Down
8 changes: 3 additions & 5 deletions packages/styleguide/src/components/Preview/CodeExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -214,6 +211,7 @@ export default class CodeExample extends React.Component {
<Code
inline={false}
ref={this.codeBlockRef}
data-testid={this.state.codePreviewType}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-testid= sa ti naozaj zobrazi aj v produkcii, co nie je bohvieco. Napisem nizsie, ako z toho idealne vykluckovat.

language={
this.state.codePreviewType === 'html'
? 'markup'
Expand Down
17 changes: 16 additions & 1 deletion packages/styleguide/src/components/Preview/Preview.test.js
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 '.';

Expand All @@ -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'));

Choose a reason for hiding this comment

The 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:

const Paragraph  = () => <p data-testid="paragraph">Paragraph</p>
<Preview>
  <Paragraph />
</Preview>

Copy link
Author

Choose a reason for hiding this comment

The 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 HTML preview renders more than 1 child


expect(getByTestId('html')).toBeInTheDocument();

Choose a reason for hiding this comment

The 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.

<Preview>
  <p data-testid="p1">Paragraph 1</p>
  <p data-testid="p1">Paragraph 2</p>
</Preview>

Copy link
Author

Choose a reason for hiding this comment

The 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">&lt;</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">&gt;</span></span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ale to data-testid tam niekde bude.

Choose a reason for hiding this comment

The 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. Paragraph 1 a Paragraph 2

});
});