|
17 | 17 | run(async function () { |
18 | 18 | const { directLine, store } = testHelpers.createDirectLineEmulator(); |
19 | 19 |
|
| 20 | + const disableFileUpload = new URLSearchParams(location.search || '').get('disableFileUpload') !== 'false'; |
20 | 21 | const { isFluentTheme } = renderWebChat( |
21 | 22 | { |
22 | 23 | directLine, |
23 | 24 | store, |
24 | | - styleOptions: { disableFileUpload: true } |
| 25 | + styleOptions: { disableFileUpload } |
25 | 26 | }, |
26 | 27 | document.getElementById('webchat') |
27 | 28 | ); |
28 | 29 |
|
29 | 30 | await pageConditions.uiConnected(); |
30 | 31 |
|
31 | 32 | // DOM-based checks |
32 | | - expect(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)).toBeFalsy(); |
33 | | - expect(pageElements.byTestId(WebChat.testIds.sendBoxDropZone)).toBeFalsy(); |
| 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 | + } |
34 | 40 |
|
35 | 41 | // Keyboard interaction: try to tab to the upload button |
36 | 42 | await pageObjects.focusSendBoxTextBox(); |
37 | 43 | await host.sendTab(); |
38 | 44 |
|
39 | | - expect(document.activeElement).not.toBe(pageElements.byTestId(WebChat.testIds.sendBoxUploadButton)); |
40 | | - |
41 | | - // Simulate drag-and-drop using dispatchEvent |
42 | | - const sendBox = pageElements.byTestId(WebChat.testIds.sendBoxContainer); |
| 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 | + } |
43 | 50 |
|
44 | 51 | if (isFluentTheme) { |
| 52 | + // We cannot mimic drag-and-drop in WebDriver yet. So we are doing as good as we could. |
45 | 53 | const dataTransfer = new DataTransfer(); |
46 | | - const file = new File(['dummy content'], 'test.txt', { type: 'text/plain' }); |
47 | | - dataTransfer.items.add(file); |
48 | 54 |
|
49 | | - const dragEnterEvent = new DragEvent('dragenter', { |
50 | | - bubbles: true, |
51 | | - cancelable: true, |
52 | | - dataTransfer |
53 | | - }); |
| 55 | + dataTransfer.items.add(new File([new ArrayBuffer(100)], 'simple.txt')); |
54 | 56 |
|
55 | | - const dragOverEvent = new DragEvent('dragover', { |
| 57 | + const dragEnterDocumentEvent = new DragEvent('dragenter', { |
56 | 58 | bubbles: true, |
57 | 59 | cancelable: true, |
58 | 60 | dataTransfer |
59 | 61 | }); |
60 | 62 |
|
| 63 | + document.dispatchEvent(dragEnterDocumentEvent); |
| 64 | + |
61 | 65 | const dropEvent = new DragEvent('drop', { |
62 | 66 | bubbles: true, |
63 | 67 | cancelable: true, |
64 | 68 | dataTransfer |
65 | 69 | }); |
66 | 70 |
|
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(); |
| 71 | + document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`)?.dispatchEvent(dropEvent); |
76 | 72 |
|
77 | | - await host.snapshot('local'); |
| 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 | + } |
78 | 80 | } |
79 | 81 |
|
80 | | - // Hover interaction: hover over the send box area |
81 | | - await host.hover(pageElements.byTestId(WebChat.testIds.sendBoxContainer)); |
82 | | - await host.snapshot('local'); |
83 | | - |
84 | | - // Final visual confirmation |
85 | 82 | await host.snapshot('local'); |
86 | 83 | }); |
87 | 84 | </script> |
|
0 commit comments