Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
Signed-off-by: aryangupta701 <garyan447@gmail.com>
  • Loading branch information
aryangupta701 committed Jul 21, 2023
1 parent b97b4df commit e4efc71
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
11 changes: 8 additions & 3 deletions source/Background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,14 @@ async function handleMessage(
zestScript.reset();
} else if (request.type === 'stopRecording') {
if (zestScript.getZestStatementCount() > 0) {
const stmt = new ZestStatementWindowClose(0);
const data = zestScript.addStatement(stmt.toJSON());
sendZestScriptToZAP(data, zapkey, zapurl);
const {zapclosewindowhandle} = await Browser.storage.sync.get({
zapclosewindowhandle: false,
});
if (zapclosewindowhandle) {
const stmt = new ZestStatementWindowClose(0);
const data = zestScript.addStatement(stmt.toJSON());
sendZestScriptToZAP(data, zapkey, zapurl);
}
}
}
return true;
Expand Down
5 changes: 0 additions & 5 deletions source/ContentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ Browser.runtime.onMessage.addListener(
recordUserInteractions();
} else if (message.type === 'zapStopRecording') {
stopRecordingUserInteractions();
Browser.storage.sync.get({zapclosewindowhandle: false}).then((items) => {
if (items.zapclosewindowhandle) {
Browser.runtime.sendMessage({type: 'stopRecording'});
}
});
}
}
);
Expand Down
1 change: 1 addition & 0 deletions source/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function closePopup(): void {
function stopRecording(): void {
console.log('Recording stopped ...');
sendMessageToContentScript('zapStopRecording');
Browser.runtime.sendMessage({type: 'stopRecording'});
Browser.storage.sync.set({
zaprecordingactive: false,
});
Expand Down
45 changes: 45 additions & 0 deletions test/ContentScript/integrationTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,51 @@ function integrationTests(
// Then
expect(actualOutcome).toBe('recordedScript.zst');
});

test('Should send window handle close script when enabled', async () => {
server = getFakeZapServer(actualData, _JSONPORT);
const context = await driver.getContext(_JSONPORT, true);
await driver.setEnable(false);
const page = await context.newPage();
await page.goto(await driver.getPopupURL());
await page.check('#window-close-input');
await page.goto(
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
);
await page.fill('#input-1', 'testinput');
await page.fill('#input-2', '2023-06-15');
await page.goto(await driver.getPopupURL());
await page.click('#record-btn');
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
await page.close();
// Then
const expectedData =
'["{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}","{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"value\\":\\"2023-06-15\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-2\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}","{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":3,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
});

test('Should configure downloaded script name', async () => {
// Given
server = getFakeZapServer(actualData, _JSONPORT);
const context = await driver.getContext(_JSONPORT, true);
await driver.setEnable(false);
const page = await context.newPage();
await page.goto(await driver.getPopupURL());
await page.fill('#script-name-input', 'test-name');
let actualOutcome = '';
page.on('download', async (download) => {
actualOutcome = download.suggestedFilename();
await download.delete();
});
// When
await page.click('#save-script');
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
await page.close();
// Then
expect(actualOutcome).toBe('test-name.zst');
});
}
}

Expand Down

0 comments on commit e4efc71

Please sign in to comment.