From 75196d185d8e06b220dfe4ccaf40f11131b09990 Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Mon, 17 May 2021 23:30:03 +0300 Subject: [PATCH] avatar fixes after review --- frontend/app/components/avatar/avatar.spec.tsx | 13 +++++++++---- frontend/app/components/avatar/avatar.tsx | 12 ++++++++---- frontend/app/components/comment/comment.tsx | 4 +--- frontend/app/components/user-info/user-info.tsx | 2 +- frontend/app/typings/svg.d.ts | 5 +++++ 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 frontend/app/typings/svg.d.ts diff --git a/frontend/app/components/avatar/avatar.spec.tsx b/frontend/app/components/avatar/avatar.spec.tsx index 76d3de5b..9ac51a52 100644 --- a/frontend/app/components/avatar/avatar.spec.tsx +++ b/frontend/app/components/avatar/avatar.spec.tsx @@ -7,10 +7,15 @@ import { BASE_URL } from 'common/constants.config'; import { Avatar } from './avatar'; describe('', () => { - it('should get', () => { - const { getByAltText } = render(); + it('should have correct url', () => { + const { container } = render(); - expect(getByAltText('avatar')).toHaveAttribute('src', `${BASE_URL}/image.svg`); - expect(getByAltText('avatar')).toHaveAttribute('alt', 'avatar'); + expect(container.querySelector('img')).toHaveAttribute('src', `${BASE_URL}/image.svg`); + }); + + it("shouldn't be accessible with screen reader", () => { + const { container } = render(); + + expect(container.querySelector('img')).toHaveAttribute('aria-hidden', 'true'); }); }); diff --git a/frontend/app/components/avatar/avatar.tsx b/frontend/app/components/avatar/avatar.tsx index 89b46265..d3f8e7c4 100644 --- a/frontend/app/components/avatar/avatar.tsx +++ b/frontend/app/components/avatar/avatar.tsx @@ -3,20 +3,24 @@ import { h } from 'preact'; import { BASE_URL } from 'common/constants.config'; +import ghostIconUrl from './assets/ghost.svg'; import styles from './avatar.module.css'; type Props = { url?: string; - alt: string; /** className should be used only in puprose of put permanent class on Avatar for user themization */ className: string; }; -export function Avatar({ url, className, alt }: Props) { - const avatarUrl = url || `${BASE_URL}${require('./assets/ghost.svg').default}`; +export function Avatar({ url, className }: Props) { + const avatarUrl = url || `${BASE_URL}${ghostIconUrl}`; return ( // eslint-disable-next-line jsx-a11y/alt-text - {alt} + ); } diff --git a/frontend/app/components/comment/comment.tsx b/frontend/app/components/comment/comment.tsx index 775f49fc..3ed409fa 100644 --- a/frontend/app/components/comment/comment.tsx +++ b/frontend/app/components/comment/comment.tsx @@ -660,9 +660,7 @@ export class Comment extends Component { )}
- {props.view !== 'user' && !props.collapsed && ( - - )} + {props.view !== 'user' && !props.collapsed && } {props.view !== 'user' && ( { return (
- +