Skip to content

Commit

Permalink
Merge pull request #3166 from benfurber/feat/follow/add-loading-condi…
Browse files Browse the repository at this point in the history
…tion

Fix: Follow button test
  • Loading branch information
thisislawatts authored Jan 15, 2024
2 parents 3f27c72 + b807489 commit 3d595e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
19 changes: 6 additions & 13 deletions packages/components/src/FollowButton/FollowButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'

import { Button, Tooltip } from '..'
Expand All @@ -13,30 +12,24 @@ export interface IProps {
}

export const FollowButton = (props: IProps) => {
const { hasUserSubscribed, isLoggedIn, onFollowClick, sx } = props
const navigate = useNavigate()
const [hasUserSubscribed, setHasUserSubscribed] = useState<boolean>()

useEffect(
() => setHasUserSubscribed(props.hasUserSubscribed),
[props.hasUserSubscribed],
)

return (
<>
<Button
data-testid={props.isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-cy={props.isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-tip={props.isLoggedIn ? '' : 'Login to follow'}
data-testid={isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-cy={isLoggedIn ? 'follow-button' : 'follow-redirect'}
data-tip={isLoggedIn ? '' : 'Login to follow'}
icon="thunderbolt"
variant="outline"
iconColor={hasUserSubscribed ? 'subscribed' : 'notSubscribed'}
sx={{
fontSize: 2,
py: 0,
...sx,
}}
onClick={() =>
props.isLoggedIn ? props.onFollowClick() : navigate('/sign-in')
}
onClick={() => (isLoggedIn ? onFollowClick() : navigate('/sign-in'))}
>
{hasUserSubscribed ? 'Following' : 'Follow'}
</Button>
Expand Down
7 changes: 0 additions & 7 deletions packages/cypress/src/integration/research/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,9 @@ describe('[Research]', () => {

cy.step('Should persist follow status on reload')
cy.visit(researchArticleUrl)
cy.get('[data-cy="follow-button"]').first().click()
cy.get('[data-cy="follow-button"]')
.first()
.should('contain.text', 'Following')

cy.step('Should unfollow on click')
cy.get('[data-cy="follow-button"]').first().click()
cy.get('[data-cy="follow-button"]')
.first()
.should('contain.text', 'Follow')
})
})
})

0 comments on commit 3d595e1

Please sign in to comment.