Skip to content

Commit

Permalink
feat(react-intl): added localization keys for all entries (nodejs#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd authored Aug 22, 2022
1 parent 8f21dce commit 3d50be5
Show file tree
Hide file tree
Showing 124 changed files with 703 additions and 520 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ module.exports = {
},
},
{
files: ['test-processor.js', 'test-setup.js', 'test/**'],
files: [
'test-processor.js',
'test-setup.js',
'test/**',
'**/**.test.js',
'**/**.test.ts',
'**/**.test.tsx',
],
extends: ['plugin:testing-library/react'],
env: {
jest: true,
Expand Down
2 changes: 1 addition & 1 deletion test/__fixtures__/hooks.tsx → src/__fixtures__/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContributorApiResponse, Contributor } from '../../src/hooks';
import { ContributorApiResponse, Contributor } from '../hooks';

export const createRandomContributorApiData = (): ContributorApiResponse => ({
login: 'login_mock',
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions test/__fixtures__/page.tsx → src/__fixtures__/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
NodeReleaseData,
TableOfContents,
BlogCategoriesList,
} from '../../src/types';
} from '../types';
import mockMDXBodyContent from './mockMDXBodyContent';

export const mockTableOfContents: TableOfContents = {
Expand Down Expand Up @@ -168,7 +168,7 @@ export const createBlogData = (): BlogPostsList & BlogCategoriesList => ({
],
},
fields: {
date: 'Mock date',
date: '11/11/2022',
slug: 'Mock blog slug',
readingTime: {
text: '1 min read',
Expand Down Expand Up @@ -197,7 +197,7 @@ export const createBlogPageData = (): BlogPageData => ({
},
],
},
fields: { slug: 'slug-mock', date: 'date-mock' },
fields: { slug: 'slug-mock', date: '11/11/2022' },
},
recent: {
edges: [
Expand All @@ -218,7 +218,7 @@ export const createBlogPageData = (): BlogPageData => ({
],
},
fields: {
date: 'date-mock',
date: '11/11/2022',
slug: 'slug-mock',
readingTime: { text: 'text-mock' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ exports[`Article component renders correctly 1`] = `
<span>
Edit this page on GitHub
</span>
<svg
class="icon"
fill="currentColor"
Expand All @@ -129,7 +128,7 @@ exports[`Article component renders correctly 1`] = `
href="/learn/test-slug"
rel="prev"
>
  Prev
← Prev
</a>
</li>
<li>
Expand All @@ -138,7 +137,7 @@ exports[`Article component renders correctly 1`] = `
href="/learn/test-slug"
rel="next"
>
Next  
Next →
</a>
</li>
</ul>
Expand Down Expand Up @@ -324,7 +323,6 @@ exports[`Article component renders correctly in case body ref is null 1`] = `
<span>
Edit this page on GitHub
</span>
<svg
class="icon"
fill="currentColor"
Expand All @@ -347,7 +345,7 @@ exports[`Article component renders correctly in case body ref is null 1`] = `
href="/learn/test-slug"
rel="prev"
>
  Prev
← Prev
</a>
</li>
<li>
Expand All @@ -356,7 +354,7 @@ exports[`Article component renders correctly in case body ref is null 1`] = `
href="/learn/test-slug"
rel="next"
>
Next  
Next →
</a>
</li>
</ul>
Expand Down Expand Up @@ -477,7 +475,6 @@ exports[`Article component should accept and render child components 1`] = `
<span>
Edit this page on GitHub
</span>
<svg
class="icon"
fill="currentColor"
Expand All @@ -500,7 +497,7 @@ exports[`Article component should accept and render child components 1`] = `
href="/learn/test-slug"
rel="prev"
>
  Prev
← Prev
</a>
</li>
<li>
Expand All @@ -509,7 +506,7 @@ exports[`Article component should accept and render child components 1`] = `
href="/learn/test-slug"
rel="next"
>
Next  
Next →
</a>
</li>
</ul>
Expand Down
4 changes: 1 addition & 3 deletions src/components/Article/__tests__/article.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import { render } from '@testing-library/react';
import '../../../../test/__mocks__/intersectionObserverMock';

import Article from '..';
import {
createLearnPageData,
createLearnPageContext,
} from '../../../../test/__fixtures__/page';
} from '../../../__fixtures__/page';

const getArticleProps = () => {
const learnPageData = createLearnPageData();
Expand Down
16 changes: 10 additions & 6 deletions src/components/BlogCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
import React, { Fragment } from 'react';
import { injectIntl, WrappedComponentProps } from 'react-intl';
import { BlogMetaData } from '../../types';
import { getTerminatingString } from '../../util/getTerminatingString';
import './BlogCard.scss';

interface Props {
data: BlogMetaData;
}
type Props = { data: BlogMetaData } & WrappedComponentProps;

const getBlogCategoryUrl = (category: string): string => `/blog/${category}/`;

Expand All @@ -17,6 +16,7 @@ const BlogCard = ({
frontmatter: { blogAuthors, title, category },
},
},
intl,
}: Props): JSX.Element => (
<div className="blog-card">
<div className="title">
Expand All @@ -33,16 +33,20 @@ const BlogCard = ({
<div className="content">
<h4>{date}</h4>
<p>
by{' '}
{intl.formatMessage({ id: 'blog.authors.list.title.by' })}{' '}
{blogAuthors?.map((author, i) => (
<Fragment key={author.name}>
<span>{author.name}</span>
{getTerminatingString(i, blogAuthors.length)}
{getTerminatingString(
i,
blogAuthors.length,
` ${intl.formatMessage({ id: 'blog.authors.list.title.and' })} `
)}
</Fragment>
))}
</p>
</div>
</div>
);

export default BlogCard;
export default injectIntl(BlogCard);
12 changes: 6 additions & 6 deletions src/components/Codebox/__tests__/codebox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';

import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';

import Codebox from '../index';

Expand Down Expand Up @@ -35,7 +34,8 @@ describe('Codebox component', (): void => {

it('renders correctly', async () => {
const textToCopy = <p>text to be copy</p>;
const { getByText, findByText } = render(

render(
<Codebox>
{{
props: {
Expand All @@ -48,12 +48,12 @@ describe('Codebox component', (): void => {

navigatorClipboardSpy.mockImplementationOnce(() => Promise.resolve());

const buttonElement = getByText('copy');
const buttonElement = screen.getByText('copy');
userEvent.click(buttonElement);

await findByText('copied');
await screen.findByText('copied');

expect(getByText('done')).toBeInTheDocument();
expect(screen.getByText('done')).toBeInTheDocument();
expect(navigatorClipboardSpy).toHaveBeenCalledTimes(1);
expect(navigatorClipboardSpy).toHaveBeenCalledWith(textToCopy.toString());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { render } from '@testing-library/react';
import DownloadAdditional from '..';

describe('DownloadAdditional component', (): void => {
Expand Down Expand Up @@ -40,6 +40,7 @@ describe('DownloadAdditional component', (): void => {
/>
);

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
const downloadItem = container.querySelector(
'.download-additional__item'
) as Element;
Expand All @@ -59,6 +60,7 @@ describe('DownloadAdditional component', (): void => {
/>
);

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
const downloadItem = container.querySelector(
'.download-additional__item'
) as Element;
Expand Down
11 changes: 7 additions & 4 deletions src/components/DownloadAdditional/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, FC } from 'react';
import { FormattedMessage } from 'react-intl';
import DownloadToggle from '../DownloadToggle';
import { NodeReleaseLTSNPMVersion } from '../../types';
import { getDownloadableItemsList, Downloadable } from './downloadItems';
Expand All @@ -16,7 +17,7 @@ const DownloadButton: FC<DownloadButtonProps> = ({
className,
link,
label,
}: DownloadButtonProps) => (
}) => (
<a className={className} href={link}>
<i className="material-icons">get_app</i>
{label}
Expand All @@ -33,7 +34,7 @@ const DownloadableItem: FC<DownloadableItemProps> = ({
item,
isExpanded,
setExpandedItem,
}: DownloadableItemProps) => {
}) => {
const onClick = (): void =>
isExpanded ? setExpandedItem('') : setExpandedItem(item.name);
const classes = `${CLASS_NAME}__item`.concat(
Expand Down Expand Up @@ -84,12 +85,14 @@ const DownloadAdditional: FC<DownloadAdditionalProps> = ({
line,
selectedTypeRelease,
handleTypeReleaseToggle,
}: DownloadAdditionalProps): JSX.Element => {
}) => {
const [expandedItem, setExpandedItem] = useState('');
return (
<div className={CLASS_NAME}>
<div className={`${CLASS_NAME}__header`}>
<h3 className={`${CLASS_NAME}__title`}>Additional Downloads</h3>
<h3 className={`${CLASS_NAME}__title`}>
<FormattedMessage id="components.downloadAdditional.title" />
</h3>
<DownloadToggle
selected={selectedTypeRelease}
handleClick={handleTypeReleaseToggle}
Expand Down
14 changes: 6 additions & 8 deletions src/components/DownloadCards/__tests__/download-cards.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { render, screen, fireEvent } from '@testing-library/react';

import DownloadCards from '..';
import { UserOS } from '../../../util/detectOS';
Expand All @@ -12,9 +12,9 @@ describe('DownloadCards component', (): void => {
});

it('check click handler on DownloadCards component', async () => {
const { getAllByRole } = render(<DownloadCards userOS={UserOS.MAC} />);
render(<DownloadCards userOS={UserOS.MAC} />);

const listElement = getAllByRole('tab');
const listElement = screen.getAllByRole('tab');

expect(listElement[0]).toHaveClass('download-card');

Expand All @@ -24,12 +24,10 @@ describe('DownloadCards component', (): void => {
});

it('check left and right arrow click handler on DownloadCards component', (): void => {
const { getByRole, getAllByRole } = render(
<DownloadCards userOS={UserOS.MAC} />
);
render(<DownloadCards userOS={UserOS.MAC} />);

const tabListElement = getByRole('tablist');
const listElement = getAllByRole('tab');
const tabListElement = screen.getByRole('tablist');
const listElement = screen.getAllByRole('tab');

expect(listElement[0]).toHaveClass('download-card');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ exports[`DownloadHeader component renders correctly 1`] = `
>
<div>
HOME /
<span
class="download-page__navigation--active"
>
downloads
downloads
</span>
</div>
<div>
CURRENT
VERSION
v14.11.0
CURRENT VERSION v14.11.0
</div>
</div>
<div
Expand All @@ -30,9 +29,7 @@ exports[`DownloadHeader component renders correctly 1`] = `
<div
class="download-page__navigation--npm"
>
(includes npm
6.14.8
)
(includes npm 6.14.8)
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 3d50be5

Please sign in to comment.