-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from ulixee/useragent
fix(plugins): improve user agent selector
- Loading branch information
Showing
6 changed files
with
58 additions
and
10 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
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
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
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) { | ||
// eslint-disable-next-line jest/no-try-expect | ||
expect(err.message).toMatch('No installed UserAgent'); | ||
} | ||
}); |