-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add clipboard paste and drag-and-drop file support to both themes #5829
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c088b31
feat: Add clipboard paste and drag-and-drop file support to both themes
OEvgeny fd39635
Changelog
OEvgeny 2ec9144
Remove width constraint
OEvgeny 1726825
Fix types
OEvgeny a8a79f0
Potential fix for pull request finding
OEvgeny 590ec62
Apply suggestion from @OEvgeny
OEvgeny 7f15e29
Fix snaps
OEvgeny 3714fb3
Fix nits
OEvgeny b3260a3
Fix tsd
OEvgeny 549daf4
Review
OEvgeny 0972d7b
Fix props type
OEvgeny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <title>Drag and drop file upload (basic theme)</title> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> | ||
| <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> | ||
| <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script> | ||
| run(async function () { | ||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| renderWebChat( | ||
| { | ||
| directLine, | ||
| store | ||
| }, | ||
| document.getElementById('webchat') | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| const dataTransfer = new DataTransfer(); | ||
|
|
||
| dataTransfer.items.add(new File([new ArrayBuffer(100)], 'simple.txt')); | ||
|
|
||
| // WHEN: Dragging a file into document. | ||
| const dragEnterDocumentEvent = new DragEvent('dragenter', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document.dispatchEvent(dragEnterDocumentEvent); | ||
|
|
||
| // THEN: Should render the drop zone. | ||
| await pageConditions.became( | ||
| 'Drop zone should appear', | ||
| () => !!document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`), | ||
| 1000 | ||
| ); | ||
|
|
||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Dragging into the drop zone. | ||
| const dragEnterDropZoneEvent = new DragEvent('dragenter', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document | ||
| .querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`) | ||
| .dispatchEvent(dragEnterDropZoneEvent); | ||
|
|
||
| // THEN: Should render drop zone in droppable state. | ||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Dropping into the drop zone. | ||
| const dropEvent = new DragEvent('drop', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`).dispatchEvent(dropEvent); | ||
|
|
||
| // THEN: An attachment should appear in the attachment bar. | ||
| await pageConditions.became( | ||
| 'Attachment bar item should appear', | ||
| () => !!pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem), | ||
| 1000 | ||
| ); | ||
|
|
||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Dragging a file into document again. | ||
| const dragEnterDocumentEvent1 = new DragEvent('dragenter', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document.dispatchEvent(dragEnterDocumentEvent1); | ||
|
|
||
| // THEN: Should render the drop zone again. | ||
| await pageConditions.became( | ||
| 'Drop zone should appear again', | ||
| () => !!document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`), | ||
| 1000 | ||
| ); | ||
|
|
||
| // WHEN: Dragging a file over the document. | ||
| const dragOverDocumentEvent = new DragEvent('dragover', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document.dispatchEvent(dragOverDocumentEvent); | ||
|
|
||
| // THEN: The default browser behavior should be prevented. | ||
| await pageConditions.became( | ||
| 'DragOver event preventDefault is called', | ||
| () => dragOverDocumentEvent.defaultPrevented, | ||
| 1000 | ||
| ); | ||
|
|
||
| // WHEN: Dropping out of the drop zone. | ||
| const dropEvent1 = new DragEvent('drop', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| dataTransfer | ||
| }); | ||
|
|
||
| document.body.dispatchEvent(dropEvent1); | ||
|
|
||
| // THEN: Should render single attachment (no duplicate from out-of-zone drop). | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
|
OEvgeny marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <title>Paste file into send box</title> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> | ||
| <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> | ||
| <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script> | ||
| run(async function () { | ||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| renderWebChat( | ||
| { | ||
| directLine, | ||
| store | ||
| }, | ||
| document.getElementById('webchat') | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // WHEN: Pasting a file into the send box text area. | ||
| const textBox = document.querySelector(`[data-testid="${WebChat.testIds['sendBoxTextBox']}"]`); | ||
| const dataTransfer = new DataTransfer(); | ||
|
|
||
| dataTransfer.items.add(new File([new ArrayBuffer(100)], 'test-document.txt', { type: 'text/plain' })); | ||
|
|
||
| const pasteEvent = new ClipboardEvent('paste', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| clipboardData: dataTransfer | ||
| }); | ||
|
|
||
| textBox.dispatchEvent(pasteEvent); | ||
|
|
||
| // THEN: The paste event should be prevented (file handled by webchat). | ||
| expect(pasteEvent.defaultPrevented).toBeTruthy(); | ||
|
|
||
| // THEN: An attachment should appear in the attachment bar. | ||
| await pageConditions.became( | ||
| 'Attachment bar item should appear', | ||
| () => !!pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem), | ||
| 1000 | ||
| ); | ||
|
|
||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Pasting a second file. | ||
| const dataTransfer2 = new DataTransfer(); | ||
|
|
||
| dataTransfer2.items.add(new File([new ArrayBuffer(200)], 'test-spreadsheet.csv', { type: 'text/csv' })); | ||
|
|
||
| const pasteEvent2 = new ClipboardEvent('paste', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| clipboardData: dataTransfer2 | ||
| }); | ||
|
|
||
| textBox.dispatchEvent(pasteEvent2); | ||
|
|
||
| // THEN: Both attachments should appear (accumulated, not replaced). | ||
| await pageConditions.became( | ||
| 'Two attachment bar items should appear', | ||
| () => document.querySelectorAll(`[data-testid="${WebChat.testIds.sendBoxAttachmentBarItem}"]`).length === 2, | ||
| 1000 | ||
| ); | ||
|
|
||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+58.5 KB
__tests__/html2/styleOptions/deprecated.hideScrollToEndButton.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+60.3 KB
__tests__/html2/styleOptions/deprecated.hideScrollToEndButton.html.snap-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62.8 KB
__tests__/html2/styleOptions/deprecated.newMessageButtonFontSize.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.9 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.7 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.9 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13 KB
__tests__/html2/suggestedActions/styleOptions.deprecated.html.snap-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.