|
1 | | -import PropTypes from 'prop-types'; |
2 | 1 | import React from 'react'; |
3 | 2 | import { Link } from 'react-router-dom'; |
4 | 3 | import { useTranslation } from 'react-i18next'; |
5 | 4 |
|
6 | 5 | import LogoIcon from '../images/p5js-logo-small.svg'; |
7 | 6 | import CodeIcon from '../images/code.svg'; |
8 | 7 |
|
9 | | -const PreviewNav = ({ owner, project }) => { |
| 8 | +interface PreviewNavProps { |
| 9 | + owner: { username: string }; |
| 10 | + project: { name: string; id: string }; |
| 11 | +} |
| 12 | + |
| 13 | +export const PreviewNav = ({ owner, project }: PreviewNavProps) => { |
10 | 14 | const { t } = useTranslation(); |
11 | 15 | return ( |
12 | | - <nav className="nav preview-nav"> |
13 | | - <div className="nav__items-left"> |
14 | | - <div className="nav__item-logo"> |
15 | | - <Link to={`/${owner.username}/sketches`}> |
| 16 | + <nav className="nav preview-nav" data-testid="preview-nav"> |
| 17 | + <div className="nav__items-left" data-testid="nav-items-left"> |
| 18 | + <div className="nav__item-logo" data-testid="nav-item-logo"> |
| 19 | + <Link |
| 20 | + to={`/${owner.username}/sketches`} |
| 21 | + data-testid="icon-link_user-sketches" |
| 22 | + > |
16 | 23 | <LogoIcon |
17 | 24 | role="img" |
18 | 25 | aria-label={t('Common.p5logoARIA')} |
19 | 26 | focusable="false" |
20 | 27 | className="svg__logo" |
| 28 | + data-testid="icon_p5-logo" |
21 | 29 | /> |
22 | 30 | </Link> |
23 | 31 | </div> |
24 | 32 | <Link |
25 | 33 | className="nav__item" |
26 | 34 | to={`/${owner.username}/sketches/${project.id}`} |
| 35 | + data-testid="link_current-project" |
27 | 36 | > |
28 | 37 | {project.name} |
29 | 38 | </Link> |
30 | 39 | <p className="toolbar__project-owner">{t('PreviewNav.ByUser')}</p> |
31 | | - <Link className="nav__item" to={`/${owner.username}/sketches/`}> |
| 40 | + <Link |
| 41 | + className="nav__item" |
| 42 | + to={`/${owner.username}/sketches`} |
| 43 | + data-testid="link_user-sketches" |
| 44 | + > |
32 | 45 | {owner.username} |
33 | 46 | </Link> |
34 | 47 | </div> |
35 | | - <div className="nav__items-right"> |
| 48 | + <div className="nav__items-right" data-testid="nav-items-right"> |
36 | 49 | <Link |
37 | 50 | to={`/${owner.username}/sketches/${project.id}`} |
38 | 51 | aria-label={t('PreviewNav.EditSketchARIA')} |
| 52 | + data-testid="link_project-code" |
39 | 53 | > |
40 | 54 | <CodeIcon |
41 | 55 | className="preview-nav__editor-svg" |
42 | 56 | focusable="false" |
43 | 57 | aria-hidden="true" |
| 58 | + data-testid="icon_code" |
44 | 59 | /> |
45 | 60 | </Link> |
46 | 61 | </div> |
47 | 62 | </nav> |
48 | 63 | ); |
49 | 64 | }; |
50 | | - |
51 | | -PreviewNav.propTypes = { |
52 | | - owner: PropTypes.shape({ |
53 | | - username: PropTypes.string.isRequired |
54 | | - }).isRequired, |
55 | | - project: PropTypes.shape({ |
56 | | - name: PropTypes.string.isRequired, |
57 | | - id: PropTypes.string.isRequired |
58 | | - }).isRequired |
59 | | -}; |
60 | | - |
61 | | -export default PreviewNav; |
|
0 commit comments