hughhhh commented on a change in pull request #12772: URL: https://github.com/apache/superset/pull/12772#discussion_r566336839
########## File path: superset-frontend/spec/javascripts/utils/common_spec.jsx ########## @@ -86,4 +87,52 @@ describe('utils/common', () => { expect(applyFormattingToTabularData(originalData)).toEqual(expectedData); }); }); + describe('detectOS', () => { + it('detects Windows as the OS when appVersion includes Win', () => { + const mockNavigator = { + // This is the appVersion returned for Mac, with Win replaced on the initial version + // Using this to test that the OS exists for the check + appVersion: '5.0 (Win; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('Windows'); Review comment: we want to call `detectOS` here instead of the mock ########## File path: superset-frontend/spec/javascripts/utils/common_spec.jsx ########## @@ -86,4 +87,52 @@ describe('utils/common', () => { expect(applyFormattingToTabularData(originalData)).toEqual(expectedData); }); }); + describe('detectOS', () => { + it('detects Windows as the OS when appVersion includes Win', () => { + const mockNavigator = { + // This is the appVersion returned for Mac, with Win replaced on the initial version + // Using this to test that the OS exists for the check + appVersion: '5.0 (Win; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('Windows'); + + expect(mockNavigator.appVersion).toMatch(/Win/); + expect(OSName()).toEqual('Windows'); + }); + it('detects MacOS as the OS when appVersion includes Mac', () => { + const mockNavigator = { + appVersion: '5.0 (Mac; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('MacOS'); Review comment: Same as above ########## File path: superset-frontend/spec/javascripts/utils/common_spec.jsx ########## @@ -86,4 +87,52 @@ describe('utils/common', () => { expect(applyFormattingToTabularData(originalData)).toEqual(expectedData); }); }); + describe('detectOS', () => { + it('detects Windows as the OS when appVersion includes Win', () => { + const mockNavigator = { + // This is the appVersion returned for Mac, with Win replaced on the initial version + // Using this to test that the OS exists for the check + appVersion: '5.0 (Win; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('Windows'); + + expect(mockNavigator.appVersion).toMatch(/Win/); + expect(OSName()).toEqual('Windows'); + }); + it('detects MacOS as the OS when appVersion includes Mac', () => { + const mockNavigator = { + appVersion: '5.0 (Mac; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('MacOS'); + + expect(mockNavigator.appVersion).toMatch(/Mac/); + expect(OSName()).toEqual('MacOS'); + }); + it('detects UNIX as the OS when appVersion includes X11', () => { + const mockNavigator = { + appVersion: '5.0 (X11; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' + } + global.navigator = mockNavigator; + + const OSName = jest.fn().mockReturnValue('UNIX'); Review comment: same as above ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org