Skip to content

Commit

Permalink
Add focus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Aug 9, 2019
1 parent 9779355 commit 277f6c1
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
47 changes: 47 additions & 0 deletions __tests__/focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Key } from 'selenium-webdriver';
import { timeouts } from './constants.json';

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

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

jest.setTimeout(timeouts.test);

// Verification of fix of #1971
test('should not focus send box after clicking on send button', async () => {
const { driver, pageObjects } = await setupWebDriver();

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

await pageObjects.setSendBoxText('echo 123');
await pageObjects.clickSendButton();

await expect(pageObjects.hasFocusOnSendBoxTextBox()).resolves.toBeFalsy();
});

// Verification of fix of #1971
test('should not focus send box after clicking on suggested actions', async () => {
const { driver, pageObjects } = await setupWebDriver();

await driver.wait(uiConnected(), timeouts.directLine);
await pageObjects.sendMessageViaSendBox('suggested-actions');

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

await pageObjects.clickSuggestedActionButton(0);

await expect(pageObjects.hasFocusOnSendBoxTextBox()).resolves.toBeFalsy();
});

// Verification of fix of #1971
test('should focus send box after pressing ENTER to send message', async () => {
const { driver, pageObjects } = await setupWebDriver();

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

await pageObjects.setSendBoxText('echo 123', Key.RETURN);

await expect(pageObjects.hasFocusOnSendBoxTextBox()).resolves.toBeTruthy();
});
5 changes: 5 additions & 0 deletions __tests__/setup/pageObjects/clickSendButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import getSendButton from './elements/getSendButton';

export default async function clickSendButton(driver) {
(await getSendButton(driver)).click();
}
7 changes: 7 additions & 0 deletions __tests__/setup/pageObjects/clickSuggestedActionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getSuggestedActionButtons from './elements/getSuggestedActionButtons';

export default async function clickSuggestedActionButton(driver, index) {
const suggestedActions = await getSuggestedActionButtons(driver);

await suggestedActions[index].click();
}
6 changes: 5 additions & 1 deletion __tests__/setup/pageObjects/elements/getSendBoxTextBox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { By } from 'selenium-webdriver';

const CSS_SELECTOR = '[role="form"] > * > form > input[type="text"]';

export default async function getSendBoxTextBox(driver) {
return await driver.findElement(By.css('[role="form"] > * > form > input[type="text"]'));
return await driver.findElement(By.css(CSS_SELECTOR));
}

export { CSS_SELECTOR };
5 changes: 5 additions & 0 deletions __tests__/setup/pageObjects/elements/getSendButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { By } from 'selenium-webdriver';

export default async function getSendButton(driver) {
return await driver.findElement(By.css('[role="form"] button[title="Send"]'));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { By } from 'selenium-webdriver';

export default async function getSuggestedActionButtons(driver) {
return await driver.findElements(By.css('[role="form"] > :nth-child(2) ul > li button'));
}
19 changes: 19 additions & 0 deletions __tests__/setup/pageObjects/hasFocusOnSendBoxTextBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { By } from 'selenium-webdriver';
import getSendBoxTextBox, { CSS_SELECTOR } from './elements/getSendBoxTextBox';

export default async function hasFocusOnSendBoxTextBox(driver) {
// Make sure the send box text box is visible
await getSendBoxTextBox(driver);

try {
await driver.findElement(By.css(CSS_SELECTOR + ':focus'));

return true;
} catch (err) {
if (err.name === 'NoSuchElementError') {
return false;
}

throw err;
}
}
8 changes: 7 additions & 1 deletion __tests__/setup/pageObjects/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import clickMicrophoneButton from './clickMicrophoneButton';
import clickSendButton from './clickSendButton';
import clickSuggestedActionButton from './clickSuggestedActionButton';
import dispatchAction from './dispatchAction';
import endSpeechSynthesize from './endSpeechSynthesize';
import executePromiseScript from './executePromiseScript';
import getNumActivitiesShown from './getNumActivitiesShown';
import getSendBoxText from './getSendBoxText';
import getStore from './getStore';
import hasFocusOnSendBoxTextBox from './hasFocusOnSendBoxTextBox';
import hasPendingSpeechSynthesisUtterance from './hasPendingSpeechSynthesisUtterance';
import hasSpeechRecognitionStartCalled from './hasSpeechRecognitionStartCalled';
import isDictating from './isDictating';
Expand All @@ -31,15 +34,18 @@ export default function pageObjects(driver) {
return mapMap(
{
clickMicrophoneButton,
clickSendButton,
clickSuggestedActionButton,
dispatchAction,
endSpeechSynthesize,
executePromiseScript,
getNumActivitiesShown,
getSendBoxText,
getStore,
hasFocusOnSendBoxTextBox,
hasPendingSpeechSynthesisUtterance,
isDictating,
hasSpeechRecognitionStartCalled,
isDictating,
pingBot,
putSpeechRecognitionResult,
sendFile,
Expand Down

0 comments on commit 277f6c1

Please sign in to comment.