Skip to content

Commit abb2203

Browse files
corinagumcompulim
andauthored
microsoft#3453 Fixes plain text file attachments to show download link when uploaded (microsoft#3711)
* Add test for uploading .txt attachment * Update CHANGELOG.md * Update CHANGELOG.md * Fix breaking tests * Clean up * Update packages/component/src/Middleware/AttachmentForScreenReader/createCoreMiddleware.js Co-authored-by: William Wong <compulim@users.noreply.github.com> * Linting fixes from previous PR * More linting fixes from previous PR * Fix logic and add tests Co-authored-by: William Wong <compulim@users.noreply.github.com>
1 parent 9cea4cd commit abb2203

19 files changed

Lines changed: 199 additions & 20 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4747
- Fixes [#3431](https://github.com/microsoft/BotFramework-WebChat/issues/3431). Race condition between the first bot activity and first user activity should not cause the first bot activity to be delayed, by [@compulim](https://github.com/compulim) in PR [#3705](https://github.com/microsoft/BotFramework-WebChat/pull/3705)
4848
- Fixes [#3676](https://github.com/microsoft/BotFramework-WebChat/issues/3676). Activities without text should not generate bogus `aria-labelledby`, by [@compulim](https://github.com/compulim) in PR [#3697](https://github.com/microsoft/BotFramework-WebChat/pull/3697)
4949
- Fixes [#3625](https://github.com/microsoft/BotFramework-WebChat/issues/3625). Update 'no screen reader for custom activity middleware' warning and add screen reader renderer documentation to `ACCESSIBILITY.md`, by [@corinagum](https://github.com/corinagum) in PR [#3689](https://github.com/microsoft/BotFramework-WebChat/pull/3689)
50+
- Fixes [#3453](https://github.com/microsoft/BotFramework-WebChat/issues/3453). Fixes plain text file attachments to show download link when uploaded, by [@corinagum](https://github.com/corinagum) in PR [#3711](https://github.com/microsoft/BotFramework-WebChat/pull/3711)
5051
- Fixes [#3612](https://github.com/microsoft/BotFramework-WebChat/issues/3612). Carousel flippers in suggested actions are given extra padding, by [@compulim](https://github.com/compulim) and [@Quirinevwm](https://github.com/Quirinevwm) in PR [#3704](https://github.com/microsoft/BotFramework-WebChat/pull/3704)
5152
- Fixes [#3411](https://github.com/microsoft/BotFramework-WebChat/issues/3411). With Direct Line Speech, clicking on microphone button during speech recognition should no longer stop working, by [@compulim](https://github.com/compulim) in PR [#3694](https://github.com/microsoft/BotFramework-WebChat/pull/3694)
5253
- Although it no locker lock up microphone, clicking on the microphone button has no effect because Direct Line Speech does not support aborting speech recognition
15.2 KB
Loading
9.75 KB
Loading
10 KB
Loading
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<script crossorigin="anonymous" src="/__dist__/testharness.js"></script>
5+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
6+
</head>
7+
<body>
8+
<div id="webchat"></div>
9+
<script type="text/babel" data-presets="env,stage-3,react">
10+
const {
11+
WebChatTest: {
12+
conditions,
13+
createDirectLineWithTranscript,
14+
createStore,
15+
getConsoleHistory,
16+
host,
17+
pageObjects,
18+
timeouts,
19+
token
20+
}
21+
} = window;
22+
23+
(async function () {
24+
window.WebChat.renderWebChat(
25+
{
26+
directLine: createDirectLineWithTranscript([
27+
{
28+
type: 'message',
29+
id: 'CONVERSATION_ID-o|00000',
30+
timestamp: '2000-01-23T12:34:56.12345Z',
31+
channelId: 'directline',
32+
from: {
33+
id: 'webchat-mockbot',
34+
name: 'webchat-mockbot'
35+
},
36+
conversation: {
37+
id: 'CONVERSATION_ID-o'
38+
},
39+
locale: 'en-US',
40+
attachments: [
41+
{
42+
contentUrl: 'Hello, World!',
43+
contentType: 'text/plain',
44+
name: 'test.txt'
45+
}
46+
]
47+
}
48+
]),
49+
sendTypingIndicator: true,
50+
store: createStore()
51+
},
52+
document.getElementById('webchat')
53+
);
54+
55+
await pageObjects.wait(conditions.uiConnected(), timeouts.directLine);
56+
await pageObjects.wait(conditions.numActivitiesShown(1), timeouts.directLine);
57+
58+
await host.snapshot();
59+
await host.done();
60+
})().catch(async err => {
61+
console.error(err);
62+
63+
await host.error(err);
64+
});
65+
</script>
66+
</body>
67+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @jest-environment ./__tests__/html/__jest__/WebChatEnvironment.js
3+
*/
4+
5+
describe('text url attachment sent from bot should be rendered', () => {
6+
test('', () => runHTMLTest('sendFiles.attachmentUrl.html'));
7+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<script crossorigin="anonymous" src="/__dist__/testharness.js"></script>
5+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
6+
</head>
7+
<body>
8+
<div id="webchat"></div>
9+
<script type="text/babel" data-presets="env,stage-3,react">
10+
const {
11+
WebChatTest: {
12+
conditions,
13+
createDirectLineWithTranscript,
14+
createStore,
15+
getConsoleHistory,
16+
host,
17+
pageObjects,
18+
timeouts,
19+
token
20+
}
21+
} = window;
22+
23+
(async function () {
24+
window.WebChat.renderWebChat(
25+
{
26+
directLine: createDirectLineWithTranscript([
27+
{
28+
type: 'message',
29+
id: 'CONVERSATION_ID-o|00000',
30+
timestamp: '2000-01-23T12:34:56.12345Z',
31+
channelId: 'directline',
32+
from: {
33+
id: 'webchat-mockbot',
34+
name: 'webchat-mockbot'
35+
},
36+
conversation: {
37+
id: 'CONVERSATION_ID-o'
38+
},
39+
locale: 'en-US',
40+
attachments: [
41+
{
42+
content: 'Hello, World!',
43+
contentType: 'text/plain',
44+
name: 'test.txt'
45+
}
46+
]
47+
}
48+
]),
49+
sendTypingIndicator: true,
50+
store: createStore()
51+
},
52+
document.getElementById('webchat')
53+
);
54+
55+
await pageObjects.wait(conditions.uiConnected(), timeouts.directLine);
56+
await pageObjects.wait(conditions.numActivitiesShown(1), timeouts.directLine);
57+
58+
await host.snapshot();
59+
await host.done();
60+
})().catch(async err => {
61+
console.error(err);
62+
63+
await host.error(err);
64+
});
65+
</script>
66+
</body>
67+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @jest-environment ./__tests__/html/__jest__/WebChatEnvironment.js
3+
*/
4+
5+
describe('text file sent from bot should be rendered', () => {
6+
test('', () => runHTMLTest('sendFiles.textFiles.html'));
7+
});

__tests__/setup/local/empty.txt

Whitespace-only changes.

__tests__/upload.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint no-magic-numbers: "off" */
2+
/* eslint no-undef: "off" */
3+
14
import { imageSnapshotOptions, timeouts } from './constants.json';
25

36
import allImagesLoaded from './setup/conditions/allImagesLoaded';
@@ -28,7 +31,7 @@ describe('upload a picture', () => {
2831
});
2932
}
3033
},
31-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
34+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
3235
useProductionBot: true
3336
});
3437

@@ -132,7 +135,7 @@ describe('upload a picture', () => {
132135
uploadThumbnailWidth: 120
133136
}
134137
},
135-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
138+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
136139
useProductionBot: true
137140
});
138141

@@ -154,7 +157,7 @@ describe('upload a picture', () => {
154157
uploadThumbnailQuality: 0.1
155158
}
156159
},
157-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
160+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
158161
useProductionBot: true
159162
});
160163

@@ -176,7 +179,7 @@ describe('upload a picture', () => {
176179
enableUploadThumbnail: false
177180
}
178181
},
179-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
182+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
180183
useProductionBot: true
181184
});
182185

@@ -194,7 +197,7 @@ describe('upload a picture', () => {
194197
describe('without Web Worker', () => {
195198
test('', async () => {
196199
const { driver, pageObjects } = await setupWebDriver({
197-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
200+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
198201
useProductionBot: true
199202
});
200203

@@ -221,7 +224,7 @@ describe('upload a picture', () => {
221224
uploadThumbnailWidth: 120
222225
}
223226
},
224-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
227+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
225228
useProductionBot: true
226229
});
227230

@@ -246,7 +249,7 @@ describe('upload a picture', () => {
246249
uploadThumbnailQuality: 0.1
247250
}
248251
},
249-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
252+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
250253
useProductionBot: true
251254
});
252255

@@ -268,7 +271,7 @@ describe('upload a picture', () => {
268271

269272
test('upload a ZIP file', async () => {
270273
const { driver, pageObjects } = await setupWebDriver({
271-
// TODO: [P3] Offline bot did not reply with a downloadable attachment, we need to use production bot
274+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
272275
useProductionBot: true
273276
});
274277

@@ -282,3 +285,20 @@ test('upload a ZIP file', async () => {
282285

283286
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
284287
});
288+
289+
test('upload a .txt (plain) file', async () => {
290+
const { driver, pageObjects } = await setupWebDriver({
291+
// TODO: [P3] Offline bot did not reply with a downloadable attachment, so we need to use production bot
292+
useProductionBot: true
293+
});
294+
295+
await driver.wait(uiConnected(), timeouts.directLine);
296+
297+
await pageObjects.sendFile('empty.txt');
298+
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
299+
await driver.wait(allImagesLoaded(), timeouts.fetchImage);
300+
301+
const base64PNG = await driver.takeScreenshot();
302+
303+
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
304+
});

0 commit comments

Comments
 (0)