diff --git a/packages/webdriver-utils/test/providers/genericProvider.test.js b/packages/webdriver-utils/test/providers/genericProvider.test.js index 598e25630..554b65652 100644 --- a/packages/webdriver-utils/test/providers/genericProvider.test.js +++ b/packages/webdriver-utils/test/providers/genericProvider.test.js @@ -138,34 +138,123 @@ describe('GenericProvider', () => { describe('screenshot', () => { let getTagSpy; let getTilesSpy; + let iOSGetTagSpy; + let iOSGetTilesSpy; - beforeEach(() => { - const scrollFactors = { value: [0, 10] }; - getTagSpy = spyOn(GenericProvider.prototype, 'getTag').and.returnValue(Promise.resolve('mock-tag')); - getTilesSpy = spyOn(GenericProvider.prototype, 'getTiles').and.returnValue(Promise.resolve({ tiles: 'mock-tile', domInfoSha: 'mock-dom-sha' })); - spyOn(DesktopMetaData.prototype, 'windowSize') - .and.returnValue(Promise.resolve({ width: 1920, height: 1080 })); - spyOn(Driver.prototype, 'executeScript') - .and.returnValue(scrollFactors); + describe('With Desktop', () => { + let desktopTag; + let desktopTiles; + beforeEach(() => { + desktopTag = { + name: 'Windows_11_Chrome_103', + osName: 'Windows', + osVersion: '11', + width: 1000, + height: 1000, + orientation: 'landscape', + browserName: 'chrome', + browserVersion: '103', + resolution: '1980 x 1080' + }; + desktopTiles = { + tiles: [{ + statusBarHeight: 0, + sha: 'abc', + navBarHeight: 0, + headerHeight: 0, + footerHeight: 0, + fullscreen: false + }], + domInfoSha: 'mock-dom-sha' + }; + const scrollFactors = { value: [0, 10] }; + getTagSpy = spyOn(GenericProvider.prototype, 'getTag').and.returnValue(Promise.resolve(desktopTag)); + getTilesSpy = spyOn(GenericProvider.prototype, 'getTiles').and.returnValue(Promise.resolve(desktopTiles)); + spyOn(DesktopMetaData.prototype, 'windowSize') + .and.returnValue(Promise.resolve({ width: 1920, height: 1080 })); + spyOn(Driver.prototype, 'executeScript') + .and.returnValue(scrollFactors); + }); + + it('calls correct funcs', async () => { + genericProvider = new GenericProvider('123', 'http:executorUrl', { platform: 'win' }, {}, 'local-poc-poa', 'staging-poc-poa', {}); + await genericProvider.createDriver(); + let res = await genericProvider.screenshot('mock-name', {}); + expect(getTagSpy).toHaveBeenCalledTimes(1); + expect(genericProvider.pageYShiftFactor).toEqual(-10); + expect(genericProvider.pageXShiftFactor).toEqual(-0); + expect(getTilesSpy).toHaveBeenCalledOnceWith(0, 0, false); + expect(res).toEqual({ + name: 'mock-name', + tag: desktopTag, + tiles: desktopTiles.tiles, + externalDebugUrl: 'https://localhost/v1', + environmentInfo: 'staging-poc-poa', + ignoredElementsData: { ignoreElementsData: [] }, + consideredElementsData: { considerElementsData: [] }, + clientInfo: 'local-poc-poa', + domInfoSha: 'mock-dom-sha', + metadata: null + }); + }); }); - it('calls correct funcs', async () => { - genericProvider = new GenericProvider('123', 'http:executorUrl', { platform: 'win' }, {}, 'local-poc-poa', 'staging-poc-poa', {}); - await genericProvider.createDriver(); - let res = await genericProvider.screenshot('mock-name', {}); - expect(getTagSpy).toHaveBeenCalledTimes(1); - expect(getTilesSpy).toHaveBeenCalledOnceWith(0, 0, false); - expect(res).toEqual({ - name: 'mock-name', - tag: 'mock-tag', - tiles: 'mock-tile', - externalDebugUrl: 'https://localhost/v1', - environmentInfo: 'staging-poc-poa', - ignoredElementsData: { ignoreElementsData: [] }, - consideredElementsData: { considerElementsData: [] }, - clientInfo: 'local-poc-poa', - domInfoSha: 'mock-dom-sha', - metadata: null + describe('With Mobile iOS', () => { + let iosTag; + let iosTiles; + + beforeEach(() => { + const scrollFactors = { value: [0, 10] }; + iosTag = { + name: 'iPhone 11 Pro', + osName: 'iOS', + osVersion: '15', + width: 1000, + height: 1000, + orientation: 'potrait', + browserName: 'safari', + browserVersion: '15', + resolution: '1980 x 1080' + }; + iosTiles = { + tiles: [{ + statusBarHeight: 132, + sha: 'abc', + navBarHeight: 0, + headerHeight: 0, + footerHeight: 0, + fullscreen: false + }], + domInfoSha: 'mock-dom-sha' + }; + iOSGetTagSpy = spyOn(GenericProvider.prototype, 'getTag').and.returnValue(Promise.resolve(iosTag)); + iOSGetTilesSpy = spyOn(GenericProvider.prototype, 'getTiles').and.returnValue(Promise.resolve(iosTiles)); + spyOn(DesktopMetaData.prototype, 'windowSize') + .and.returnValue(Promise.resolve({ width: 1920, height: 1080 })); + spyOn(Driver.prototype, 'executeScript') + .and.returnValue(scrollFactors); + }); + + it('calls correct funcs with iOS', async () => { + genericProvider = new GenericProvider('123', 'http:executorUrl', { platform: 'win' }, {}, 'local-poc-poa', 'staging-poc-poa', {}); + await genericProvider.createDriver(); + let res = await genericProvider.screenshot('mock-name', {}); + expect(iOSGetTagSpy).toHaveBeenCalledTimes(1); + expect(genericProvider.pageYShiftFactor).toEqual(132); + expect(genericProvider.pageXShiftFactor).toEqual(0); + expect(iOSGetTilesSpy).toHaveBeenCalledOnceWith(0, 0, false); + expect(res).toEqual({ + name: 'mock-name', + tag: iosTag, + tiles: iosTiles.tiles, + externalDebugUrl: 'https://localhost/v1', + environmentInfo: 'staging-poc-poa', + ignoredElementsData: { ignoreElementsData: [] }, + consideredElementsData: { considerElementsData: [] }, + clientInfo: 'local-poc-poa', + domInfoSha: 'mock-dom-sha', + metadata: null + }); }); }); });