Skip to content

Commit

Permalink
Fixing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rishigupta1599 committed Nov 16, 2023
1 parent 6b279be commit 9b53f4c
Showing 1 changed file with 91 additions and 52 deletions.
143 changes: 91 additions & 52 deletions packages/webdriver-utils/test/providers/automateProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AutomateProvider from '../../src/providers/automateProvider.js';
import DesktopMetaData from '../../src/metadata/desktopMetaData.js';
import Tile from '../../src/util/tile.js';
import MobileMetaData from '../../src/metadata/mobileMetaData.js';
import Cache from '../../src/util/cache.js';

describe('AutomateProvider', () => {
let superScreenshotSpy;
Expand Down Expand Up @@ -208,60 +209,10 @@ describe('AutomateProvider', () => {
});
});

describe('getTiles', () => {
let browserstackExecutorSpy;
let executeScriptSpy;
let percyBuildInfo = {
id: '123',
url: 'https://percy.io/abc/123'
};
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);

beforeEach(async () => {
spyOn(Driver.prototype, 'getCapabilites');
browserstackExecutorSpy = spyOn(AutomateProvider.prototype, 'browserstackExecutor')
.and.returnValue(Promise.resolve({ value: '{"success": true, "result": "{\\"tiles\\":[{\\"sha\\":\\"abc\\",\\"status_bar\\":0,\\"nav_bar\\":156,\\"header_height\\":0,\\"footer_height\\":156,\\"index\\":0},{\\"sha\\":\\"cde\\",\\"status_bar\\":0,\\"nav_bar\\":156,\\"header_height\\":0.0,\\"footer_height\\":156.0,\\"index\\":1}],\\"dom_sha\\":\\"def\\"}"}' }));
executeScriptSpy = spyOn(Driver.prototype, 'executeScript')
.and.returnValue(Promise.resolve(1));
});

it('should return tiles when success', async () => {
await automateProvider.createDriver();
const res = await automateProvider.getTiles(false);
const expectedOutput = {
tiles: [
new Tile({
statusBarHeight: 0,
navBarHeight: 156,
headerHeight: 0,
footerHeight: 156,
fullscreen: false,
sha: 'abc'
}),
new Tile({
statusBarHeight: 0,
navBarHeight: 156,
headerHeight: 0,
footerHeight: 156,
fullscreen: false,
sha: 'cde'
})
],
domInfoSha: 'def',
metadata: {}
};
expect(browserstackExecutorSpy).toHaveBeenCalledTimes(1);
expect(executeScriptSpy).toHaveBeenCalledTimes(1);
expect(Object.keys(res).length).toEqual(3);
expect(res.domInfoSha).toBe('def');
expect(res.tiles.length).toEqual(2);
expect(res.tiles[0]).toBeInstanceOf(Tile);
expect(res.tiles[1]).toBeInstanceOf(Tile);
expect(res).toEqual(expectedOutput);
});

function tilesErrorResponseCheck(automateProvider) {
it('throws error when response is false', async () => {
await automateProvider.createDriver();
let browserstackExecutorSpy = spyOn(AutomateProvider.prototype, 'browserstackExecutor');
browserstackExecutorSpy.and.returnValue(Promise.resolve({ value: '{ "error": "Random Error", "success":false }' }));
await expectAsync(automateProvider.getTiles(false)).toBeRejectedWithError('Failed to get screenshots from Automate.' +
' Check dashboard for error.');
Expand All @@ -271,6 +222,94 @@ describe('AutomateProvider', () => {
automateProvider.driver = null;
await expectAsync(automateProvider.getTiles(false)).toBeRejectedWithError('Driver is null, please initialize driver with createDriver().');
});
}

describe('getTiles', () => {
let percyBuildInfo = {
id: '123',
url: 'https://percy.io/abc/123'
};
let browserstackExecutorSpy = null;
let executeScriptSpy;

describe('fullpage', () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', { fullPage: true }, percyBuildInfo);

beforeEach(async () => {
Cache.reset();
spyOn(Driver.prototype, 'getCapabilites');
browserstackExecutorSpy = spyOn(AutomateProvider.prototype, 'browserstackExecutor')
.and.returnValue(Promise.resolve({ value: '{"success": true, "result": "{\\"tiles\\":[{\\"sha\\":\\"abc\\",\\"status_bar\\":0,\\"nav_bar\\":156,\\"header_height\\":0,\\"footer_height\\":156,\\"index\\":0},{\\"sha\\":\\"cde\\",\\"status_bar\\":0,\\"nav_bar\\":156,\\"header_height\\":0.0,\\"footer_height\\":156.0,\\"index\\":1}],\\"dom_sha\\":\\"def\\"}"}' }));
executeScriptSpy = spyOn(Driver.prototype, 'executeScript')
.and.returnValue(Promise.resolve(1));
});

it('should return tiles when success', async () => {
await automateProvider.createDriver();
const res = await automateProvider.getTiles(false);
const expectedOutput = {
tiles: [
new Tile({
statusBarHeight: 0,
navBarHeight: 156,
headerHeight: 0,
footerHeight: 156,
fullscreen: false,
sha: 'abc'
}),
new Tile({
statusBarHeight: 0,
navBarHeight: 156,
headerHeight: 0,
footerHeight: 156,
fullscreen: false,
sha: 'cde'
})
],
domInfoSha: 'def',
metadata: {}
};
expect(browserstackExecutorSpy).toHaveBeenCalledTimes(1);
expect(executeScriptSpy).toHaveBeenCalledTimes(1);
expect(res).toEqual(expectedOutput);
});
tilesErrorResponseCheck(automateProvider);
});

describe('singlepage', () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
beforeEach(async () => {
Cache.reset();
spyOn(Driver.prototype, 'getCapabilites');
browserstackExecutorSpy = spyOn(AutomateProvider.prototype, 'browserstackExecutor')
.and.returnValue(Promise.resolve({ value: '{"success": true, "result": "{\\"tiles\\":[{\\"sha\\":\\"abc\\",\\"status_bar\\":0,\\"nav_bar\\":156,\\"header_height\\":0,\\"footer_height\\":156,\\"index\\":0}],\\"dom_sha\\":\\"def\\"}"}' }));
executeScriptSpy = spyOn(Driver.prototype, 'executeScript')
.and.returnValue(Promise.resolve(1));
});

it('should return tiles when success', async () => {
await automateProvider.createDriver();
const res = await automateProvider.getTiles(false);
const expectedOutput = {
tiles: [
new Tile({
statusBarHeight: 0,
navBarHeight: 156,
headerHeight: 0,
footerHeight: 156,
fullscreen: false,
sha: 'abc'
})
],
domInfoSha: 'def',
metadata: {}
};
expect(browserstackExecutorSpy).toHaveBeenCalledTimes(1);
expect(executeScriptSpy).toHaveBeenCalledTimes(1);
expect(res).toEqual(expectedOutput);
});
tilesErrorResponseCheck(automateProvider);
});
});

describe('getTag', () => {
Expand Down

0 comments on commit 9b53f4c

Please sign in to comment.