docbrown/app/javascript/articles/__tests__/Article.test.jsx
2020-05-13 11:02:56 -04:00

177 lines
4.2 KiB
JavaScript

import { h } from 'preact';
import render from 'preact-render-to-json';
import { Article } from '..';
import {
article,
articleWithOrganization,
articleWithSnippetResult,
articleWithReactions,
videoArticle,
articleWithComments,
podcastArticle,
podcastEpisodeArticle,
userArticle,
assetPath,
} from './utilities/articleUtilities';
import '../../../assets/javascripts/lib/xss';
import '../../../assets/javascripts/utilities/timeAgo';
const commonProps = {
reactionsIcon: assetPath('reactions-stack.png'),
commentsIcon: assetPath('comments-bubble.png'),
videoIcon: assetPath('video-camera.svg'),
};
describe('<Article /> component', () => {
it('should render a standard article', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={article}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render a featured article', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
isFeatured
article={article}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render a featured article for an organization', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
isFeatured
article={articleWithOrganization}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render a featured article for a video post', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
isFeatured
article={videoArticle}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render with an organization', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={articleWithOrganization}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render with a flare tag', () => {
const tree = render(
<Article {...commonProps} isBookmarked={false} article={article} />,
);
expect(tree).toMatchSnapshot();
});
it('should render with a snippet result', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={articleWithSnippetResult}
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render with reactions', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={articleWithReactions}
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render with comments', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={articleWithComments}
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render as saved on reading list', () => {
const tree = render(
<Article {...commonProps} isBookmarked article={articleWithComments} />,
);
expect(tree).toMatchSnapshot();
});
it('should render a video article', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={videoArticle}
currentTag="javascript"
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render a video article with a flare tag', () => {
const tree = render(
<Article {...commonProps} isBookmarked={false} article={videoArticle} />,
);
expect(tree).toMatchSnapshot();
});
it('should render a podcast article', () => {
const tree = render(
<Article
{...commonProps}
isBookmarked={false}
article={podcastArticle}
/>,
);
expect(tree).toMatchSnapshot();
});
it('should render a podcast episode', () => {
const tree = render(
<Article isBookmarked={false} article={podcastEpisodeArticle} />,
);
expect(tree).toMatchSnapshot();
});
it('should render a user article', () => {
const tree = render(<Article article={userArticle} />);
expect(tree).toMatchSnapshot();
});
});