|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <title>Disable file upload</title> |
| 5 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 6 | + <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> |
| 7 | + <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> |
| 8 | + <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> |
| 9 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 10 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 11 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 12 | + <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> |
| 13 | + </head> |
| 14 | + <body> |
| 15 | + <main id="webchat"></main> |
| 16 | + <script> |
| 17 | + run(async function () { |
| 18 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 19 | + |
| 20 | + const disableFileUpload = new URLSearchParams(location.search || '').get('disableFileUpload') !== 'false'; |
| 21 | + const { isFluentTheme } = renderWebChat( |
| 22 | + { |
| 23 | + directLine, |
| 24 | + store, |
| 25 | + styleOptions: { disableFileUpload } |
| 26 | + }, |
| 27 | + document.getElementById('webchat') |
| 28 | + ); |
| 29 | + |
| 30 | + await pageConditions.uiConnected(); |
| 31 | + |
| 32 | + // DOM-based checks |
| 33 | + if (disableFileUpload) { |
| 34 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy(); |
| 35 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy(); |
| 36 | + } else { |
| 37 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeDefined(); |
| 38 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeDefined(); |
| 39 | + } |
| 40 | + |
| 41 | + // Keyboard interaction: try to tab to the upload button |
| 42 | + await pageObjects.focusSendBoxTextBox(); |
| 43 | + await host.sendTab(); |
| 44 | + |
| 45 | + if (disableFileUpload) { |
| 46 | + expect(document.activeElement).not.toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)); |
| 47 | + } else { |
| 48 | + expect(document.activeElement).toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)); |
| 49 | + } |
| 50 | + |
| 51 | + if (isFluentTheme) { |
| 52 | + // We cannot mimic drag-and-drop in WebDriver yet. So we are doing as good as we could. |
| 53 | + const dataTransfer = new DataTransfer(); |
| 54 | + |
| 55 | + dataTransfer.items.add(new File([new ArrayBuffer(100)], 'simple.txt')); |
| 56 | + |
| 57 | + const dragEnterDocumentEvent = new DragEvent('dragenter', { |
| 58 | + bubbles: true, |
| 59 | + cancelable: true, |
| 60 | + dataTransfer |
| 61 | + }); |
| 62 | + |
| 63 | + document.dispatchEvent(dragEnterDocumentEvent); |
| 64 | + |
| 65 | + const dropEvent = new DragEvent('drop', { |
| 66 | + bubbles: true, |
| 67 | + cancelable: true, |
| 68 | + dataTransfer |
| 69 | + }); |
| 70 | + |
| 71 | + document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`)?.dispatchEvent(dropEvent); |
| 72 | + |
| 73 | + if (disableFileUpload) { |
| 74 | + // Attachment bar item should not appear |
| 75 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeFalsy(); |
| 76 | + } else { |
| 77 | + // Attachment bar item should appear |
| 78 | + expect(pageElements.byTestId(WebChat.testIds.sendBoxAttachmentBarItem)).toBeDefined(); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + await host.snapshot('local'); |
| 83 | + }); |
| 84 | + </script> |
| 85 | + </body> |
| 86 | +</html> |
0 commit comments