Skip to content

Commit 753b8a6

Browse files
authored
useSubmit() should function after reconnect (#4707)
* useSubmit() should function after reconnect * Add entry
1 parent 960a5a5 commit 753b8a6

File tree

6 files changed

+101
-2
lines changed

6 files changed

+101
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4949
- Fixes [#4557](https://github.com/microsoft/BotFramework-WebChat/issues/4557). Flipper buttons in carousels and suggested actions is now renamed to "next/previous" from "left/right", by [@compulim](https://github.com/compulim), in PR [#4646](https://github.com/microsoft/BotFramework-WebChat/pull/4646)
5050
- Fixes [#4652](https://github.com/microsoft/BotFramework-WebChat/issues/4652). Keyboard help screen, activity focus traps, and chat history terminator should not be hidden behind `aria-hidden` because they are focusable, by [@compulim](https://github.com/compulim), in PR [#4659](https://github.com/microsoft/BotFramework-WebChat/pull/4659)
5151
- Fixes [#4665](https://github.com/microsoft/BotFramework-WebChat/issues/4665). Updated development server with latest ESBuild API, by [@compulim](https://github.com/compulim), in PR [#4662](https://github.com/microsoft/BotFramework-WebChat/pull/4662).
52+
- Fixes [#4706](https://github.com/microsoft/BotFramework-WebChat/issues/4706). Send button and <kbd>ENTER</kbd> key should function after reconnected, by [@compulim](https://github.com/compulim), in PR [#4707](https://github.com/microsoft/BotFramework-WebChat/pull/4707).
5253

5354
### Changed
5455

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<main id="webchat"></main>
11+
<script>
12+
run(async function () {
13+
const { directLine, store } = testHelpers.createDirectLineEmulator();
14+
15+
WebChat.renderWebChat(
16+
{
17+
directLine,
18+
store
19+
},
20+
document.getElementById('webchat')
21+
);
22+
23+
await pageConditions.uiConnected();
24+
25+
// WHEN: Reconnecting.
26+
27+
const { resolve } = directLine.emulateReconnect();
28+
29+
// THEN: Connectivity status should show "Network interruption occurred. Reconnecting…"
30+
31+
await pageConditions.connectivityStatusShown('Network interruption occurred. Reconnecting…');
32+
33+
// ---
34+
35+
// WHEN: Reconnected.
36+
37+
resolve();
38+
39+
// THEN: Connectivity status should be hidden as it is connected.
40+
41+
await pageConditions.became(
42+
'connectivity status is "connected"',
43+
// Connected means the element is not present.
44+
() => !pageElements.connectivityStatus(),
45+
1000
46+
);
47+
48+
// ---
49+
50+
// WHEN: Send a message.
51+
52+
const { resolveAll } = await directLine.actPostActivity(() =>
53+
pageObjects.sendMessageViaSendBox('echo Hello, World!', { waitForSend: false })
54+
);
55+
56+
await resolveAll();
57+
58+
// THEN: Should send successfully.
59+
60+
await pageConditions.allOutgoingActivitiesSent();
61+
62+
// THEN: Should show one message.
63+
64+
await pageConditions.numActivitiesShown(1);
65+
66+
// ---
67+
68+
// WHEN: Bot send a message.
69+
70+
await directLine.emulateIncomingActivity({ text: 'Aloha!', type: 'message' });
71+
72+
// THEN: Should show 2 messages.
73+
74+
await pageConditions.numActivitiesShown(2);
75+
});
76+
</script>
77+
</body>
78+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
test('after reconnect should send and receive message as usual', () => runHTML('chatAdapter.reconnect.html'));

packages/component/src/providers/internal/SendBox/SendBoxComposer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ const SendBoxComposer = ({ children }: PropsWithChildren<{}>) => {
9191
setErrorRef.current = setError;
9292

9393
const submitErrorRef = useRefFrom<'empty' | 'offline' | undefined>(
94-
connectivityStatus !== 'connected' ? 'offline' : !sendBoxValue ? 'empty' : undefined
94+
connectivityStatus !== 'connected' && connectivityStatus !== 'reconnected'
95+
? 'offline'
96+
: !sendBoxValue
97+
? 'empty'
98+
: undefined
9599
);
96100

97101
const submit = useCallback<ContextType['submit']>(

packages/test/page-object/src/globals/pageObjects/sendMessageViaSendBox.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import allOutgoingActivitiesSent from '../pageConditions/allOutgoingActivitiesSent';
2+
import became from '../pageConditions/became';
23
import numActivitiesShown from '../pageConditions/numActivitiesShown';
34
import getActivityElements from '../pageElements/activities';
5+
import getSendBoxTextBoxElement from '../pageElements/sendBoxTextBox';
46
import typeInSendBox from './typeInSendBox';
57

68
export default async function sendMessageViaSendBox(text, { waitForNumResponse = 0, waitForSend = true } = {}) {
@@ -14,6 +16,10 @@ export default async function sendMessageViaSendBox(text, { waitForNumResponse =
1416

1517
await typeInSendBox(text, '\n');
1618

17-
waitForSend && (await allOutgoingActivitiesSent());
19+
if (waitForSend) {
20+
await became('send box to be emptied', () => !getSendBoxTextBoxElement()?.value, 1000);
21+
await allOutgoingActivitiesSent();
22+
}
23+
1824
waitForNumResponse && (await numActivitiesShown(numActivitiesShownBeforeSend + 1 + waitForNumResponse));
1925
}

packages/test/page-object/src/globals/testHelpers/createDirectLineEmulator.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ export default function createDirectLineEmulator({ autoConnect = true, ponyfill
111111
// This is a mock and will no-op on dispatch().
112112
},
113113
postActivity,
114+
emulateReconnect: () => {
115+
connectionStatusDeferredObservable.next(1);
116+
117+
return {
118+
resolve: () => connectionStatusDeferredObservable.next(2)
119+
};
120+
},
114121
emulateConnected: connectedDeferred.resolve,
115122
emulateIncomingActivity: async activity => {
116123
if (typeof activity === 'string') {

0 commit comments

Comments
 (0)