-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugins): improve user agent selector
- Loading branch information
1 parent
ad88883
commit cd4b6af
Showing
5 changed files
with
55 additions
and
12 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
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
28 changes: 28 additions & 0 deletions
28
plugins/default-browser-emulator/test/selectUserAgentOptions.test.ts
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,28 @@ | ||
import selectUserAgentOption from '../lib/helpers/selectUserAgentOption'; | ||
import DataLoader from '../lib/DataLoader'; | ||
|
||
const dataLoader = new DataLoader(`${__dirname}/..`); | ||
|
||
test('should support choosing a specific useragent', async () => { | ||
const options = selectUserAgentOption( | ||
'~ chrome >= 88 && chrome < 89', | ||
dataLoader.userAgentOptions, | ||
); | ||
expect(options.browserVersion.major).toBe('88'); | ||
}); | ||
|
||
test('should support choosing a specific OS', async () => { | ||
const options = selectUserAgentOption('~ mac & chrome >= 88', dataLoader.userAgentOptions); | ||
expect(parseInt(options.browserVersion.major, 10)).toBeGreaterThanOrEqual(88); | ||
expect(options.operatingSystemName).toBe('mac-os'); | ||
}); | ||
|
||
test('should throw an error for a non-installed pattern', async () => { | ||
try { | ||
expect( | ||
selectUserAgentOption('~ mac & chrome >= 500000', dataLoader.userAgentOptions), | ||
).not.toBeTruthy(); | ||
} catch (err) { | ||
expect(err.message).toMatch('No installed UserAgent'); | ||
} | ||
}); |