Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSubmit() should function after reconnect #4707

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- 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)
- 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)
- 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).
- 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).

### Changed

Expand Down
78 changes: 78 additions & 0 deletions __tests__/html/chatAdapter.reconnect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<main id="webchat"></main>
<script>
run(async function () {
const { directLine, store } = testHelpers.createDirectLineEmulator();

WebChat.renderWebChat(
{
directLine,
store
},
document.getElementById('webchat')
);

await pageConditions.uiConnected();

// WHEN: Reconnecting.

const { resolve } = directLine.emulateReconnect();

// THEN: Connectivity status should show "Network interruption occurred. Reconnecting…"

await pageConditions.connectivityStatusShown('Network interruption occurred. Reconnecting…');

// ---

// WHEN: Reconnected.

resolve();

// THEN: Connectivity status should be hidden as it is connected.

await pageConditions.became(
'connectivity status is "connected"',
// Connected means the element is not present.
() => !pageElements.connectivityStatus(),
1000
);

// ---

// WHEN: Send a message.

const { resolveAll } = await directLine.actPostActivity(() =>
pageObjects.sendMessageViaSendBox('echo Hello, World!', { waitForSend: false })
);

await resolveAll();

// THEN: Should send successfully.

await pageConditions.allOutgoingActivitiesSent();

// THEN: Should show one message.

await pageConditions.numActivitiesShown(1);

// ---

// WHEN: Bot send a message.

await directLine.emulateIncomingActivity({ text: 'Aloha!', type: 'message' });

// THEN: Should show 2 messages.

await pageConditions.numActivitiesShown(2);
});
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions __tests__/html/chatAdapter.reconnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */

test('after reconnect should send and receive message as usual', () => runHTML('chatAdapter.reconnect.html'));
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ const SendBoxComposer = ({ children }: PropsWithChildren<{}>) => {
setErrorRef.current = setError;

const submitErrorRef = useRefFrom<'empty' | 'offline' | undefined>(
connectivityStatus !== 'connected' ? 'offline' : !sendBoxValue ? 'empty' : undefined
connectivityStatus !== 'connected' && connectivityStatus !== 'reconnected'
? 'offline'
: !sendBoxValue
? 'empty'
: undefined
);

const submit = useCallback<ContextType['submit']>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import allOutgoingActivitiesSent from '../pageConditions/allOutgoingActivitiesSent';
import became from '../pageConditions/became';
import numActivitiesShown from '../pageConditions/numActivitiesShown';
import getActivityElements from '../pageElements/activities';
import getSendBoxTextBoxElement from '../pageElements/sendBoxTextBox';
import typeInSendBox from './typeInSendBox';

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

await typeInSendBox(text, '\n');

waitForSend && (await allOutgoingActivitiesSent());
if (waitForSend) {
await became('send box to be emptied', () => !getSendBoxTextBoxElement()?.value, 1000);
await allOutgoingActivitiesSent();
}

waitForNumResponse && (await numActivitiesShown(numActivitiesShownBeforeSend + 1 + waitForNumResponse));
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export default function createDirectLineEmulator({ autoConnect = true, ponyfill
// This is a mock and will no-op on dispatch().
},
postActivity,
emulateReconnect: () => {
connectionStatusDeferredObservable.next(1);

return {
resolve: () => connectionStatusDeferredObservable.next(2)
};
},
emulateConnected: connectedDeferred.resolve,
emulateIncomingActivity: async activity => {
if (typeof activity === 'string') {
Expand Down