-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add browser support validation to the docs
- Loading branch information
1 parent
1543725
commit b4469b3
Showing
8 changed files
with
56 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as browserService from './services/browser.js'; | ||
|
||
browserService.init(); |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import windowService from './window.js'; | ||
|
||
const NO_SUPPORT_MSG = 'This browser may have no support for all the features required to run this website. Please, use Chrome or Firefox.'; | ||
|
||
export const init = () => { | ||
if (!isBrowserAgent('chrome') && !isBrowserAgent('firefox')) window.alert(NO_SUPPORT_MSG); | ||
}; | ||
|
||
function isBrowserAgent(agentName){ | ||
return windowService.getUserAgent().toLowerCase().includes(agentName); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import windowService from './window'; | ||
import * as browserService from './browser'; | ||
|
||
describe('Browser Service', () => { | ||
beforeEach(() => { | ||
window.alert = jest.fn(); | ||
}); | ||
|
||
it('should alert that Safari doesn\'t fully support the docs', () => { | ||
mockUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15'); | ||
browserService.init(); | ||
expect(window.alert).toHaveBeenCalledWith('This browser may have no support for all the features required to run this website. Please, use Chrome or Firefox.'); | ||
}); | ||
|
||
it('should not alert missing support if browser is other than Safari', () => { | ||
mockUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'); | ||
browserService.init(); | ||
expect(window.alert).not.toHaveBeenCalled(); | ||
}); | ||
|
||
function mockUserAgent(userAgent){ | ||
windowService.getUserAgent = jest.fn(() => userAgent); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const _public = {}; | ||
|
||
_public.getUserAgent = () => window.navigator.userAgent; | ||
|
||
export default _public; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import windowService from './window'; | ||
|
||
describe('Window Service', () => { | ||
it('should get user agent', () => { | ||
expect(windowService.getUserAgent()).toEqual(window.navigator.userAgent); | ||
}); | ||
}); |