forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expecting input should only turn on microphone if via microphone
- Loading branch information
Showing
5 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters