Skip to content

Commit 5f745a6

Browse files
authored
Add more tests (#2293)
* Add tests * Add tests * Add focus tests * Add tests * Improve reliability * Fix * Add link * Add comment * Apply PR changes * Rename and move files * Rename
1 parent 00da406 commit 5f745a6

38 files changed

Lines changed: 608 additions & 154 deletions

__tests__/cardActionMiddleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { imageSnapshotOptions, timeouts } from './constants.json';
44

55
import allOutgoingActivitiesSent from './setup/conditions/allOutgoingActivitiesSent';
66
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown.js';
7-
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed';
7+
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
88
import uiConnected from './setup/conditions/uiConnected';
99

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

34-
await driver.wait(suggestedActionsShowed(), timeouts.directLine);
34+
await driver.wait(suggestedActionsShown(), timeouts.directLine);
3535

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

__tests__/clockSkew.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('Clock skew', () => {
8484

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

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

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

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

9999
// Skip the echoback for 2nd user-originated activity, so we don't apply server timestamp to it. It will be visually appear as "sending".
100100
// Even the 2nd user-originated activity didn't apply server timestamp, the insertion-sort algorithm should put bot-originated activity below it.

__tests__/focus.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Key } from 'selenium-webdriver';
2+
3+
import { timeouts } from './constants.json';
4+
import sendBoxTextBoxFocused from './setup/conditions/sendBoxTextBoxFocused';
5+
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
6+
import uiConnected from './setup/conditions/uiConnected';
7+
8+
// selenium-webdriver API doc:
9+
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html
10+
11+
jest.setTimeout(timeouts.test);
12+
13+
// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/1971
14+
test('should not focus send box after clicking on send button', async () => {
15+
const { driver, pageObjects } = await setupWebDriver();
16+
17+
await driver.wait(uiConnected(), timeouts.directLine);
18+
19+
await pageObjects.typeOnSendBox('echo 123');
20+
await pageObjects.clickSendButton();
21+
22+
await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
23+
});
24+
25+
// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/1971
26+
test('should not focus send box after clicking on suggested actions', async () => {
27+
const { driver, pageObjects } = await setupWebDriver();
28+
29+
await driver.wait(uiConnected(), timeouts.directLine);
30+
await pageObjects.sendMessageViaSendBox('suggested-actions');
31+
32+
await driver.wait(suggestedActionsShown(), timeouts.directLine);
33+
34+
await pageObjects.clickSuggestedActionButton(0);
35+
36+
await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
37+
});
38+
39+
// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/1971
40+
test('should focus send box after pressing ENTER to send message', async () => {
41+
const { driver, pageObjects } = await setupWebDriver();
42+
43+
await driver.wait(uiConnected(), timeouts.directLine);
44+
45+
await pageObjects.typeOnSendBox('echo 123', Key.RETURN);
46+
47+
await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeTruthy();
48+
});

__tests__/inputHint.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { timeouts } from './constants.json';
22

3-
import isRecognizingSpeech from './setup/pageObjects/isRecognizingSpeech';
43
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
5-
import speechSynthesisPending from './setup/conditions/speechSynthesisPending';
4+
import speechRecognitionStartCalled from './setup/conditions/speechRecognitionStartCalled';
5+
import speechSynthesisUtterancePended from './setup/conditions/speechSynthesisUtterancePended';
66
import uiConnected from './setup/conditions/uiConnected';
77

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

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

28-
await driver.wait(speechSynthesisPending(), timeouts.ui);
28+
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
2929
await pageObjects.startSpeechSynthesize();
3030
await pageObjects.endSpeechSynthesize();
3131

32-
expect(isRecognizingSpeech(driver)).resolves.toBeTruthy();
32+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeTruthy();
3333
});
3434

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

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

48-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
48+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
4949
});
5050
});
5151

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

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

66-
await driver.wait(speechSynthesisPending(), timeouts.ui);
66+
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
6767
await pageObjects.startSpeechSynthesize();
6868
await pageObjects.endSpeechSynthesize();
6969

70-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
70+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
7171
});
7272

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

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

86-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
86+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
8787
});
8888
});
8989

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

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

104-
await driver.wait(speechSynthesisPending(), timeouts.ui);
104+
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
105105
await pageObjects.startSpeechSynthesize();
106106
await pageObjects.endSpeechSynthesize();
107107

108-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
108+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
109109
});
110110

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

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

124-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
124+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
125125
});
126126
});
127127

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

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

142-
await driver.wait(speechSynthesisPending(), timeouts.ui);
142+
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
143143
await pageObjects.startSpeechSynthesize();
144144
await pageObjects.endSpeechSynthesize();
145145

146-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
146+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
147147
});
148148

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

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

162-
expect(isRecognizingSpeech(driver)).resolves.toBeFalsy();
162+
await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
163163
});
164164
});
165165
});

__tests__/scrollToBottom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { imageSnapshotOptions, timeouts } from './constants.json';
44

55
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
66
import scrollToBottomCompleted from './setup/conditions/scrollToBottomCompleted';
7-
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed';
7+
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
88
import uiConnected from './setup/conditions/uiConnected';
99

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

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

2727
const submitButton = await driver.findElement(By.css('button.ac-pushButton:nth-of-type(2)'));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Condition } from 'selenium-webdriver';
2+
3+
export default function negateCondition(condition) {
4+
return new Condition(`Negate of ${condition.name}`, async (...args) => !(await condition.fn(...args)));
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { By, Condition } from 'selenium-webdriver';
2+
3+
import getSendBoxTextBox, { CSS_SELECTOR } from '../elements/getSendBoxTextBox';
4+
5+
export default function sendBoxTextBoxFocused() {
6+
return new Condition('Send box text box to be focused', async driver => {
7+
// Make sure the send box text box is visible
8+
await getSendBoxTextBox(driver);
9+
10+
try {
11+
await driver.findElement(By.css(CSS_SELECTOR + ':focus'));
12+
13+
return true;
14+
} catch (err) {
15+
if (err.name === 'NoSuchElementError') {
16+
return false;
17+
}
18+
19+
throw err;
20+
}
21+
});
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Condition } from 'selenium-webdriver';
2+
3+
// Checks if Web Chat has called "speechRecognition.start()" and pending for a series of speech events.
4+
5+
export default function speechRecognitionStartCalled() {
6+
return new Condition('SpeechRecognition.start to be called', driver =>
7+
driver.executeScript(() => window.WebSpeechMock.speechRecognitionStartCalled())
8+
);
9+
}

__tests__/setup/conditions/speechRecognitionStarted.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

__tests__/setup/conditions/speechSynthesisPending.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)