Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(project): add anchor tags for better seo #345

Merged
merged 26 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2b18938
fix(project): e2e tests
olga-jwp Jul 25, 2023
f0398a1
fix(project): set card url prop required
olga-jwp Jul 26, 2023
9d86f5e
fix(project): fix Card tests
olga-jwp Jul 26, 2023
ae61a01
chore(project): code cleanup for cards seo
olga-jwp Jul 26, 2023
5af16a3
fix(project): aff url for card tests
olga-jwp Jul 26, 2023
ea1e4d6
fix(project): remove conditional url
olga-jwp Jul 26, 2023
8a1dff2
fix(project): update test snap
olga-jwp Jul 26, 2023
7778618
fix(project): search refactoring
olga-jwp Jul 26, 2023
5233e2d
chore(project): code cleanup
olga-jwp Jul 27, 2023
9b168f4
chore(project): code cleanup
olga-jwp Jul 27, 2023
f0ada87
chore(project): code cleanup
olga-jwp Jul 28, 2023
c6fbbc7
chore(project): fix unit test
olga-jwp Jul 28, 2023
508d4c3
Merge branch 'develop' into chore/seo-add-anchor-tag
olga-jwp Jul 28, 2023
db164ae
Merge branch 'feature/cumulative-seo-cards' into chore/seo-add-anchor…
olga-jwp Jul 28, 2023
595e55d
fix(project): resolve merge conflicts
olga-jwp Jul 28, 2023
48a983a
chore(project): add redirect url for series cards
olga-jwp Jul 28, 2023
32465ce
fix(project): remove onKeyDown from card
olga-jwp Jul 31, 2023
541a188
fix(project): update e2e tests
olga-jwp Aug 1, 2023
74d2423
chore(project): add getURL for setting anchor links
olga-jwp Aug 2, 2023
2d69e3c
fix(project): fix urls for card links
olga-jwp Aug 2, 2023
5abe506
fix(project): fix urls for card links
olga-jwp Aug 2, 2023
ff2e153
fix(project): update CardGrid tests
olga-jwp Aug 2, 2023
d83c736
Merge branch 'feature/cumulative-seo-cards' into chore/seo-add-anchor…
olga-jwp Aug 2, 2023
9e8c5cc
fix(project): update CardGrid tests
olga-jwp Aug 2, 2023
1388ad2
fix(project): e2e tests
olga-jwp Aug 2, 2023
b6c6df5
fix(project): e2e mobile tests
olga-jwp Aug 2, 2023
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
14 changes: 9 additions & 5 deletions src/components/Card/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ const itemWithImage = { title: 'This is a movie', duration: 120, cardImage: 'htt

describe('<Card>', () => {
it('renders card with video title', () => {
const { getByText } = renderWithRouter(<Card item={item} onClick={() => ''} />);
const { getByText } = renderWithRouter(<Card item={item} url="https://test.dummy.jwplayer.com" />);
expect(getByText(/aa/i)).toBeTruthy();
});

it('renders tag with correct duration', () => {
const { getByText } = renderWithRouter(<Card item={item} onClick={() => ''} />);
const { getByText } = renderWithRouter(<Card item={item} url="https://test.dummy.jwplayer.com" />);
expect(getByText(/2/i)).toBeTruthy();
});

it('renders the image with the image prop when valid', () => {
const { getByAltText } = renderWithRouter(<Card item={itemWithImage} onClick={() => ''} />);

const { getByAltText } = renderWithRouter(<Card item={itemWithImage} url="https://test.dummy.jwplayer.com" />);
expect(getByAltText('This is a movie')).toHaveAttribute('src', 'http://movie.jpg?width=320');
});

it('makes the image visible after load', () => {
const { getByAltText } = renderWithRouter(<Card item={itemWithImage} onClick={() => ''} />);
const { getByAltText } = renderWithRouter(<Card item={itemWithImage} url="https://test.dummy.jwplayer.com" />);

expect(getByAltText('This is a movie')).toHaveAttribute('src', 'http://movie.jpg?width=320');
expect(getByAltText('This is a movie')).toHaveStyle({ opacity: 0 });
Expand All @@ -36,4 +35,9 @@ describe('<Card>', () => {

expect(getByAltText('This is a movie')).toHaveStyle({ opacity: 1 });
});

it('should render anchor tag', () => {
const { container } = renderWithRouter(<Card item={itemWithImage} url="https://test.dummy.jwplayer.com" />);
expect(container).toMatchSnapshot();
});
});
11 changes: 4 additions & 7 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type PosterAspectRatio = (typeof cardAspectRatios)[number];

type CardProps = {
item: PlaylistItem;
onClick?: () => void;
onHover?: () => void;
progress?: number;
posterAspect?: PosterAspectRatio;
Expand All @@ -29,11 +28,10 @@ type CardProps = {
isCurrent?: boolean;
isLocked?: boolean;
currentLabel?: string;
url?: string;
url: string;
};

function Card({
onClick,
onHover,
progress,
item,
Expand Down Expand Up @@ -90,13 +88,12 @@ function Card({

return (
<Link
to={url ?? ''}
to={url}
className={cardClassName}
onClick={onClick}
onClick={disabled ? (e) => e.preventDefault() : undefined}
onMouseEnter={onHover}
tabIndex={disabled ? -1 : 0}
onKeyDown={(event: KeyboardEvent) => (event.key === 'Enter' || event.key === ' ') && !disabled && onClick && onClick()}
role="button"
onKeyDown={(event: KeyboardEvent) => (event.key === 'Enter' || event.key === ' ') && !disabled}
dbudzins marked this conversation as resolved.
Show resolved Hide resolved
aria-label={title}
>
<div className={posterClassNames}>
Expand Down
62 changes: 62 additions & 0 deletions src/components/Card/__snapshots__/Card.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`<Card> > should render anchor tag 1`] = `
<div>
<a
aria-label="This is a movie"
class="_card_d75732"
href="/https://test.dummy.jwplayer.com"
tabindex="0"
>
<div
class="_poster_d75732 _aspect169_d75732"
>
<img
alt="This is a movie"
class="_posterImage_d75732 _image_4c41c3"
src="http://movie.jpg?width=320"
/>
<div
class="_meta_d75732"
>
<div
class="_tags_d75732"
>
<div
aria-label="card_lock"
class="_tag_d75732 _lock_d75732"
role="status"
>
<svg
aria-hidden="true"
class="_icon_1e9999"
focusable="false"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z"
fill="currentColor"
/>
</svg>
</div>
<div
class="_tag_d75732"
>
2 min
</div>
</div>
</div>
</div>
<div
class="_titleContainer_d75732"
>
<div
class="_title_d75732"
>
This is a movie
</div>
</div>
</a>
</div>
`;
10 changes: 1 addition & 9 deletions src/components/CardGrid/CardGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ describe('<CardGrid>', () => {
it('renders and matches snapshot', () => {
const playlist = playlistFixture as Playlist;
const { container } = renderWithRouter(
<CardGrid
playlist={playlist}
onCardHover={vi.fn()}
onCardClick={vi.fn()}
isLoading={false}
accessModel={'SVOD'}
isLoggedIn={true}
hasSubscription={true}
/>,
<CardGrid playlist={playlist} onCardHover={vi.fn()} isLoading={false} accessModel={'SVOD'} isLoggedIn={true} hasSubscription={true} />,
);

expect(container).toMatchSnapshot();
Expand Down
3 changes: 0 additions & 3 deletions src/components/CardGrid/CardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type CardGridProps = {
hasLoadMore?: boolean;
loadMore?: () => void;
onCardHover?: (item: PlaylistItem) => void;
onCardClick: (item: PlaylistItem, playlistId?: string) => void;
};

function CardGrid({
Expand All @@ -52,7 +51,6 @@ function CardGrid({
hasSubscription,
hasLoadMore,
loadMore,
onCardClick,
onCardHover,
}: CardGridProps) {
const breakpoint: Breakpoint = useBreakpoint();
Expand All @@ -78,7 +76,6 @@ function CardGrid({
<Card
progress={watchHistory ? watchHistory[mediaid] : undefined}
url={url}
onClick={() => onCardClick(playlistItem, playlistItem.feedid)}
onHover={typeof onCardHover === 'function' ? () => onCardHover(playlistItem) : undefined}
loading={isLoading}
isCurrent={currentCardItem && currentCardItem.mediaid === mediaid}
Expand Down
3 changes: 0 additions & 3 deletions src/components/CardGrid/__snapshots__/CardGrid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exports[`<CardGrid> > renders and matches snapshot 1`] = `
aria-label="Agent 327"
class="_card_d75732"
href="/m/uB8aRnu6/agent-327?r=dGSUzs9o"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -61,7 +60,6 @@ exports[`<CardGrid> > renders and matches snapshot 1`] = `
aria-label="Big Buck Bunny"
class="_card_d75732"
href="/m/awWEFyPu/big-buck-bunny?r=dGSUzs9o"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -104,7 +102,6 @@ exports[`<CardGrid> > renders and matches snapshot 1`] = `
aria-label="Elephants Dream"
class="_card_d75732"
href="/m/eFPH2tVG/elephants-dream?r=dGSUzs9o"
role="button"
tabindex="0"
>
<div
Expand Down
1 change: 0 additions & 1 deletion src/components/Favorites/Favorites.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('<Favorites>', () => {
playlist={playlist}
error={error}
isLoading={isLoading}
onCardClick={() => null}
onCardHover={() => null}
onClearFavoritesClick={() => null}
hasSubscription={true}
Expand Down
4 changes: 1 addition & 3 deletions src/components/Favorites/Favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Props = {
isLoading: boolean;
accessModel: AccessModel;
hasSubscription: boolean;
onCardClick: (item: PlaylistItem) => void;
onCardHover?: (item: PlaylistItem) => void;
onClearFavoritesClick: () => void;
};
Expand All @@ -30,7 +29,7 @@ const cols: Breakpoints = {
[Breakpoint.xl]: 3,
};

const Favorites = ({ playlist, error, isLoading, accessModel, hasSubscription, onCardClick, onCardHover, onClearFavoritesClick }: Props): JSX.Element => {
const Favorites = ({ playlist, error, isLoading, accessModel, hasSubscription, onCardHover, onClearFavoritesClick }: Props): JSX.Element => {
const { t } = useTranslation('user');

if (isLoading) return <LoadingOverlay />;
Expand All @@ -48,7 +47,6 @@ const Favorites = ({ playlist, error, isLoading, accessModel, hasSubscription, o
{playlist.playlist.length > 0 ? (
<CardGrid
playlist={playlist}
onCardClick={onCardClick}
onCardHover={onCardHover}
cols={cols}
isLoading={isLoading}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shelf/Shelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const Shelf = ({
isLocked={isLocked(accessModel, isLoggedIn, hasSubscription, item)}
posterAspect={posterAspect}
item={item}
url={isInView ? url : undefined}
url={url}
/>
);
},
Expand Down
17 changes: 4 additions & 13 deletions src/components/Shelf/__snapshots__/Shelf.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ exports[`Shelf Component tests > Featured shelf 1`] = `
<a
aria-label="Third movie"
class="_card_d75732 _featured_d75732 _disabled_d75732"
href="/"
role="button"
href="/m/12332123/third-movie"
tabindex="-1"
>
<div
Expand All @@ -67,8 +66,7 @@ exports[`Shelf Component tests > Featured shelf 1`] = `
<a
aria-label="Last playlist item"
class="_card_d75732 _featured_d75732 _disabled_d75732"
href="/"
role="button"
href="/m/ddeeddee/last-playlist-item"
tabindex="-1"
>
<div
Expand All @@ -92,7 +90,6 @@ exports[`Shelf Component tests > Featured shelf 1`] = `
aria-label="Movie 1"
class="_card_d75732 _featured_d75732"
href="/m/1234abcd/movie-1"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -126,8 +123,7 @@ exports[`Shelf Component tests > Featured shelf 1`] = `
<a
aria-label="Movie 2"
class="_card_d75732 _featured_d75732 _disabled_d75732"
href="/"
role="button"
href="/m/aaaaaaaa/movie-2"
tabindex="-1"
>
<div
Expand All @@ -150,8 +146,7 @@ exports[`Shelf Component tests > Featured shelf 1`] = `
<a
aria-label="Third movie"
class="_card_d75732 _featured_d75732 _disabled_d75732"
href="/"
role="button"
href="/m/12332123/third-movie"
tabindex="-1"
>
<div
Expand Down Expand Up @@ -239,7 +234,6 @@ exports[`Shelf Component tests > Regular shelf 1`] = `
aria-label="Movie 1"
class="_card_d75732"
href="/m/1234abcd/movie-1"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -278,7 +272,6 @@ exports[`Shelf Component tests > Regular shelf 1`] = `
aria-label="Movie 2"
class="_card_d75732"
href="/m/aaaaaaaa/movie-2"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -317,7 +310,6 @@ exports[`Shelf Component tests > Regular shelf 1`] = `
aria-label="Third movie"
class="_card_d75732"
href="/m/12332123/third-movie"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -356,7 +348,6 @@ exports[`Shelf Component tests > Regular shelf 1`] = `
aria-label="Last playlist item"
class="_card_d75732"
href="/m/ddeeddee/last-playlist-item"
role="button"
tabindex="0"
>
<div
Expand Down
1 change: 0 additions & 1 deletion src/components/VideoLayout/VideoLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const VideoLayout: React.FC<Props> = ({
</div>
<CardGrid
playlist={playlist}
onCardClick={onItemClick}
isLoading={isLoading}
watchHistory={watchHistory}
accessModel={accessModel}
Expand Down
4 changes: 0 additions & 4 deletions src/pages/Home/__snapshots__/Home.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ exports[`Home Component tests > Home test 1`] = `
aria-label="My video"
class="_card_d75732"
href="/m/abcddabc/my-video"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -95,7 +94,6 @@ exports[`Home Component tests > Home test 1`] = `
aria-label="Other Vids"
class="_card_d75732"
href="/m/zzzaaazz/other-vids"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -181,7 +179,6 @@ exports[`Home Component tests > Home test 1`] = `
aria-label="My video"
class="_card_d75732"
href="/m/abcddabc/my-video"
role="button"
tabindex="0"
>
<div
Expand Down Expand Up @@ -238,7 +235,6 @@ exports[`Home Component tests > Home test 1`] = `
aria-label="Other Vids"
class="_card_d75732"
href="/m/zzzaaazz/other-vids"
role="button"
tabindex="0"
>
<div
Expand Down
Loading
Loading