Skip to content

Commit

Permalink
fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedtan committed Sep 19, 2023
1 parent f6129d5 commit 0edbc5f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ startedWithDate.args = {
impactCountPerMetric: 3,
dateStarted: '2020-01-10T10:00:00.000Z',
}

4 changes: 3 additions & 1 deletion src/components/groupImpactComponents/GroupImpactSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ const GroupImpactSidebar = ({
precision={3}
renderer={({ hours, days }) => (
<Typography className={classes.robotoBold}>
{`${days > 0 ? `${days} Days` : ``} ${hours > 0 ? `${hours} Hours` : ``} ${days > 0 || hours > 0 ? ` Left`: ``}`}
{`${days > 0 ? `${days} Days` : ``} ${
hours > 0 ? `${hours} Hours` : ``
} ${days > 0 || hours > 0 ? ` Left` : ``}`}
</Typography>
)}
/>
Expand Down
73 changes: 73 additions & 0 deletions src/components/groupImpactComponents/__tests__/GroupImpact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,77 @@ describe('GroupImpact component', () => {
const wrapper = mount(<GroupImpact {...mockProps} />)
expect(wrapper.find(GroupGoalNotification).exists()).toEqual(false)
})

it('displays values correctly if timeboxed', () => {
const GroupImpact =
require('src/components/groupImpactComponents/GroupImpact').default
const mockProps = {
user: {
id: 'user-id',
cause: {
groupImpactMetric: {
id: 'abcd',
dollarProgress: 250,
dollarProgressFromSearch: 125,
dollarGoal: 600,
impactMetric: {
impactTitle: 'impact-title',
whyValuableDescription: 'why-valuable-description',
impactCountPerMetric: 5,
},
dateStarted: '2023-09-19T10:00:00.000Z',
dateExpires: '2023-09-23T10:00:00.000Z',
},
},
},
}

localstorageManager.getNumericItem.mockReturnValue(0)
localstorageGroupImpactManager.getLastSeenGroupImpactMetric.mockReturnValue(
mockProps.user.cause.groupImpactMetric
)
const wrapper = mount(<GroupImpact {...mockProps} />)
expect(
wrapper.find(GroupGoalNotification).first().prop('dateStarted')
).toEqual(mockProps.user.cause.groupImpactMetric.dateStarted)
expect(wrapper.find(GroupImpactSidebar).prop('dateExpires')).toEqual(
mockProps.user.cause.groupImpactMetric.dateExpires
)
})

it('displays values correctly if not timeboxed', () => {
const GroupImpact =
require('src/components/groupImpactComponents/GroupImpact').default
const mockProps = {
user: {
id: 'user-id',
cause: {
groupImpactMetric: {
id: 'abcd',
dollarProgress: 250,
dollarProgressFromSearch: 125,
dollarGoal: 600,
impactMetric: {
impactTitle: 'impact-title',
whyValuableDescription: 'why-valuable-description',
impactCountPerMetric: 5,
},
dateStarted: '2023-09-19T10:00:00.000Z',
},
},
},
}

localstorageManager.getNumericItem.mockReturnValue(0)
localstorageGroupImpactManager.getLastSeenGroupImpactMetric.mockReturnValue(
mockProps.user.cause.groupImpactMetric
)
const wrapper = mount(<GroupImpact {...mockProps} />)
expect(
wrapper.find(GroupGoalNotification).first().prop('dateStarted')
).toEqual(null)
expect(wrapper.find(GroupImpactSidebar).prop('dateExpires')).toEqual(
undefined
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { shopLandingURL } from 'src/utils/urls'
import { windowOpenTop } from 'src/utils/navigation'
import SearchIcon from '@material-ui/icons/Search'
import TabIcon from '@material-ui/icons/Tab'
import GroupImpactLeaderboard from '../GroupImpactLeaderboard'
import Countdown from 'react-countdown'
import GroupImpactLeaderboard from '../GroupImpactLeaderboard'

jest.mock('ga-gtag')
jest.mock('src/utils/navigation')
Expand Down Expand Up @@ -502,7 +502,9 @@ describe('GroupImpactSidebar component', () => {
}
const wrapper = shallow(<GroupImpactSidebar {...mockProps} />)
expect(wrapper.find(Countdown).exists()).toEqual(true)
expect(wrapper.find(Countdown).prop('dateExpires')).toEqual(mockProps.dateExpires)
expect(wrapper.find(Countdown).prop('dateExpires')).toEqual(
mockProps.dateExpires
)
expect(wrapper.find(Typography).first().text()).toEqual('WEEKLY GROUP GOAL')
})

Expand Down

0 comments on commit 0edbc5f

Please sign in to comment.