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

adds cause id to local storage and adds tests to team seas #194

Merged
merged 3 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"prettier": "^2.1.2",
"react-test-renderer": "^16.14.0",
"storybook-addon-gatsby": "^0.0.2",
"tab-e2e": "^2.0.1",
"tab-e2e": "^2.0.2",
"webpack": "^5.57.1"
},
"jest": {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/__tests__/cats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('cats page', () => {
expect(wrapper.find(getTestIdSelector('mission-text')).exists()).toBe(true)
})

it('the InstallButton onBeforeInstall sets the "Tab V4 enabled" flag in local storage', () => {
it('the InstallButton onBeforeInstall sets the "Tab V4 enabled" flag in local storage and the cause id', () => {
const CatsPageWithTheme = require('../cats').default
const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
Expand All @@ -275,6 +275,10 @@ describe('cats page', () => {
'tab.newUser.isTabV4Enabled',
'true'
)
expect(localStorageMgr.setItem).toHaveBeenCalledWith(
'tab.newUser.causeId',
'7f8476b9-f83f-47ac-8173-4a1c2ec3dc29'
)
})

it('the InstallButton onUnsupportedBrowserInstallClick shows unsupported browser model', async () => {
Expand Down
143 changes: 143 additions & 0 deletions src/pages/__tests__/teamseas.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* eslint-env jest */

import React from 'react'
import { shallow, mount } from 'enzyme'
import localStorageMgr from 'src/utils/local-storage'
import { getTestIdSelector } from 'src/utils/test-utils'
jest.mock('src/utils/local-storage')
jest.mock('src/utils/redirect')
jest.mock('src/utils/location')
jest.mock('src/utils/navigation')
const getMockProps = () => ({
location: {
pathname: '/',
},
pageContext: {},
})

afterEach(() => {
jest.clearAllMocks()
localStorageMgr.clear()
})

describe('teamseas page', () => {
it('renders without error', () => {
const SeasPageWithTheme = require('../teamseas').default
shallow(<SeasPageWithTheme {...getMockProps()} />)
})

it('stores the referrer ID in local storage when it is a vanity URL', () => {
const SeasPageWithTheme = require('../teamseas').default

// Gatsby will pass a referrer in the pageContext prop if it's
// a page created for a vanity referrer URL.
const mockProps = getMockProps()
mockProps.pageContext = { referrer: { id: 123 } }
mount(<SeasPageWithTheme {...mockProps} />)
expect(localStorageMgr.setItem).toHaveBeenCalledWith(
'tab.referralData.referringChannel',
123
)
expect(localStorageMgr.setItem).toHaveBeenCalledTimes(1)
})

it('does not store a referrer ID in local storage when it is not a vanity URL', () => {
const SeasPageWithTheme = require('../teamseas').default
const mockProps = getMockProps()
mockProps.pageContext = {}
mount(<SeasPageWithTheme {...mockProps} />)
expect(localStorageMgr.setItem).not.toHaveBeenCalled()
})

it('does not show referral copy when it is not a vanity URL', () => {
const SeasPageWithTheme = require('../teamseas').default
const mockProps = getMockProps()
mockProps.pageContext = {}
const wrapper = mount(<SeasPageWithTheme {...mockProps} />)
expect(wrapper.find(getTestIdSelector('referral-text')).exists()).toBe(
false
)
})

it('stores the referrer ID in local storage when it is included as a URL parameter', () => {
const SeasPageWithTheme = require('../teamseas').default

const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
getUrlParameterValue.mockImplementation((param) => {
switch (param) {
case 'r':
return '234'
default:
return null
}
})

mount(<SeasPageWithTheme {...getMockProps()} />)
expect(localStorageMgr.setItem).toHaveBeenCalledWith(
'tab.referralData.referringChannel',
234
)
expect(localStorageMgr.setItem).toHaveBeenCalledTimes(1)
})

it('does not store a referrer ID in local storage when the referrer ID is not in the URL params', () => {
const SeasPageWithTheme = require('../teamseas').default

const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
getUrlParameterValue.mockReturnValue(null)

mount(<SeasPageWithTheme {...getMockProps()} />)
expect(localStorageMgr.setItem).not.toHaveBeenCalled()
})

it('does not store a referrer ID in local storage when the URL param referrer ID value is not an integer', () => {
const SeasPageWithTheme = require('../teamseas').default

const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
getUrlParameterValue.mockImplementation((param) => {
switch (param) {
case 'r':
return 'hello'
default:
return null
}
})

mount(<SeasPageWithTheme {...getMockProps()} />)
expect(localStorageMgr.setItem).not.toHaveBeenCalled()
})

it('stores the referring user in local storage when it is included as a URL parameter', () => {
const SeasPageWithTheme = require('../teamseas').default
const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
getUrlParameterValue.mockImplementation((param) => {
switch (param) {
case 'u':
return 'bobert'
default:
return null
}
})

mount(<SeasPageWithTheme {...getMockProps()} />)
expect(localStorageMgr.setItem).toHaveBeenCalledWith(
'tab.referralData.referringUser',
'bobert'
)
expect(localStorageMgr.setItem).toHaveBeenCalledTimes(1)
})

it('does not store a referrer ID in local storage when the referrer ID is not in the URL params', () => {
const SeasPageWithTheme = require('../teamseas').default
const getUrlParameterValue =
require('src/utils/location').getUrlParameterValue
getUrlParameterValue.mockReturnValue(null)

mount(<SeasPageWithTheme {...getMockProps()} />)
expect(localStorageMgr.setItem).not.toHaveBeenCalled()
})
})
10 changes: 10 additions & 0 deletions src/pages/cats.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ import {
STORAGE_REFERRAL_DATA_REFERRING_USER,
STORAGE_NEW_USER_IS_TAB_V4_BETA,
STORAGE_REFERRAL_DATA_MISSION_ID,
STORAGE_CATS_CAUSE_ID,
STORAGE_NEW_USER_CAUSE_ID,
} from 'src/utils/constants'
import { getUrlParameterValue } from 'src/utils/location'
import Divider from '@material-ui/core/Divider'
Expand Down Expand Up @@ -221,6 +223,10 @@ const Cats = ({ pageContext, location }) => {
classes={{ contained: cx.mainInstallButton }}
onBeforeInstall={() => {
localStorageMgr.setItem(STORAGE_NEW_USER_IS_TAB_V4_BETA, 'true')
localStorageMgr.setItem(
STORAGE_NEW_USER_CAUSE_ID,
STORAGE_CATS_CAUSE_ID
)
}}
onUnsupportedBrowserInstallClick={() => {
setShowUnsupportedBrowserMessage(true)
Expand Down Expand Up @@ -269,6 +275,10 @@ const Cats = ({ pageContext, location }) => {
<InstallButton
onBeforeInstall={() => {
localStorageMgr.setItem(STORAGE_NEW_USER_IS_TAB_V4_BETA, 'true')
localStorageMgr.setItem(
STORAGE_NEW_USER_CAUSE_ID,
STORAGE_CATS_CAUSE_ID
)
}}
classes={{ contained: cx.MuiButtonContained }}
onUnsupportedBrowserInstallClick={() => {
Expand Down
9 changes: 9 additions & 0 deletions src/pages/teamseas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import seaImg from 'src/img/seas/ocean.jpg'
import {
STORAGE_REFERRAL_DATA_REFERRING_CHANNEL,
STORAGE_REFERRAL_DATA_REFERRING_USER,
STORAGE_NEW_USER_IS_TAB_V4_BETA,
STORAGE_SEAS_CAUSE_ID,
STORAGE_NEW_USER_CAUSE_ID,
} from 'src/utils/constants'
import Link from 'src/components/Link'
import Countdown from 'react-countdown'
Expand Down Expand Up @@ -116,6 +119,12 @@ const Seas = ({ pageContext, location }) => {
}
}, [])

// function to be used in install button
// eslint-disable-next-line no-unused-vars
const onBeforeInstall = () => {
localStorageMgr.setItem(STORAGE_NEW_USER_IS_TAB_V4_BETA, 'true')
localStorageMgr.setItem(STORAGE_NEW_USER_CAUSE_ID, STORAGE_SEAS_CAUSE_ID)
}
const absolutePageURL = getAbsoluteURL(location.pathname)
return (
<div>
Expand Down
3 changes: 3 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ export const SEARCH_STORAGE_REFERRAL_DATA_REFERRING_USER =
'search.referralData.referringUser'
export const SEARCH_STORAGE_REFERRAL_DATA_REFERRING_CHANNEL =
'search.referralData.referringChannel'
export const STORAGE_NEW_USER_CAUSE_ID = 'tab.newUser.causeId'
export const STORAGE_CATS_CAUSE_ID = '7f8476b9-f83f-47ac-8173-4a1c2ec3dc29'
export const STORAGE_SEAS_CAUSE_ID = 'c04b544f-5e6b-4e10-b783-05834e5d087d'
Loading