Skip to content

Commit

Permalink
Add more tests (#2293)
Browse files Browse the repository at this point in the history
* Add tests

* Add tests

* Add focus tests

* Add tests

* Improve reliability

* Fix

* Add link

* Add comment

* Apply PR changes

* Rename and move files

* Rename
  • Loading branch information
compulim authored Aug 10, 2019
1 parent 00da406 commit 5f745a6
Show file tree
Hide file tree
Showing 38 changed files with 608 additions and 154 deletions.
4 changes: 2 additions & 2 deletions __tests__/cardActionMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { imageSnapshotOptions, timeouts } from './constants.json';

import allOutgoingActivitiesSent from './setup/conditions/allOutgoingActivitiesSent';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown.js';
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed';
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
import uiConnected from './setup/conditions/uiConnected';

// selenium-webdriver API doc:
Expand All @@ -31,7 +31,7 @@ test('card action "openUrl"', async () => {
await driver.wait(uiConnected(), timeouts.directLine);
await pageObjects.sendMessageViaSendBox('card-actions', { waitForSend: true });

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

const openUrlButton = await driver.findElement(By.css('[role="form"] ul > li:first-child button'));

Expand Down
4 changes: 2 additions & 2 deletions __tests__/clockSkew.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Clock skew', () => {

// Make sure the clock skew is set correctly.
// If it is not set, the result could be false-positive.
expect(pageObjects.getStore()).resolves.toHaveProperty('clockSkewAdjustment', 120000);
await expect(pageObjects.getStore()).resolves.toHaveProperty('clockSkewAdjustment', 120000);

await pageObjects.sendMessageViaSendBox('echo This outgoing activity should be the last in the list.', {
waitForSend: false
Expand All @@ -94,7 +94,7 @@ describe('Clock skew', () => {

const lastActivity = await driver.findElement(By.css('[role="list"] > li:last-child p'));

expect(lastActivity.getText()).resolves.toBe('echo This outgoing activity should be the last in the list.');
await expect(lastActivity.getText()).resolves.toBe('echo This outgoing activity should be the last in the list.');

// Skip the echoback for 2nd user-originated activity, so we don't apply server timestamp to it. It will be visually appear as "sending".
// Even the 2nd user-originated activity didn't apply server timestamp, the insertion-sort algorithm should put bot-originated activity below it.
Expand Down
48 changes: 48 additions & 0 deletions __tests__/focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Key } from 'selenium-webdriver';

import { timeouts } from './constants.json';
import sendBoxTextBoxFocused from './setup/conditions/sendBoxTextBoxFocused';
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
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);

// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/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.typeOnSendBox('echo 123');
await pageObjects.clickSendButton();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
});

// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/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(suggestedActionsShown(), timeouts.directLine);

await pageObjects.clickSuggestedActionButton(0);

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
});

// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/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.typeOnSendBox('echo 123', Key.RETURN);

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeTruthy();
});
28 changes: 14 additions & 14 deletions __tests__/inputHint.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { timeouts } from './constants.json';

import isRecognizingSpeech from './setup/pageObjects/isRecognizingSpeech';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import speechSynthesisPending from './setup/conditions/speechSynthesisPending';
import speechRecognitionStartCalled from './setup/conditions/speechRecognitionStartCalled';
import speechSynthesisUtterancePended from './setup/conditions/speechSynthesisUtterancePended';
import uiConnected from './setup/conditions/uiConnected';

// selenium-webdriver API doc:
Expand All @@ -25,11 +25,11 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

await driver.wait(speechSynthesisPending(), timeouts.ui);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
await pageObjects.startSpeechSynthesize();
await pageObjects.endSpeechSynthesize();

expect(isRecognizingSpeech(driver)).resolves.toBeTruthy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeTruthy();
});

test('should not turn on microphone if initiated via typing', async () => {
Expand All @@ -45,7 +45,7 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});
});

Expand All @@ -63,11 +63,11 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

await driver.wait(speechSynthesisPending(), timeouts.ui);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
await pageObjects.startSpeechSynthesize();
await pageObjects.endSpeechSynthesize();

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});

test('should not turn on microphone if initiated via typing', async () => {
Expand All @@ -83,7 +83,7 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});
});

Expand All @@ -101,11 +101,11 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

await driver.wait(speechSynthesisPending(), timeouts.ui);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
await pageObjects.startSpeechSynthesize();
await pageObjects.endSpeechSynthesize();

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});

test('should turn off microphone if initiated via typing', async () => {
Expand All @@ -121,7 +121,7 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});
});

Expand All @@ -139,11 +139,11 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

await driver.wait(speechSynthesisPending(), timeouts.ui);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
await pageObjects.startSpeechSynthesize();
await pageObjects.endSpeechSynthesize();

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});

test('should not turn on microphone if initiated via typing', async () => {
Expand All @@ -159,7 +159,7 @@ describe('input hint', () => {

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
});
});
});
4 changes: 2 additions & 2 deletions __tests__/scrollToBottom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 suggestedActionsShown from './setup/conditions/suggestedActionsShown';
import uiConnected from './setup/conditions/uiConnected';

// selenium-webdriver API doc:
Expand All @@ -21,7 +21,7 @@ test('should stick to bottom if submitting an Adaptive Card while suggested acti
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

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

const submitButton = await driver.findElement(By.css('button.ac-pushButton:nth-of-type(2)'));
Expand Down
5 changes: 5 additions & 0 deletions __tests__/setup/conditions/negate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Condition } from 'selenium-webdriver';

export default function negateCondition(condition) {
return new Condition(`Negate of ${condition.name}`, async (...args) => !(await condition.fn(...args)));
}
22 changes: 22 additions & 0 deletions __tests__/setup/conditions/sendBoxTextBoxFocused.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { By, Condition } from 'selenium-webdriver';

import getSendBoxTextBox, { CSS_SELECTOR } from '../elements/getSendBoxTextBox';

export default function sendBoxTextBoxFocused() {
return new Condition('Send box text box to be focused', async 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;
}
});
}
9 changes: 9 additions & 0 deletions __tests__/setup/conditions/speechRecognitionStartCalled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Condition } from 'selenium-webdriver';

// Checks if Web Chat has called "speechRecognition.start()" and pending for a series of speech events.

export default function speechRecognitionStartCalled() {
return new Condition('SpeechRecognition.start to be called', driver =>
driver.executeScript(() => window.WebSpeechMock.speechRecognitionStartCalled())
);
}
15 changes: 0 additions & 15 deletions __tests__/setup/conditions/speechRecognitionStarted.js

This file was deleted.

15 changes: 0 additions & 15 deletions __tests__/setup/conditions/speechSynthesisPending.js

This file was deleted.

7 changes: 7 additions & 0 deletions __tests__/setup/conditions/speechSynthesisUtterancePended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Condition } from 'selenium-webdriver';

export default function speechSynthesisUtterancePended() {
return new Condition('Speech synthesis utterance to be pended to synthesize', driver =>
driver.executeScript(() => window.WebSpeechMock.speechSynthesisUtterancePended())
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { By, until } from 'selenium-webdriver';

export default function suggestedActionsShowed() {
export default function suggestedActionsShown() {
return until.elementLocated(By.css('[role="form"] ul'));
}
9 changes: 9 additions & 0 deletions __tests__/setup/elements/getSendBoxTextBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +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(CSS_SELECTOR));
}

export { CSS_SELECTOR };
5 changes: 5 additions & 0 deletions __tests__/setup/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"]'));
}
5 changes: 5 additions & 0 deletions __tests__/setup/elements/getSuggestedActionButtons.js
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'));
}
File renamed without changes.
7 changes: 7 additions & 0 deletions __tests__/setup/pageObjects/clickMicrophoneButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getMicrophoneButton from '../elements/getMicrophoneButton';

export default async function clickMicrophoneButton(driver) {
const microphoneButton = await getMicrophoneButton(driver);

await microphoneButton.click();
}
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();
}
5 changes: 5 additions & 0 deletions __tests__/setup/pageObjects/getNumActivitiesShown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { By } from 'selenium-webdriver';

export default async function getNumActivitiesShown(driver) {
return (await driver.findElements(By.css(`[role="listitem"]`))).length;
}
7 changes: 7 additions & 0 deletions __tests__/setup/pageObjects/getSendBoxText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getSendBoxTextBox from '../elements/getSendBoxTextBox';

export default async function getSendBoxText(driver) {
const textBox = await getSendBoxTextBox(driver);

return await textBox.getAttribute('value');
}
5 changes: 0 additions & 5 deletions __tests__/setup/pageObjects/getSendBoxTextBox.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5f745a6

Please sign in to comment.