Skip to content

Commit 88dc42f

Browse files
added testing for drag and drop, deprecation patch, and removed dual flag logic
1 parent f5ef7ae commit 88dc42f

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
102102
- Attaching files will no longer remove previously attached files
103103
- Updated Fluent theme to use the new attachment preview feature
104104
- Added collapsible activity and activity with abstract handling, in PR [#5506](https://github.com/microsoft/BotFramework-WebChat/pull/5506), in PR [#5513](https://github.com/microsoft/BotFramework-WebChat/pull/5513), by [@OEvgeny](https://github.com/OEvgeny)
105-
- Added `disableFileUpload` flag to completelly disable file upload feature, in PR [#5508](https://github.com/microsoft/BotFramework-WebChat/pull/5508), by [@JamesNewbyAtMicrosoft](https://github.com/JamesNewbyAtMicrosoft)
105+
- Added `disableFileUpload` flag to completelly disable file upload feature,
106+
- Deprecated `hideUploadButton` in favor of `disableFileUpload`. Added rectification logic in `patchStyleOptionsFromDeprecatedProps.js`.
107+
- Updated `BasicSendBoxToolbar` to rely solely on `disableFileUpload`.
108+
- Improved test to simulate keyboard and mouse behavior instead of DOM-only checks.
109+
in PR [#5508](https://github.com/microsoft/BotFramework-WebChat/pull/5508), by [@JamesNewbyAtMicrosoft](https://github.com/JamesNewbyAtMicrosoft)
106110

107111
### Changed
108112

__tests__/html2/basic/disableFileUpload.html

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,71 @@
1717
run(async function () {
1818
const { directLine, store } = testHelpers.createDirectLineEmulator();
1919

20-
renderWebChat({
21-
directLine,
22-
store,
23-
styleOptions: { disableFileUpload: true }
24-
}, document.getElementById('webchat'));
20+
WebChat.renderWebChat(
21+
{
22+
directLine,
23+
store,
24+
styleOptions: { disableFileUpload: true }
25+
},
26+
document.getElementById('webchat')
27+
);
2528

2629
await pageConditions.uiConnected();
2730

28-
// THEN: No attach button should be render.
31+
// DOM-based checks
2932
expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy();
3033
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy();
34+
35+
// Keyboard interaction: try to tab to the upload button
36+
await pageObjects.focusSendBoxTextBox();
37+
await host.sendTab();
38+
console.log('document.activeElement', document.activeElement);
39+
40+
expect(document.activeElement).not.toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton));
41+
42+
// Simulate drag-and-drop using dispatchEvent
43+
const sendBox = document.querySelector('[role="form"]');
44+
if (sendBox) {
45+
const dataTransfer = new DataTransfer();
46+
const file = new File(['dummy content'], 'test.txt', { type: 'text/plain' });
47+
dataTransfer.items.add(file);
48+
49+
const dragEnterEvent = new DragEvent('dragenter', {
50+
bubbles: true,
51+
cancelable: true,
52+
dataTransfer
53+
});
54+
55+
const dragOverEvent = new DragEvent('dragover', {
56+
bubbles: true,
57+
cancelable: true,
58+
dataTransfer
59+
});
60+
61+
const dropEvent = new DragEvent('drop', {
62+
bubbles: true,
63+
cancelable: true,
64+
dataTransfer
65+
});
66+
67+
sendBox.dispatchEvent(dragEnterEvent);
68+
sendBox.dispatchEvent(dragOverEvent);
69+
sendBox.dispatchEvent(dropEvent);
70+
71+
// Drop zone should still not appear
72+
expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy();
73+
74+
// Attachment bar item should not appear
75+
expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeFalsy();
76+
77+
await host.snapshot('drag-and-drop-disabled');
78+
}
79+
80+
// Hover interaction: hover over the send box area
81+
await host.hover(document.querySelector('[role="form"]'));
82+
await host.snapshot('hover-over-sendbox-toolbar');
83+
84+
// Final visual confirmation
3185
await host.snapshot('local');
3286
});
3387
</script>

packages/api/src/patchStyleOptionsFromDeprecatedProps.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ export default function patchStyleOptionsFromDeprecatedProps(styleOptions) {
1010
styleOptions = updateIn(styleOptions, ['slowConnectionAfter'], () => 0);
1111
}
1212

13+
// Rectify deprecated "hideUploadButton" into "disableFileUpload"
14+
if ('hideUploadButton' in styleOptions && !('disableFileUpload' in styleOptions)) {
15+
console.warn('Web Chat: "hideUploadButton" is deprecated. Please use "disableFileUpload" instead.');
16+
17+
styleOptions = updateIn(styleOptions, ['disableFileUpload'], () => !!styleOptions.hideUploadButton);
18+
}
19+
1320
return styleOptions;
1421
}

packages/component/src/SendBoxToolbar/BasicSendBoxToolbar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import UploadButton from './UploadButton';
55

66
const { useStyleOptions } = hooks;
77

8+
// NOTE: "hideUploadButton" is deprecated. Use "disableFileUpload" instead.
9+
// Rectification logic is handled in patchStyleOptionsFromDeprecatedProps.js
810
function BasicSendBoxToolbar({ className }: SendBoxToolbarMiddlewareProps) {
9-
const [{ disableFileUpload, hideUploadButton }] = useStyleOptions();
11+
const [{ disableFileUpload }] = useStyleOptions();
1012

11-
return !(disableFileUpload || hideUploadButton) && <UploadButton className={className} />;
13+
return !disableFileUpload && <UploadButton className={className} />;
1214
}
1315

1416
export default memo(BasicSendBoxToolbar);

packages/component/src/SendBoxToolbar/UploadButton.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import useMakeThumbnail from '../hooks/useMakeThumbnail';
1313
import useStyleSet from '../hooks/useStyleSet';
1414
import useSubmit from '../providers/internal/SendBox/useSubmit';
1515
import AttachmentIcon from './Assets/AttachmentIcon';
16+
import testIds from '../testIds';
1617

1718
const { useSendBoxAttachments, useLocalizer, useStyleOptions, useUIState } = hooks;
1819

@@ -120,7 +121,13 @@ function UploadButton(props: UploadButtonProps) {
120121
tabIndex={-1}
121122
type="file"
122123
/>
123-
<IconButton alt={uploadFileString} aria-label={uploadFileString} disabled={disabled} onClick={handleClick}>
124+
<IconButton
125+
alt={uploadFileString}
126+
aria-label={uploadFileString}
127+
data-testid={testIds.basicSendBoxUploadButton}
128+
disabled={disabled}
129+
onClick={handleClick}
130+
>
124131
<AttachmentIcon checked={!!sendBoxAttachments.length} />
125132
</IconButton>
126133
</div>

packages/component/src/testIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const testIds = {
2+
basicSendBoxUploadButton: 'basic send box toolbar upload button',
23
codeBlockCopyButton: 'code block copy button',
34
copyButton: 'copy button',
45
feedbackButton: 'feedback button',

packages/fluent-theme/src/components/sendBox/SendBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Props = Readonly<{
4848
}>;
4949

5050
function SendBox(props: Props) {
51-
const [{ disableFileUpload, hideTelephoneKeypadButton, hideUploadButton, maxMessageLength }] = useStyleOptions();
51+
const [{ disableFileUpload, hideTelephoneKeypadButton, maxMessageLength }] = useStyleOptions();
5252
const [attachments, setAttachments] = useSendBoxAttachments();
5353
const [globalMessage, setGlobalMessage] = useSendBoxValue();
5454
const [localMessage, setLocalMessage] = useState('');
@@ -238,7 +238,7 @@ function SendBox(props: Props) {
238238
)}
239239
<Toolbar>
240240
{!hideTelephoneKeypadButton && <TelephoneKeypadToolbarButton />}
241-
{!(disableFileUpload || hideUploadButton) && <AddAttachmentButton onFilesAdded={handleAddFiles} />}
241+
{!disableFileUpload && <AddAttachmentButton onFilesAdded={handleAddFiles} />}
242242
<ToolbarSeparator />
243243
<ToolbarButton
244244
aria-label={localize('TEXT_INPUT_SEND_BUTTON_ALT')}

0 commit comments

Comments
 (0)