-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(MetaBlock): test for MetaBlock added
- Loading branch information
Showing
9 changed files
with
162 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import {PADDING_SIZES} from '../../../../test-utils/constants'; | ||
import {testPaddingBottom, testPaddingTop} from '../../../../test-utils/shared/common'; | ||
import {MetaProps} from '../../../models/blocks'; | ||
import {PaddingSize} from '../../../models/paddings'; | ||
import {getQaAttributes} from '../../../utils/common'; | ||
import {Meta} from '../Meta'; | ||
import {LikesRoutineType, PostPageContext} from '../../../contexts/PostPageContext'; | ||
import post from '../../../../.mocks/post.json'; | ||
import {PostData} from '../../../models/common'; | ||
import {LocaleContext} from '../../../contexts/LocaleContext'; | ||
import {Lang} from '../../../models/locale'; | ||
import {format} from '../../../utils/date'; | ||
import {Keyset, i18} from '../../../i18n'; | ||
|
||
const locale = { | ||
code: 'en-En', | ||
lang: Lang.En, | ||
langName: 'English', | ||
pathPrefix: 'en', | ||
}; | ||
|
||
const metaProps = { | ||
locale: 'en', | ||
qa: 'meta-block', | ||
}; | ||
|
||
const qaAttributes = getQaAttributes(metaProps.qa, 'post-info'); | ||
const likes: LikesRoutineType = { | ||
handleUserLike: jest.fn(), | ||
likesCount: 1, | ||
hasUserLike: true, | ||
}; | ||
|
||
const RenderComponent = (props: MetaProps) => { | ||
return ( | ||
<LocaleContext.Provider value={{locale}}> | ||
<PostPageContext.Provider | ||
value={{post: post as unknown as PostData, suggestedPosts: [] as PostData[], likes}} | ||
> | ||
<Meta {...props} /> | ||
</PostPageContext.Provider> | ||
</LocaleContext.Provider> | ||
); | ||
}; | ||
|
||
describe('Meta', () => { | ||
test('render meta by default', async () => { | ||
render(<RenderComponent {...metaProps} />); | ||
const meta = screen.getByText(post.title); | ||
expect(meta).toHaveClass('yfm_blog_breadcrumbs'); | ||
}); | ||
|
||
test('render with breadcrumbs', async () => { | ||
render(<RenderComponent {...metaProps} />); | ||
const blogBreadcrumb = screen.getByText('Blog'); | ||
const tagBreadcrumb = screen.getByText('Slug'); | ||
const titleBreadcrumb = screen.getByText(post.title); | ||
|
||
expect(blogBreadcrumb).toHaveClass('pc-header-breadcrumbs__text'); | ||
expect(tagBreadcrumb).toHaveClass('pc-header-breadcrumbs__text'); | ||
expect(titleBreadcrumb).toHaveClass('yfm_blog_breadcrumbs'); | ||
}); | ||
|
||
test('render with date', async () => { | ||
const qaAttr = getQaAttributes(qaAttributes.postInfo, 'date'); | ||
|
||
render(<RenderComponent {...metaProps} />); | ||
const blogBreadcrumb = screen.getByTestId(qaAttr.date); | ||
|
||
expect(blogBreadcrumb).toHaveTextContent(format(post.date, 'longDate', metaProps.locale)); | ||
}); | ||
|
||
test('render with reading time', async () => { | ||
const qaAttr = getQaAttributes(qaAttributes.postInfo, 'reading-time'); | ||
|
||
render(<RenderComponent {...metaProps} />); | ||
const blogBreadcrumb = screen.getByTestId(qaAttr.readingTime); | ||
|
||
expect(blogBreadcrumb).toHaveTextContent( | ||
i18(Keyset.ContextReadingTime, {count: post.readingTime}), | ||
); | ||
}); | ||
|
||
test('render with share menu', async () => { | ||
render(<RenderComponent {...metaProps} />); | ||
const user = userEvent.setup(); | ||
const shareComponent = screen.getByText('Share'); | ||
await user.click(shareComponent); | ||
|
||
const shareOption = screen.getByText('Copy link'); | ||
|
||
expect(shareOption).toBeVisible(); | ||
}); | ||
|
||
test('render with likes', async () => { | ||
const qaAttr = getQaAttributes(qaAttributes.postInfo, 'save'); | ||
|
||
render(<RenderComponent {...metaProps} />); | ||
|
||
const component = screen.getByTestId(qaAttr.save); | ||
|
||
expect(component).toHaveTextContent(likes.likesCount.toString()); | ||
}); | ||
|
||
test.each(new Array<PaddingSize>(...PADDING_SIZES))( | ||
'render with given "%s" paddingTop size', | ||
(size: PaddingSize) => { | ||
testPaddingTop<MetaProps>({ | ||
component: RenderComponent, | ||
props: {...metaProps, paddingTop: size}, | ||
options: {qaId: qaAttributes.wrapper}, | ||
}); | ||
}, | ||
); | ||
|
||
test.each(new Array<PaddingSize>(...PADDING_SIZES))( | ||
'render with given "%s" paddingBottom size', | ||
(size: PaddingSize) => { | ||
testPaddingBottom<MetaProps>({ | ||
component: RenderComponent, | ||
props: {...metaProps, paddingBottom: size}, | ||
options: {qaId: qaAttributes.wrapper}, | ||
}); | ||
}, | ||
); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import React, {useContext} from 'react'; | ||
|
||
import {LocaleContext} from '../../../contexts/LocaleContext'; | ||
import {PostCardSize} from '../../../models/common'; | ||
import {PostCardSize, QAProps} from '../../../models/common'; | ||
import {block} from '../../../utils/cn'; | ||
import {format} from '../../../utils/date'; | ||
|
||
import '../PostInfo.scss'; | ||
|
||
const b = block('post-info'); | ||
|
||
type DateProps = { | ||
type DateProps = QAProps & { | ||
date: string | number; | ||
size?: PostCardSize; | ||
}; | ||
|
||
export const Date = ({date, size = PostCardSize.SMALL}: DateProps) => { | ||
export const Date = ({date, size = PostCardSize.SMALL, qa}: DateProps) => { | ||
const {locale} = useContext(LocaleContext); | ||
|
||
return <div className={b('item', {size})}>{format(date, 'longDate', locale?.code)}</div>; | ||
return ( | ||
<div className={b('item', {size})} data-qa={qa}> | ||
{format(date, 'longDate', locale?.code)} | ||
</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
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