Skip to content

Commit

Permalink
Expecting input should only turn on microphone if via microphone
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Jul 10, 2019
1 parent b0c803e commit 1eb2ffa
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 2 deletions.
165 changes: 165 additions & 0 deletions __tests__/inputHint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { timeouts } from './constants.json';

import isRecognizingSpeech from './setup/pageObjects/isRecognizingSpeech';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import speechSynthesisPending from './setup/conditions/speechSynthesisPending';
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);

describe('input hint', () => {
describe('of expectingInput', async () => {
test('should turn on microphone if initiated via microphone', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaMicrophone('hint expecting input');

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

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

expect(isRecognizingSpeech(driver)).resolves.toBeTruthy();
});

test('should not turn on microphone if initiated via typing', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaMicrophone('hint expecting input');

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});
});

describe('of acceptingInput', async () => {
test('should not turn on microphone if initiated via microphone', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaMicrophone('hint accepting input');

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

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});

test('should not turn on microphone if initiated via typing', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaSendBox('hint accepting input');

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});
});

describe('of ignoringInput', async () => {
test('should turn off microphone if initiated via microphone', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaMicrophone('hint ignoring input');

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

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});

test('should turn off microphone if initiated via typing', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaSendBox('hint ignoring input');

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});
});

describe('of undefined', async () => {
test('should not turn on microphone if initiated via microphone', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaMicrophone('hint undefined');

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

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});

test('should not turn on microphone if initiated via typing', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

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

await pageObjects.sendMessageViaSendBox('hint undefined');

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

expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
});
});
});
2 changes: 2 additions & 0 deletions __tests__/setup/pageObjects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import hasPendingSpeechSynthesisUtterance from './hasPendingSpeechSynthesisUtter
import isRecognizingSpeech from './isRecognizingSpeech';
import pingBot from './pingBot';
import putSpeechRecognitionResult from './putSpeechRecognitionResult';
import sendMessageViaMicrophone from './sendMessageViaMicrophone';
import sendMessageViaSendBox from './sendMessageViaSendBox';
import startSpeechSynthesize from './startSpeechSynthesize';

Expand All @@ -30,6 +31,7 @@ export default function pageObjects(driver) {
isRecognizingSpeech,
pingBot,
putSpeechRecognitionResult,
sendMessageViaMicrophone,
sendMessageViaSendBox,
startSpeechSynthesize
},
Expand Down
16 changes: 16 additions & 0 deletions __tests__/setup/pageObjects/sendMessageViaMicrophone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { timeouts } from '../../constants.json';
import allOutgoingActivitiesSent from '../conditions/allOutgoingActivitiesSent';
import getMicrophoneButton from './getMicrophoneButton';
import putSpeechRecognitionResult from './putSpeechRecognitionResult';
import speechRecognitionStarted from '../conditions/speechRecognitionStarted';

export default async function sendMessageViaMicrophone(driver, text, { waitForSend = true } = {}) {
const microphoneButton = await getMicrophoneButton(driver);

await microphoneButton.click();

await driver.wait(speechRecognitionStarted(), timeouts.ui);
await putSpeechRecognitionResult(driver, 'recognize', text);

waitForSend && (await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine));
}
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';
import getSendBoxTextBox from './getSendBoxTextBox';

export default async function sendMessageViaSendBox(driver, text, { waitForSend = true }) {
export default async function sendMessageViaSendBox(driver, text, { waitForSend = true } = {}) {
const input = await getSendBoxTextBox(driver);

await input.sendKeys(text, Key.RETURN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function* speakActivityAndStartDictateOnIncomingActivityFromOthers({ userID }) {
yield put(markActivity(activity, 'speak', true));
}

if (activity.inputHint === 'expectingInput' || (shouldSpeak && activity.inputHint !== 'ignoringInput')) {
if (shouldSpeak && activity.inputHint === 'expectingInput') {
yield put(startDictate());
} else if (activity.inputHint === 'ignoringInput') {
yield put(stopDictate());
Expand Down

0 comments on commit 1eb2ffa

Please sign in to comment.