Skip to content

Commit 8d7c29f

Browse files
authored
Merge pull request #3554 from clairep94/pr05/04/migrate_instance_of_react_file
pr05 Typescript #4: migrate instance of react file
2 parents b03ec08 + 143ed2c commit 8d7c29f

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"tsx": "never"
3030
}
3131
],
32+
"react/jsx-filename-extension": [1, { "extensions": [".jsx", ".tsx"] }],
3233
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
3334
"default-param-last": 0,
3435
"no-else-return" :0,
@@ -126,7 +127,12 @@
126127
{
127128
"files": ["*.ts", "*.tsx"],
128129
"parser": "@typescript-eslint/parser",
129-
"plugins": ["@typescript-eslint"]
130+
"plugins": ["@typescript-eslint"],
131+
"rules": {
132+
"no-use-before-define": "off",
133+
"import/no-extraneous-dependencies": "off",
134+
"no-unused-vars": "off"
135+
}
130136
},
131137
{
132138
"files": ["*.stories.@(js|jsx|ts|tsx)"],

client/components/SkipLink.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { render, screen, fireEvent } from '@testing-library/react';
2+
import React from 'react';
3+
import { useTranslation } from 'react-i18next';
4+
import '@testing-library/jest-dom';
5+
import SkipLink from './SkipLink';
6+
7+
jest.mock('react-i18next', () => ({
8+
useTranslation: () => ({
9+
t: (key: string) => key
10+
})
11+
}));
12+
13+
describe('SkipLink', () => {
14+
const defaultProps = {
15+
targetId: 'main-content',
16+
text: 'goToMain'
17+
};
18+
19+
test('renders with correct href and text', () => {
20+
render(<SkipLink {...defaultProps} />);
21+
const link = screen.getByRole('link');
22+
23+
expect(link).toBeInTheDocument();
24+
expect(link).toHaveAttribute('href', '#main-content');
25+
expect(link).toHaveTextContent('SkipLink.goToMain');
26+
});
27+
28+
test('adds "focus" class on focus and removes it on blur', () => {
29+
render(<SkipLink {...defaultProps} />);
30+
const link = screen.getByRole('link');
31+
32+
expect(link.className).toBe('skip_link');
33+
34+
fireEvent.focus(link);
35+
expect(link.className).toContain('focus');
36+
37+
fireEvent.blur(link);
38+
expect(link.className).toBe('skip_link');
39+
});
40+
});

client/components/SkipLink.jsx renamed to client/components/SkipLink.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import React, { useState } from 'react';
22
import classNames from 'classnames';
3-
import PropTypes from 'prop-types';
43
import { useTranslation } from 'react-i18next';
54

6-
const SkipLink = ({ targetId, text }) => {
5+
type SkipLinkProps = {
6+
targetId: string,
7+
text: string
8+
};
9+
10+
const SkipLink = ({ targetId, text }: SkipLinkProps) => {
711
const [focus, setFocus] = useState(false);
812
const { t } = useTranslation();
913
const handleFocus = () => {
@@ -27,9 +31,4 @@ const SkipLink = ({ targetId, text }) => {
2731
);
2832
};
2933

30-
SkipLink.propTypes = {
31-
targetId: PropTypes.string.isRequired,
32-
text: PropTypes.string.isRequired
33-
};
34-
3534
export default SkipLink;

0 commit comments

Comments
 (0)