Skip to content

Commit c167376

Browse files
committed
Improve test and cover false scenario
1 parent 3df7b65 commit c167376

11 files changed

Lines changed: 454 additions & 30 deletions

__tests__/html2/activity/renderActivity.profiling.html

Lines changed: 417 additions & 0 deletions
Large diffs are not rendered by default.
40.3 KB
Loading
266 Bytes
Loading
-5.91 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Disable file upload (false) (fluent)</title>
5+
<script>
6+
location = './disableFileUpload?disableFileUpload=false&theme=fluent';
7+
</script>
8+
</head>
9+
<body></body>
10+
</html>
7.72 KB
Loading
282 Bytes
Loading
-5.91 KB
Binary file not shown.

__tests__/html2/basic/disableFileUpload.html

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

20+
const disableFileUpload = new URLSearchParams(location.search || '').get('disableFileUpload') !== 'false';
2021
const { isFluentTheme } = renderWebChat(
2122
{
2223
directLine,
2324
store,
24-
styleOptions: { disableFileUpload: true }
25+
styleOptions: { disableFileUpload }
2526
},
2627
document.getElementById('webchat')
2728
);
2829

2930
await pageConditions.uiConnected();
3031

3132
// 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+
}
3440

3541
// Keyboard interaction: try to tab to the upload button
3642
await pageObjects.focusSendBoxTextBox();
3743
await host.sendTab();
3844

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+
}
4350

4451
if (isFluentTheme) {
52+
// We cannot mimic drag-and-drop in WebDriver yet. So we are doing as good as we could.
4553
const dataTransfer = new DataTransfer();
46-
const file = new File(['dummy content'], 'test.txt', { type: 'text/plain' });
47-
dataTransfer.items.add(file);
4854

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'));
5456

55-
const dragOverEvent = new DragEvent('dragover', {
57+
const dragEnterDocumentEvent = new DragEvent('dragenter', {
5658
bubbles: true,
5759
cancelable: true,
5860
dataTransfer
5961
});
6062

63+
document.dispatchEvent(dragEnterDocumentEvent);
64+
6165
const dropEvent = new DragEvent('drop', {
6266
bubbles: true,
6367
cancelable: true,
6468
dataTransfer
6569
});
6670

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);
7672

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+
}
7880
}
7981

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
8582
await host.snapshot('local');
8683
});
8784
</script>
-52 Bytes
Loading

0 commit comments

Comments
 (0)