Skip to content

Commit

Permalink
feat: added test case
Browse files Browse the repository at this point in the history
fix: changed response.data -> response.body.data
  • Loading branch information
this-is-shivamsingh committed Jan 29, 2024
1 parent f6b0582 commit 766549e
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 205 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
try {
if (utils.percy?.type === 'automate') {
const percyOnAutomateResponse = await percyOnAutomate(driver, name, options);
return percyOnAutomateResponse.data;
return percyOnAutomateResponse?.body?.data;
}
const provider = ProviderResolver.resolve(driver);
const response = await provider.screenshot(name, {
Expand All @@ -107,7 +107,7 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
sync
});
log.debug(`[${name}] -> end`);
return response.data;
return response?.body?.data;
} catch (e) {
log.error(`[${name}] failed to take screenshot`);
log.debug(`[${name}] ${e}, \n ${e.stack}`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@percy/appium-app",
"description": "Appium client library for visual testing with Percy",
"version": "2.0.3",
"version": "2.0.4",
"license": "MIT",
"author": "Perceptual Inc.",
"repository": {
Expand Down
33 changes: 20 additions & 13 deletions test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,28 @@ describe('percyScreenshot', () => {
expect(response).toEqual(undefined);
});

it('should call POA percyScreenshot with ignoreRegion and considerRegion and sync', async () => {
it('should call POA percyScreenshot with ignoreRegion and considerRegion', async () => {
const element = { value: '123', elementId: '123' };
const element2 = { value: '456', elementId: '456' };
const driver = driverFunc({ enabled: true });
spyOn(percyScreenshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true))
utils.percy.type = 'automate';
const mockresponse = {
success: 'true',
data: 'sync_data'
};
const mockedPostCall = spyOn(percyOnAutomate, 'request').and.callFake(() => mockresponse);
spyOn(percyOnAutomate, 'request').and.callFake(() => {});

await percyScreenshot(driver, 'Screenshot 2', {
ignore_region_appium_elements: [element], consider_region_appium_elements: [element], sync: true
ignore_region_appium_elements: [element], consider_region_appium_elements: [element]
});
expect(mockedPostCall).toHaveBeenCalledWith(jasmine.objectContaining({
expect(percyOnAutomate.request).toHaveBeenCalledWith(jasmine.objectContaining({
sessionId: 'sessionID',
commandExecutorUrl: 'https://localhost/wd/hub',
snapshotName: 'Screenshot 2',
options: {
ignore_region_elements: ['123'],
consider_region_elements: ['123'],
sync: true
consider_region_elements: ['123']
}
}));

const data = await percyScreenshot(driver, 'Screenshot 3', {
await percyScreenshot(driver, 'Screenshot 3', {
ignoreRegionAppiumElements: [element2], considerRegionAppiumElements: [element2]
});
expect(percyOnAutomate.request).toHaveBeenCalledWith(jasmine.objectContaining({
Expand All @@ -293,10 +288,22 @@ describe('percyScreenshot', () => {
consider_region_elements: ['456']
}
}));

expect(data).toEqual(mockresponse.data);
});

it('should return CLI response', async() => {
const mockResponse = {
success: true,
body: { data: { name: 'test_snapshot', some_data: 'some_data', some_obj: { some_obj: 'some_obj' }}}
}
const driver = driverFunc({ enabled: true });
spyOn(percyScreenshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true))
utils.percy.type = 'automate';

spyOn(percyOnAutomate, 'request').and.callFake(() => mockResponse);
const response = await percyScreenshot(driver, 'Screenshot 1', { sync: true })
expect(response).toEqual(mockResponse.body.data)
})

it('should handle error POA', async () => {
const driver = driverFunc({ enabled: true, ignoreErrors: false });
spyOn(percyScreenshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true))
Expand Down
Loading

0 comments on commit 766549e

Please sign in to comment.