Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Jun 21, 2019
1 parent 67767fe commit 4b93f2a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"fetch": 2500,
"navigation": 10000,
"postActivity": 30000,
"scrollToBottom": 1000,
"test": 60000
}
}
36 changes: 36 additions & 0 deletions __tests__/scrollToBottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { By } from 'selenium-webdriver';

import { imageSnapshotOptions, timeouts } from './constants.json';

import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import scrollToBottomCompleted from './setup/conditions/scrollToBottomCompleted';
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed';
import uiConnected from './setup/conditions/uiConnected';

// selenium-webdriver API doc:
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html

jest.setTimeout(timeouts.test);

test('should stick to bottom if submitting an Adaptive Card while suggested actions is open', async () => {
const { driver, pageObjects } = await setupWebDriver();

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaSendBox('card inputs', { waitForSend: true });
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

await pageObjects.sendMessageViaSendBox('suggested-actions', { waitForSend: true });
await driver.wait(suggestedActionsShowed(), timeouts.directLine);
await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom);

const submitButton = await driver.findElement(By.css('button.ac-pushButton:nth-of-type(2)'));

await submitButton.click();
await driver.wait(minNumActivitiesShown(5), timeouts.directLine);
await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom);

const base64PNG = await driver.takeScreenshot();

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
});
28 changes: 28 additions & 0 deletions __tests__/setup/conditions/scrollToBottomCompleted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Condition } from 'selenium-webdriver';

import { timeouts } from '../../constants.json';

export default function scrollToBottomCompleted() {
return new Condition('for UI to scroll to bottom', async driver => {
const done = await driver.executeAsyncScript((timeoutInMS, callback) => {
const scrollable = document.querySelector('[role="log"] > *');

// If we do not receive any "scroll" event at all, probably we are at the bottom.
const defaultTimeout = setTimeout(() => callback(true), timeoutInMS);
let timeout;
const handleScroll = () => {
clearTimeout(defaultTimeout);
clearTimeout(timeout);

timeout = setTimeout(() => {
scrollable.removeEventListener('scroll', handleScroll);
callback(true);
}, 200);
};

scrollable.addEventListener('scroll', handleScroll);
}, timeouts.scrollToBottom);

return done;
});
}
2 changes: 1 addition & 1 deletion __tests__/setup/pageObjects/sendMessageViaSendBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { timeouts } from '../../constants.json';
import allOutgoingActivitiesSent from '../conditions/allOutgoingActivitiesSent';

export default async function sendMessageViaSendBox(driver, text, { waitForSend = true }) {
const input = await driver.findElement(By.css('input[type="text"]'));
const input = await driver.findElement(By.css('[role="form"] > * > form > input[type="text"]'));

await input.sendKeys(text, Key.RETURN);

Expand Down

0 comments on commit 4b93f2a

Please sign in to comment.