Skip to content

Commit 32f361f

Browse files
committed
Move sendBoxAttachments from Redux to React
1 parent 0df7fd9 commit 32f361f

30 files changed

Lines changed: 274 additions & 91 deletions

__tests__/html/sendAttachmentOn/useSendBoxAttachments.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script>
5+
location = './useSendBoxAttachments?deprecated';
6+
</script>
7+
</head>
8+
<body></body>
9+
</html>

__tests__/__image_snapshots__/html/use-send-box-attachments-js-call-use-send-box-attachments-hook-should-get-set-and-upload-attachments-1-snap.png renamed to __tests__/html2/sendBox/sendAttachmentOn/useSendBoxAttachments.deprecated.html.snap-1.png

File renamed without changes.

__tests__/__image_snapshots__/html/use-send-box-attachments-js-call-use-send-box-attachments-hook-should-get-set-and-upload-attachments-2-snap.png renamed to __tests__/html2/sendBox/sendAttachmentOn/useSendBoxAttachments.deprecated.html.snap-2.png

File renamed without changes.

__tests__/html/sendAttachmentOn/useSendBoxAttachments.html renamed to __tests__/html2/sendBox/sendAttachmentOn/useSendBoxAttachments.html

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<main id="webchat"></main>
1313
<script>
1414
run(async function () {
15+
const useDeprecatedHook = new URL(location).searchParams.has('deprecated');
1516
const directLine = WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() });
1617
const store = testHelpers.createStore();
1718

@@ -23,8 +24,10 @@
2324
await pageConditions.uiConnected();
2425

2526
// WHEN: `useSendBoxAttachments` hook is called to get the attachments.
26-
const initialSendBoxAttachments = await pageObjects.runHook(
27-
({ useSendBoxAttachments }) => useSendBoxAttachments()[0]
27+
const initialSendBoxAttachments = await pageObjects.runHook(hooks =>
28+
useDeprecatedHook
29+
? hooks.useSendBoxAttachments()[0]
30+
: hooks.useSendBoxAttachmentsHooks().useSendBoxAttachments()[0]
2831
);
2932

3033
// THEN: It should return empty array.
@@ -59,16 +62,25 @@
5962
});
6063

6164
// WHEN: `useSendBoxAttachments` hook is called to set an attachment.
62-
await pageObjects.runHook(({ useSendBoxAttachments }) => {
65+
await pageObjects.runHook(hooks => {
6366
const attachmentsRef = React.useRef([{ blob, thumbnailURL }]);
64-
useSendBoxAttachments()[1](attachmentsRef.current);
67+
68+
if (useDeprecatedHook) {
69+
hooks.useSendBoxAttachments()[1](attachmentsRef.current);
70+
} else {
71+
hooks.useSendBoxAttachmentsHooks().useSendBoxAttachments()[1](attachmentsRef.current);
72+
}
6573
});
6674

6775
// THEN: It should show checkmark on the button and file preview.
68-
await host.snapshot();
76+
await host.snapshot('local');
6977

7078
// WHEN: `useSendBoxAttachments` hook is called to get the attachments.
71-
const sendBoxAttachments = await pageObjects.runHook(({ useSendBoxAttachments }) => useSendBoxAttachments()[0]);
79+
const sendBoxAttachments = await pageObjects.runHook(hooks =>
80+
useDeprecatedHook
81+
? hooks.useSendBoxAttachments()[0]
82+
: hooks.useSendBoxAttachmentsHooks().useSendBoxAttachments()[0]
83+
);
7284

7385
// THEN: It should return 1 attachment.
7486
expect(sendBoxAttachments).toHaveLength(1);
@@ -80,11 +92,13 @@
8092
// THEN: It should send the attachment (each "run hook" is an activity).
8193
await pageConditions.allOutgoingActivitiesSent();
8294
await pageConditions.numActivitiesShown(5);
83-
await host.snapshot();
95+
await host.snapshot('local');
8496

8597
// WHEN: `useSendBoxAttachments` hook is called to get the attachments.
86-
const finalSendBoxAttachments = await pageObjects.runHook(
87-
({ useSendBoxAttachments }) => useSendBoxAttachments()[0]
98+
const finalSendBoxAttachments = await pageObjects.runHook(hooks =>
99+
useDeprecatedHook
100+
? hooks.useSendBoxAttachments()[0]
101+
: hooks.useSendBoxAttachmentsHooks().useSendBoxAttachments()[0]
88102
);
89103

90104
// THEN: It should return 0 attachments.
11.6 KB
Loading
43.3 KB
Loading

packages/api/src/hooks/Composer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
setLanguage,
1818
setNotification,
1919
setSendBox,
20-
setSendBoxAttachments,
2120
setSendTimeout,
2221
setSendTypingIndicator,
2322
singleToArray,
@@ -104,7 +103,6 @@ const DISPATCHERS = {
104103
setDictateState,
105104
setNotification,
106105
setSendBox,
107-
setSendBoxAttachments,
108106
setSendTimeout,
109107
startDictate,
110108
startSpeakingActivity,

packages/api/src/hooks/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ import useUserID from './useUserID';
7272
import useUsername from './useUsername';
7373
import useVoiceSelector from './useVoiceSelector';
7474

75-
export { useSuggestedActionsHooks, useWhileConnectedHooks } from 'botframework-webchat-redux-store';
75+
export {
76+
useSendBoxAttachmentsHooks,
77+
useSuggestedActionsHooks,
78+
useWhileConnectedHooks
79+
} from 'botframework-webchat-redux-store';
7680

7781
export {
7882
useActiveTyping,

packages/api/src/hooks/internal/WebChatAPIContext.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
type Observable,
44
type WebChatActivity,
55
type sendFiles,
6-
type sendMessage,
7-
type setSendBoxAttachments
6+
type sendMessage
87
} from 'botframework-webchat-core';
98
import { createContext, type ComponentType } from 'react';
109

@@ -78,7 +77,6 @@ export type WebChatAPIContextType = {
7877
setDictateState?: (dictateState: number) => void;
7978
setNotification?: (notification: Notification) => void;
8079
setSendBox?: (value: string) => void;
81-
setSendBoxAttachments?: (...args: Parameters<typeof setSendBoxAttachments>) => void;
8280
setSendTimeout?: (timeout: number) => void;
8381
startDictate?: () => void;
8482
startSpeakingActivity?: () => void;

0 commit comments

Comments
 (0)