Skip to content

Commit

Permalink
feat(webapp): hide mark as seen button for future episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoosepAlviste committed Dec 17, 2023
1 parent 01c7fd4 commit 1141ec6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import { addDays, format } from 'date-fns'
import React from 'react'

import { makeFragmentData } from '#/generated/gql'
Expand All @@ -25,11 +26,11 @@ describe('features/series/components/EpisodeLine', () => {
}: {
season: Season
episode: Episode
returnedEpisode: Episode
returnedEpisode?: Episode
}) => {
const [doc, mockResolver] = createMockResolver(ToggleEpisodeSeenDocument, {
data: {
toggleEpisodeSeen: returnedEpisode,
toggleEpisodeSeen: returnedEpisode ?? episode,
},
})

Expand Down Expand Up @@ -110,4 +111,16 @@ describe('features/series/components/EpisodeLine', () => {
},
})
})

it('does not render the mark as seen button if the episode airs in the future', async () => {
const episode = episodeFactory.build({
releasedAt: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
})

await renderEpisodeLine({ episode, season: episode.season })

expect(
screen.queryByRole('button', { name: 'Mark as seen' }),
).not.toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation } from '@apollo/client'
import { isFuture } from 'date-fns/esm'
import React from 'react'

import { Button, Text } from '#/components'
Expand Down Expand Up @@ -87,6 +88,10 @@ export const EpisodeLine = ({
}
}

const isAiringInTheFuture = episode.releasedAt
? isFuture(new Date(episode.releasedAt))
: false

return (
<li className={s.episode}>
<Text variant="secondary" weight="bold">
Expand All @@ -98,7 +103,7 @@ export const EpisodeLine = ({
{episode.releasedAt ? ` · ${formatDate(episode.releasedAt)}` : ''}
</Text>
</Text>
{currentUser && (
{currentUser && !isAiringInTheFuture && (
<Button
variant={episode.isSeen ? 'primary' : 'secondary'}
size="s"
Expand Down

0 comments on commit 1141ec6

Please sign in to comment.