-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
[WEB-3418] - Enable Safari on Mobile [DON'T MERGE] #1513
Open
henry-tp
wants to merge
10
commits into
develop
Choose a base branch
from
WEB-3418-mobile-safari
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1533a3f
WEB-3418 enable safari iOS devices
henry-tp de170eb
WEB-3418 explicitly enable CriOS
henry-tp cc1418e
WEB-3418 enable strings containing ipad or iphone in isMobile() check
henry-tp a45e049
WEB-3418 add tests for browser check
henry-tp c8291b0
WEB-3418 tests for isMobile
henry-tp be69dee
Merge branch 'develop' into WEB-3418-mobile-safari
henry-tp d5a5fac
WEB-3418 reset userAgent after tests are done running
henry-tp 0d2edf4
Merge branch 'WEB-3418-mobile-safari' of github.com:tidepool-org/blip…
henry-tp fbd5073
Merge branch 'develop' into WEB-3418-mobile-safari
henry-tp d168c12
Merge branch 'develop' into WEB-3418-mobile-safari
henry-tp 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
This file contains 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 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 |
---|---|---|
|
@@ -12,7 +12,8 @@ import appContext from '../../app/bootstrap'; | |
|
||
describe('appContext', () => { | ||
before(() => { | ||
Object.defineProperty(window.navigator, 'userAgent', { value: 'Mozilla/5.0 .. truncated .. Chrome/131.0.0.0' }); | ||
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'; | ||
Object.defineProperty(window.navigator, 'userAgent', { value: userAgent, configurable: true }); | ||
|
||
appContext.api = { | ||
metrics: { | ||
|
@@ -42,12 +43,12 @@ describe('appContext', () => { | |
[loggedInUserId]: { username: '[email protected]', roles: ['clinician'] }, | ||
}; | ||
|
||
appContext.store.getState.returns({ | ||
appContext.store.getState.returns({ | ||
blip: { | ||
selectedClinicId, | ||
loggedInUserId, | ||
allUsersMap, | ||
}, | ||
}, | ||
}); | ||
|
||
appContext.trackMetric('someMetric2'); | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
/* global it */ | ||
/* global context */ | ||
/* global sinon */ | ||
/* global after */ | ||
/* global afterEach */ | ||
/* global assert */ | ||
|
||
|
@@ -14,6 +15,11 @@ import releases from '../../fixtures/githubreleasefixture'; | |
const expect = chai.expect; | ||
|
||
describe('utils', () => { | ||
after(() => { | ||
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'; | ||
Object.defineProperty(window.navigator, 'userAgent', { value: userAgent, configurable: true }); | ||
}); | ||
|
||
describe('capitalize', () => { | ||
it('should return a capitalized string', () => { | ||
expect(utils.capitalize('lower')).to.equal('Lower'); | ||
|
@@ -72,6 +78,98 @@ describe('utils', () => { | |
}); | ||
}); | ||
|
||
const USER_AGENTS = { | ||
chromeWin: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36', | ||
chromeMac: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36', | ||
chromeIPad: 'Mozilla/5.0 (iPad; CPU OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/133.0.6943.33 Mobile/15E148 Safari/604.1', | ||
chromeIPhone: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/133.0.6943.33 Mobile/15E148 Safari/604.1', | ||
chromeAndroid: 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.49 Mobile Safari/537.36', | ||
|
||
firefoxWin: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0', | ||
firefoxMac: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:135.0) Gecko/20100101 Firefox/135.0', | ||
firefoxIPhone: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/135.0 Mobile/15E148 Safari/605.1.15', | ||
firefoxAndroid: 'Mozilla/5.0 (Android 15; Mobile; rv:135.0) Gecko/135.0 Firefox/135.0', | ||
|
||
edgeWin: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/131.0.2903.86', | ||
edgeMac: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/131.0.2903.86', | ||
edgeAndroid: 'Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.49 Mobile Safari/537.36 EdgA/131.0.2903.87', | ||
edgeIPhone: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 EdgiOS/131.2903.92 Mobile/15E148 Safari/605.1.15', | ||
|
||
safariMac: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15', | ||
safariIPhone: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1', | ||
safariIPad: 'Mozilla/5.0 (iPad; CPU OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1', | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the value / longevity of these tests given that they capture only a specific device. But I feel like we should have something. |
||
|
||
describe('isSupportedBrowser', () => { | ||
it('returns true for only supported devices', () => { | ||
_.each(Object.values(USER_AGENTS), userAgent => { | ||
Object.defineProperty(window.navigator, 'userAgent', { value: userAgent, configurable: true }); | ||
|
||
switch(userAgent) { | ||
case USER_AGENTS.chromeWin: | ||
case USER_AGENTS.chromeMac: | ||
case USER_AGENTS.chromeIPad: | ||
case USER_AGENTS.chromeIPhone: | ||
case USER_AGENTS.chromeAndroid: | ||
case USER_AGENTS.edgeWin: | ||
case USER_AGENTS.edgeMac: | ||
case USER_AGENTS.edgeAndroid: | ||
case USER_AGENTS.edgeIPhone: | ||
case USER_AGENTS.safariIPhone: | ||
case USER_AGENTS.safariIPad: | ||
expect(utils.isSupportedBrowser()).to.be.true; | ||
break; | ||
|
||
case USER_AGENTS.firefoxWin: | ||
case USER_AGENTS.firefoxMac: | ||
case USER_AGENTS.firefoxIPhone: | ||
case USER_AGENTS.firefoxAndroid: | ||
case USER_AGENTS.safariMac: | ||
expect(utils.isSupportedBrowser()).to.be.false; | ||
break; | ||
|
||
default: | ||
throw new Error('Each string in USER_AGENTS should have an expected result in the test'); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('isMobile', () => { | ||
it('returns true for only supported devices', () => { | ||
_.each(Object.values(USER_AGENTS), userAgent => { | ||
Object.defineProperty(window.navigator, 'userAgent', { value: userAgent, configurable: true }); | ||
|
||
switch(userAgent) { | ||
case USER_AGENTS.chromeIPad: | ||
case USER_AGENTS.chromeIPhone: | ||
case USER_AGENTS.chromeAndroid: | ||
case USER_AGENTS.edgeAndroid: | ||
case USER_AGENTS.edgeIPhone: | ||
case USER_AGENTS.safariIPhone: | ||
case USER_AGENTS.safariIPad: | ||
case USER_AGENTS.firefoxIPhone: | ||
case USER_AGENTS.firefoxAndroid: | ||
expect(utils.isMobile()).to.be.true; | ||
break; | ||
|
||
case USER_AGENTS.chromeWin: | ||
case USER_AGENTS.chromeMac: | ||
case USER_AGENTS.edgeWin: | ||
case USER_AGENTS.edgeMac: | ||
case USER_AGENTS.firefoxWin: | ||
case USER_AGENTS.firefoxMac: | ||
case USER_AGENTS.safariMac: | ||
expect(utils.isMobile()).to.be.false; | ||
break; | ||
|
||
default: | ||
throw new Error('Each string in USER_AGENTS should have an expected result in the test'); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('validateEmail', () => { | ||
it('should validate [email protected] as email', () => { | ||
expect(utils.validateEmail('[email protected]')).to.be.true; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They key change here is the addition of
configurable: true
. I found that ifconfigurable
is not set to true,Object.defineProperty()
cannot be called again withwindow.navigator
, so settingconfigurable: true
allows us to re-define the property.Unfortunately,
defineProperty
is called in one file, the effect seems to bleed into other test files as well, as the test runner is not restarting for every new file. That's why I needed to make an adjustment here.