browser.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { checkBrowserCompatibility } from './browser';
  2. const setUserAgentString = (userAgentString: string) => {
  3. Object.defineProperty(window.navigator, 'userAgent', {
  4. value: userAgentString,
  5. configurable: true,
  6. });
  7. };
  8. const setVendor = (vendor: string) => {
  9. Object.defineProperty(window.navigator, 'vendor', {
  10. value: vendor,
  11. configurable: true,
  12. });
  13. };
  14. describe('browser', () => {
  15. describe('check compatibility', () => {
  16. describe('Chrome', () => {
  17. it('should be true for chrome version 77', () => {
  18. setUserAgentString(
  19. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'
  20. );
  21. setVendor('Google Inc.');
  22. expect(checkBrowserCompatibility()).toBeTruthy();
  23. });
  24. it('should be false for chrome version <= 54', () => {
  25. setUserAgentString(
  26. 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'
  27. );
  28. setVendor('Google Inc.');
  29. expect(checkBrowserCompatibility()).toBeFalsy();
  30. });
  31. });
  32. describe('IE', () => {
  33. it('should be false for IE 11', () => {
  34. setUserAgentString('Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko');
  35. setVendor('Microsoft');
  36. expect(checkBrowserCompatibility()).toBeFalsy();
  37. });
  38. });
  39. describe('Edge', () => {
  40. it('should be false for Edge <= 16', () => {
  41. setUserAgentString(
  42. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
  43. );
  44. setVendor('Microsoft');
  45. expect(checkBrowserCompatibility()).toBeFalsy();
  46. });
  47. it('should be true for Edge version 44', () => {
  48. setUserAgentString(
  49. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 Edg/44.18362.387.0'
  50. );
  51. setVendor('Microsoft');
  52. expect(checkBrowserCompatibility()).toBeTruthy();
  53. });
  54. });
  55. describe('Firefox', () => {
  56. it('should be true for version 69', () => {
  57. setUserAgentString('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/69.0');
  58. setVendor('Firefox');
  59. expect(checkBrowserCompatibility()).toBeTruthy();
  60. });
  61. });
  62. });
  63. });