import { h } from 'preact'; import { render } from '@testing-library/preact'; import { axe } from 'jest-axe'; import '@testing-library/jest-dom'; 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('
component', () => { it('should have no a11y violations for a standard article', async () => { const { container } = render(
, ); const results = await axe(container); expect(results).toHaveNoViolations(); }); it('should have no a11y violations for a featured article', async () => { const { container } = render(
, ); const results = await axe(container); expect(results).toHaveNoViolations(); }); it('should render a standard article', () => { const { container, queryByAltText } = render(
, ); expect(container.firstChild).not.toHaveClass('crayons-story--featured', { exact: false, }); expect(queryByAltText('Emil99 profile')).toBeDefined(); }); it('should render a featured article', () => { const { container, queryByAltText } = render(
, ); expect(container.firstChild).toHaveClass('crayons-story--featured', { exact: false, }); expect(queryByAltText('Emil99 profile')).toBeDefined(); }); it('should render a rich feed', () => { const tree = render(
, ); expect(tree).toMatchSnapshot(); }); it('should render a featured article for an organization', () => { const { container, queryByAltText } = render(
, ); expect(container.firstChild).toHaveClass('crayons-story--featured', { exact: false, }); expect(queryByAltText('Web info-mediaries logo')).toBeDefined(); expect(queryByAltText('Emil99 profile')).toBeDefined(); }); it('should render a featured article for a video post', () => { const { queryByTitle } = render(
, ); expect(queryByTitle(/video duration/i)).toBeDefined(); }); it('should render with an organization', () => { const { queryByAltText } = render(
, ); expect(queryByAltText('Web info-mediaries logo')).toBeDefined(); expect(queryByAltText('Emil99 profile')).toBeDefined(); }); it('should render with a flare tag', () => { const { queryByText } = render(
, ); expect(queryByText('#javascript', { selector: 'span' })).toBeDefined(); }); it('should render with a snippet result', () => { const { queryByText } = render(
, ); expect( queryByText( '…copying Rest withdrawal Handcrafted multi-state Pre-emptive e-markets feed...overriding RSS Fantastic Plastic Gloves invoice productize systemic Monaco…', ), ).toBeDefined(); }); it('should render with reactions', () => { const { getByTitle } = render(
, ); const reactions = getByTitle('Number of reactions'); expect(reactions.textContent).toEqual('232 reactions'); }); it('should render with comments', () => { const { getByTitle } = render(
, ); const comments = getByTitle('Number of comments'); expect(comments.textContent).toEqual('213 comments'); }); it('should render with an add comment button when there are no comments', () => { const { queryByTestId } = render(
, ); expect(queryByTestId('add-a-comment')).toBeDefined(); }); it('should render as saved on reading list', () => { const { queryByText } = render(
, ); expect(queryByText('Saved', { selector: 'button' })).toBeDefined(); }); it('should render as not saved on reading list', () => { const { queryByText } = render(
, ); expect(queryByText('Save', { selector: 'button' })).toBeDefined(); }); it('should render a video article', () => { const { queryByTitle } = render(
, ); expect(queryByTitle(/video duration/i)).toBeDefined(); }); it('should render a podcast article', () => { const { queryByAltText, queryByText } = render(
, ); expect(queryByAltText('Rubber local')).toBeDefined(); expect(queryByText('podcast', { selector: 'span' })).toBeDefined(); }); it('should render a podcast episode', () => { const { queryByText } = render(
, ); expect(queryByText('podcast', { selector: 'span' })).toBeDefined(); }); it('should render a user article', () => { const { queryByText } = render(
); expect(queryByText('person', { selector: 'span' })).toBeDefined(); }); });