Skip to content

Commit

Permalink
Add test and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Aug 11, 2019
1 parent 938c62a commit 715ef15
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
12 changes: 6 additions & 6 deletions __tests__/inputHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('input hint', () => {

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

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

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

Expand All @@ -41,7 +41,7 @@ describe('input hint', () => {

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

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

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

Expand All @@ -59,7 +59,7 @@ describe('input hint', () => {

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

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

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

Expand All @@ -79,7 +79,7 @@ describe('input hint', () => {

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

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

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

Expand All @@ -97,7 +97,7 @@ describe('input hint', () => {

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

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

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

Expand All @@ -117,7 +117,7 @@ describe('input hint', () => {

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

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

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

Expand Down
5 changes: 5 additions & 0 deletions __tests__/setup/pageObjects/errorSpeechSynthesize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import executePromiseScript from './executePromiseScript';

export default async function errorSpeechSynthesize(driver, reason) {
return await executePromiseScript(driver, reason => window.WebSpeechMock.mockErrorSynthesize(reason), reason);
}
2 changes: 2 additions & 0 deletions __tests__/setup/pageObjects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import clickSendButton from './clickSendButton';
import clickSuggestedActionButton from './clickSuggestedActionButton';
import dispatchAction from './dispatchAction';
import endSpeechSynthesize from './endSpeechSynthesize';
import errorSpeechSynthesize from './errorSpeechSynthesize';
import executePromiseScript from './executePromiseScript';
import getNumActivitiesShown from './getNumActivitiesShown';
import getSendBoxText from './getSendBoxText';
Expand Down Expand Up @@ -32,6 +33,7 @@ export default function pageObjects(driver) {
clickSuggestedActionButton,
dispatchAction,
endSpeechSynthesize,
errorSpeechSynthesize,
executePromiseScript,
getNumActivitiesShown,
getSendBoxText,
Expand Down
12 changes: 12 additions & 0 deletions __tests__/setup/web/mockWebSpeech.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ window.WebSpeechMock = {
});
},

mockErrorSynthesize(error = 'artificial-error') {
return new Promise(resolve => {
speechSynthesisBroker.consume(utterance => {
utterance.dispatchEvent({ error, type: 'error' });

const { lang, pitch, rate, text, voice, volume } = utterance;

resolve({ lang, pitch, rate, text, voice, volume });
});
});
},

mockRecognize(...args) {
speechRecognitionBroker.produce(...args);
},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/speech.recognition.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('speech recognition', () => {
}
});

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

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
Expand Down
20 changes: 20 additions & 0 deletions __tests__/speech.synthesis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { timeouts } from './constants.json';

import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import speechRecognitionStartCalled from './setup/conditions/speechRecognitionStartCalled';
import speechSynthesisUtterancePended from './setup/conditions/speechSynthesisUtterancePended';

// selenium-webdriver API doc:
Expand Down Expand Up @@ -54,4 +55,23 @@ describe('speech synthesis', () => {

await pageObjects.endSpeechSynthesize();
});

test('should start recognition after failing on speech synthesis with activity of expecting input', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

await pageObjects.sendMessageViaMicrophone('hint expecting');

await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);

await pageObjects.startSpeechSynthesize();
await pageObjects.errorSpeechSynthesize();

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

0 comments on commit 715ef15

Please sign in to comment.