Skip to content

Commit

Permalink
Merge pull request #357 from gladly-team/kevin/supporting-chip-all-users
Browse files Browse the repository at this point in the history
Show the "Supporting [cause]" chip to all users
  • Loading branch information
kmjennison authored Jun 24, 2022
2 parents 02fea76 + e6a1aa8 commit 4482164
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 83 deletions.
64 changes: 2 additions & 62 deletions src/__tests__/pages/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,77 +1264,17 @@ describe('index.js', () => {
expect(wrapper.find(SearchInput).first().prop('tooltip')).toEqual(false)
})

it('shows a "supporting" chip that links to the "about the cause" page when the feature is enabled', () => {
it('shows a "supporting" chip that links to the "about the cause" page', () => {
expect.assertions(2)
const IndexPage = require('src/pages/index').default
const defaultMockProps = getMockProps()
const mockProps = {
...defaultMockProps,
data: {
...defaultMockProps.data,
user: {
...defaultMockProps.data.user,
features: [
{
featureName: 'supporting-cause-chip',
variation: 'true',
},
],
},
},
}
const mockProps = getMockProps()
useData.mockReturnValue({ data: mockProps.data })
const wrapper = mount(<IndexPage {...mockProps} />)
const elem = wrapper.find(Chip)
expect(elem.prop('label')).toEqual('Supporting: Example Cause')
elem.simulate('click')
expect(goTo).toHaveBeenCalledWith(aboutURL)
})

it('does not show a "supporting" chip when the feature is disabled', () => {
expect.assertions(1)
const IndexPage = require('src/pages/index').default
const defaultMockProps = getMockProps()
const mockProps = {
...defaultMockProps,
data: {
...defaultMockProps.data,
user: {
...defaultMockProps.data.user,
features: [
{
featureName: 'supporting-cause-chip',
variation: 'false',
},
],
},
},
}
useData.mockReturnValue({ data: mockProps.data })
const wrapper = mount(<IndexPage {...mockProps} />)
const elem = wrapper.find(Chip)
expect(elem.exists()).toBe(false)
})

it('does not show a "supporting" chip when the feature is not returned in the list of features', () => {
expect.assertions(1)
const IndexPage = require('src/pages/index').default
const defaultMockProps = getMockProps()
const mockProps = {
...defaultMockProps,
data: {
...defaultMockProps.data,
user: {
...defaultMockProps.data.user,
features: [],
},
},
}
useData.mockReturnValue({ data: mockProps.data })
const wrapper = mount(<IndexPage {...mockProps} />)
const elem = wrapper.find(Chip)
expect(elem.exists()).toBe(false)
})
})

describe('index.js: hardcoded notifications', () => {
Expand Down
30 changes: 9 additions & 21 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ if (isClientSide()) {
loadAds()
}

const SUPPORTING_CAUSE_CHIP_FEATURE = 'supporting-cause-chip'

const getRelayQuery = async ({ AuthUser }) => {
// If the user is not authenticated, don't try to fetch data
// for this page. We won't render the page until data exists.
Expand Down Expand Up @@ -619,14 +617,6 @@ const Index = ({ data: fallbackData }) => {
setJustFinishedIntroFlow(true)
}
const showIntro = !get(user, 'hasViewedIntroFlow') && !justFinishedIntroFlow

const showSupportingCauseChip =
(
features.find(
(feature) => feature.featureName === SUPPORTING_CAUSE_CHIP_FEATURE
) || {}
).variation === 'true' || false

return (
<div className={classes.pageContainer} data-test-id="new-tab-page">
{showIntro ? (
Expand Down Expand Up @@ -827,17 +817,15 @@ const Index = ({ data: fallbackData }) => {
color={enableBackgroundImages ? 'white' : null}
className={classes.logo}
/>
{showSupportingCauseChip && (
<Chip
label={`Supporting: ${causeName}`}
className={classes.supportingChip}
color="primary"
size="small"
onClick={() => {
goTo(aboutURL)
}}
/>
)}
<Chip
label={`Supporting: ${causeName}`}
className={classes.supportingChip}
color="primary"
size="small"
onClick={() => {
goTo(aboutURL)
}}
/>
<SearchInputContainer
userId={userId}
className={classes.searchBar}
Expand Down

1 comment on commit 4482164

@vercel
Copy link

@vercel vercel bot commented on 4482164 Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.