forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmarkdownPreferredOverEntities.html
More file actions
98 lines (83 loc) · 3.21 KB
/
markdownPreferredOverEntities.html
File metadata and controls
98 lines (83 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script type="importmap">
{
"imports": {
"jest-mock": "https://esm.sh/jest-mock",
"react": "https://esm.sh/react@18",
"react-dom": "https://esm.sh/react-dom@18",
"react-dom/": "https://esm.sh/react-dom@18/"
}
}
</script>
<script type="module">
import React from 'react';
window.React = React;
</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>
</head>
<body>
<main id="webchat"></main>
<script type="module">
import { fn, spyOn } from 'jest-mock';
run(async function () {
const { directLine, store } = testHelpers.createDirectLineEmulator();
WebChat.renderWebChat(
{
directLine,
store
},
document.getElementById('webchat')
);
await pageConditions.uiConnected();
const consoleWarn = fn(console.log.bind(console));
spyOn(console, 'warn').mockImplementationOnce(consoleWarn);
await directLine.emulateIncomingActivity({
entities: [
{
'@context': 'https://schema.org',
'@id': '',
'@type': 'Message',
type: 'https://schema.org/Message',
citation: [
{
'@id': ':_doesnt-care-1',
'@type': 'Claim',
appearance: {
'@type': 'DigitalDocument',
encodingFormat: 'application/octet-stream',
url: 'https://aka.ms/bad-link'
},
position: '1'
}
]
}
],
text: `Ea officia[1] elit laboris[2] reprehenderit laborum elit ipsum qui eiusmod.
[1]: https://aka.ms/correct-link
[2]: javascript:alert(1)
`,
type: 'message'
});
expect(consoleWarn).toHaveBeenCalledTimes(1);
expect(consoleWarn.mock.calls[0][0]).toBe(
'botframework-webchat: When "Message.citation[].url" is set in entities, it must match its corresponding URL in Markdown link reference definition'
);
await host.snapshot('local');
const markdownElement = pageElements.activities()[0].querySelector('.webchat__text-content__markdown');
const markdownClickableLinks = markdownElement.querySelectorAll('a[href]');
// The javascript: shouldn't be a link.
expect(markdownClickableLinks).toHaveLength(1);
expect(markdownClickableLinks[0].getAttribute('href')).toBe('https://aka.ms/correct-link');
const linkDefinitionItems = pageElements.linkDefinitions()[0].querySelectorAll('[role="listitem"] > *');
// THe javascript: link is gone in Markdown, should be ignored in citation as well.
expect(linkDefinitionItems).toHaveLength(1);
expect(linkDefinitionItems[0].getAttribute('href')).toBe('https://aka.ms/correct-link');
});
</script>
</body>
</html>