-
-
Notifications
You must be signed in to change notification settings - Fork 54
Handle signup flow if initiated from Tidepool Mobile (MOBILE-696) #2037
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
Open
gniezen
wants to merge
7
commits into
develop
Choose a base branch
from
mobile-signup-scheme
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1bc1d41
handle signup flow if iniated from tidepool mobile
gniezen c43b7c2
v1.101.0-mobile-custom-scheme.1
gniezen da864de
show mobile app link for logged-in patients on browser warning screen
gniezen d4804eb
v1.101.0-mobile-custom-scheme.2
gniezen 5f29317
address automated review feedback
gniezen e3f6e0b
add more tests
gniezen be5da6d
v1.101.0-mobile-custom-scheme.3
gniezen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
__tests__/unit/app/components/mobileapplink/MobileAppLink.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* global jest */ | ||
| /* global expect */ | ||
| /* global describe */ | ||
| /* global it */ | ||
| /* global beforeEach */ | ||
| /* global afterEach */ | ||
|
|
||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import MobileAppLink, { | ||
| ANDROID_APP_URL, | ||
| APP_STORE_URL, | ||
| IOS_APP_URL, | ||
| PLAY_STORE_URL, | ||
| } from '@app/components/mobileapplink/MobileAppLink'; | ||
| import utils from '@app/core/utils'; | ||
|
|
||
| const OPEN_APP_LABEL = 'Open the Tidepool Mobile app'; | ||
| const STORE_BADGE_LABEL = 'Download Tidepool Mobile'; | ||
|
|
||
| describe('MobileAppLink', () => { | ||
| let getMobilePlatform; | ||
| let trackMetric; | ||
|
|
||
| beforeEach(() => { | ||
| getMobilePlatform = jest.spyOn(utils, 'getMobilePlatform'); | ||
| trackMetric = jest.fn(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| getMobilePlatform.mockRestore(); | ||
| }); | ||
|
|
||
| describe('on a desktop user agent', () => { | ||
| it('should render nothing, since the link cannot work there', () => { | ||
| getMobilePlatform.mockReturnValue(null); | ||
| const { container } = render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('on iOS', () => { | ||
| beforeEach(() => { | ||
| getMobilePlatform.mockReturnValue('ios'); | ||
| }); | ||
|
|
||
| it('should link to the app with the plain custom scheme', () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(screen.getByRole('link', { name: OPEN_APP_LABEL })) | ||
| .toHaveAttribute('href', IOS_APP_URL); | ||
| expect(IOS_APP_URL).toBe('org.tidepool.mobile://signup-complete'); | ||
| }); | ||
|
|
||
| it('should fall back to the App Store listing', () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(screen.getByRole('link', { name: STORE_BADGE_LABEL })) | ||
| .toHaveAttribute('href', APP_STORE_URL); | ||
| }); | ||
|
|
||
| it('should track a metric when the app link is clicked', async () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
| await userEvent.click(screen.getByRole('link', { name: OPEN_APP_LABEL })); | ||
|
|
||
| expect(trackMetric).toHaveBeenCalledWith('Clicked Open Tidepool Mobile App', { platform: 'ios' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('on Android', () => { | ||
| beforeEach(() => { | ||
| getMobilePlatform.mockReturnValue('android'); | ||
| }); | ||
|
|
||
| it('should link to the app with the intent:// scheme, so a missing app falls through to the Play Store', () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(screen.getByRole('link', { name: OPEN_APP_LABEL })) | ||
| .toHaveAttribute('href', ANDROID_APP_URL); | ||
| expect(ANDROID_APP_URL).toBe('intent://signup-complete#Intent;scheme=org.tidepool.mobile;package=io.tidepool.urchin;S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dio.tidepool.urchin;end'); | ||
| }); | ||
|
|
||
| it('should fall back to the Play Store listing', () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(screen.getByRole('link', { name: STORE_BADGE_LABEL })) | ||
| .toHaveAttribute('href', PLAY_STORE_URL); | ||
| }); | ||
|
|
||
| // The visible button must be the anchor itself: nesting a real <button> inside the link is | ||
| // invalid HTML and broke iOS Safari's long-press menu on the link. | ||
| it('should render the app link as a single control, with no button nested inside', () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
|
|
||
| expect(screen.getByRole('link', { name: OPEN_APP_LABEL })).toBeInTheDocument(); | ||
| expect(screen.queryByRole('button')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should track a metric when the app link is clicked', async () => { | ||
| render(<MobileAppLink trackMetric={trackMetric} />); | ||
| await userEvent.click(screen.getByRole('link', { name: OPEN_APP_LABEL })); | ||
|
|
||
| expect(trackMetric).toHaveBeenCalledWith('Clicked Open Tidepool Mobile App', { platform: 'android' }); | ||
| }); | ||
| }); | ||
| }); |
61 changes: 61 additions & 0 deletions
61
__tests__/unit/app/pages/browserwarning/BrowserWarning.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* global expect */ | ||
| /* global describe */ | ||
| /* global it */ | ||
|
|
||
| import { mapStateToProps } from '@app/pages/browserwarning/browserwarning'; | ||
|
|
||
| const makeState = (blip) => ({ blip }); | ||
|
|
||
| describe('BrowserWarning mapStateToProps', () => { | ||
| it('should show the mobile app link for a logged-in patient', () => { | ||
| const state = makeState({ | ||
| isLoggedIn: true, | ||
| loggedInUserId: 'p1', | ||
| allUsersMap: { p1: { userid: 'p1', roles: [] } }, | ||
| }); | ||
|
|
||
| expect(mapStateToProps(state).showMobileAppLink).toBe(true); | ||
| }); | ||
|
|
||
| // Clinicians reach this page from mobile browsers too (requireSupportedBrowserForUserType), and | ||
| // the Tidepool Mobile app is for patients. | ||
| it('should not show the mobile app link for a clinician', () => { | ||
| const state = makeState({ | ||
| isLoggedIn: true, | ||
| loggedInUserId: 'c1', | ||
| allUsersMap: { c1: { userid: 'c1', roles: ['clinician'] } }, | ||
| }); | ||
|
|
||
| expect(mapStateToProps(state).showMobileAppLink).toBe(false); | ||
| }); | ||
|
|
||
| it('should not show the mobile app link for a clinic member without a clinician role', () => { | ||
| const state = makeState({ | ||
| isLoggedIn: true, | ||
| loggedInUserId: 'c2', | ||
| allUsersMap: { c2: { userid: 'c2', roles: [], isClinicMember: true } }, | ||
| }); | ||
|
|
||
| expect(mapStateToProps(state).showMobileAppLink).toBe(false); | ||
| }); | ||
|
|
||
| it('should not show the mobile app link when logged out', () => { | ||
| const state = makeState({ | ||
| isLoggedIn: false, | ||
| loggedInUserId: null, | ||
| allUsersMap: {}, | ||
| }); | ||
|
|
||
| expect(mapStateToProps(state).showMobileAppLink).toBe(false); | ||
| }); | ||
|
|
||
| it('should not show the mobile app link while the user has not loaded yet', () => { | ||
| const state = makeState({ | ||
| isLoggedIn: true, | ||
| loggedInUserId: 'p1', | ||
| allUsersMap: {}, | ||
| }); | ||
|
|
||
| expect(mapStateToProps(state).showMobileAppLink).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { withTranslation } from 'react-i18next'; | ||
| import { Box, Flex, Image, Link } from 'theme-ui'; | ||
|
|
||
| import { Paragraph1 } from '../elements/FontStyles'; | ||
| import utils from '../../core/utils'; | ||
|
|
||
| import AppStoreBadge from './images/appstore-badge.svg'; | ||
| import GooglePlayBadge from './images/google-play-badge.png'; | ||
|
|
||
| export const APP_STORE_URL = 'https://apps.apple.com/us/app/tidepool-mobile/id1026395200'; | ||
| export const PLAY_STORE_URL = 'https://play.google.com/store/apps/details?id=io.tidepool.urchin'; | ||
|
|
||
| // A custom scheme for now. The nicer alternative, an iOS universal link, is postponed to post-MVP | ||
| // because it needs real infrastructure: a dedicated link host (iOS refuses to open universal links | ||
| // pointing at the host of the page they're tapped on) and an associated-domains entitlement in the | ||
| // app, i.e. a mobile release. A verified, working implementation is parked on the | ||
| // universal-link-prototype branch. This link only foregrounds the app — it carries no parameters | ||
| // and the app does no routing on it. | ||
| export const IOS_APP_URL = 'org.tidepool.mobile://signup-complete'; | ||
|
|
||
| // Chrome's intent:// syntax, so that a missing app falls through to the Play Store listing instead | ||
| // of failing silently. iOS has no equivalent fallback — Safari shows an "address is invalid" alert — | ||
| // which is why the store badge sits directly below the button. | ||
| export const ANDROID_APP_URL = [ | ||
| 'intent://signup-complete#Intent', | ||
| 'scheme=org.tidepool.mobile', | ||
| 'package=io.tidepool.urchin', | ||
| `S.browser_fallback_url=${encodeURIComponent(PLAY_STORE_URL)}`, | ||
| 'end', | ||
| ].join(';'); | ||
|
|
||
| const platformConfig = { | ||
| ios: { | ||
| appUrl: IOS_APP_URL, | ||
| storeUrl: APP_STORE_URL, | ||
| badgeImage: AppStoreBadge, | ||
| badgeMetric: 'Clicked App Store Badge', | ||
| }, | ||
| android: { | ||
| appUrl: ANDROID_APP_URL, | ||
| storeUrl: PLAY_STORE_URL, | ||
| badgeImage: GooglePlayBadge, | ||
| badgeMetric: 'Clicked Play Store Badge', | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * Renders a link back to the Tidepool Mobile app, for users who arrived on the web to complete | ||
| * signup and would otherwise be stranded here. Renders nothing outside of iOS and Android, where | ||
| * the link cannot work. | ||
| */ | ||
| export const MobileAppLink = (props) => { | ||
| const { t, trackMetric } = props; | ||
| const platform = utils.getMobilePlatform(); | ||
|
|
||
| if (!platform) return null; | ||
|
|
||
| const { appUrl, storeUrl, badgeImage, badgeMetric } = platformConfig[platform]; | ||
|
|
||
| return ( | ||
| <Flex | ||
| id="mobile-app-link" | ||
| mb={4} | ||
| sx={{ flexDirection: 'column', alignItems: 'center', textAlign: 'center' }} | ||
| > | ||
| {/* A single anchor styled as a primary button — a real <Button> nested inside the Link is | ||
| invalid HTML (interactive inside interactive), and it broke iOS Safari's long-press | ||
| menu on the link. The variant assumes flex centering for its lineHeight: 0, hence the | ||
| overrides. */} | ||
| <Link | ||
| id="mobile-app-link-open" | ||
| href={appUrl} | ||
| onClick={() => trackMetric('Clicked Open Tidepool Mobile App', { platform })} | ||
| sx={{ | ||
| variant: 'buttons.primary', | ||
| display: 'inline-block', | ||
| lineHeight: 'normal', | ||
| fontSize: 2, | ||
| textDecoration: 'none', | ||
| }} | ||
| > | ||
| {t('Open the Tidepool Mobile app')} | ||
| </Link> | ||
|
|
||
| <Paragraph1 mt={3} mb={2} sx={{ fontWeight: 'medium' }}> | ||
| {t('Don\'t have the app yet?')} | ||
| </Paragraph1> | ||
|
|
||
| <Box> | ||
| <Link | ||
| id="mobile-app-link-store" | ||
| href={storeUrl} | ||
| target="_blank" | ||
| rel="noreferrer noopener" | ||
| onClick={() => trackMetric(badgeMetric, { platform })} | ||
| > | ||
| <Image | ||
| src={badgeImage} | ||
| alt={t('Download Tidepool Mobile')} | ||
| sx={{ height: '40px' }} | ||
| /> | ||
| </Link> | ||
| </Box> | ||
| </Flex> | ||
| ); | ||
| }; | ||
|
|
||
| MobileAppLink.propTypes = { | ||
| t: PropTypes.func.isRequired, | ||
| trackMetric: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default withTranslation()(MobileAppLink); | ||
File renamed without changes
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import MobileAppLink from './MobileAppLink'; | ||
|
|
||
| export default MobileAppLink; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.