Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"tsx": "never"
}
],
"react/jsx-filename-extension": [1, { "extensions": [".jsx", ".tsx"] }],
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
"default-param-last": 0,
"no-else-return" :0,
Expand Down Expand Up @@ -126,7 +127,12 @@
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
"rules": {
"no-use-before-define": "off",
"import/no-extraneous-dependencies": "off",
"no-unused-vars": "off"
}
},
{
"files": ["*.stories.@(js|jsx|ts|tsx)"],
Expand Down
40 changes: 40 additions & 0 deletions client/components/SkipLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import '@testing-library/jest-dom';
import SkipLink from './SkipLink';

jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string) => key
})
}));

describe('SkipLink', () => {
const defaultProps = {
targetId: 'main-content',
text: 'goToMain'
};

test('renders with correct href and text', () => {
render(<SkipLink {...defaultProps} />);
const link = screen.getByRole('link');

expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', '#main-content');
expect(link).toHaveTextContent('SkipLink.goToMain');
});

test('adds "focus" class on focus and removes it on blur', () => {
render(<SkipLink {...defaultProps} />);
const link = screen.getByRole('link');

expect(link.className).toBe('skip_link');

fireEvent.focus(link);
expect(link.className).toContain('focus');

fireEvent.blur(link);
expect(link.className).toBe('skip_link');
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';

const SkipLink = ({ targetId, text }) => {
type SkipLinkProps = {
targetId: string,
text: string
};

const SkipLink = ({ targetId, text }: SkipLinkProps) => {
const [focus, setFocus] = useState(false);
const { t } = useTranslation();
const handleFocus = () => {
Expand All @@ -27,9 +31,4 @@ const SkipLink = ({ targetId, text }) => {
);
};

SkipLink.propTypes = {
targetId: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
};

export default SkipLink;