-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathbundle.html
More file actions
120 lines (95 loc) · 6.1 KB
/
bundle.html
File metadata and controls
120 lines (95 loc) · 6.1 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
</head>
<body>
<main id="webchat"></main>
<script>
const { searchParams } = new URL(location.href);
const variant = searchParams.get('variant') || 'minimal';
function loadScript(src) {
return new Promise((resolve, reject) => {
const scriptElement = document.createElement('script');
scriptElement.setAttribute('crossorigin', 'anonymous');
scriptElement.setAttribute('src', src);
scriptElement.addEventListener('error', reject);
scriptElement.addEventListener('load', resolve);
document.head.append(scriptElement);
});
}
run(async function () {
const bundleName =
variant === 'full' ? 'webchat.js' : variant === 'full-es5' ? 'webchat-es5.js' : 'webchat-minimal.js';
await loadScript(`/__dist__/${bundleName}`);
const { WebChat } = window;
const metaMap = new Map(
Array.from(document.querySelectorAll('meta'))
.filter(element => element.name.startsWith('botframework-webchat'))
.map(element => [element.name, element.getAttribute('content')])
);
// THEN: It should have `<meta name="botframework-webchat:api">`.
expect(metaMap.has('botframework-webchat:api')).toBe(true);
expect(metaMap.get('botframework-webchat:api')).toEqual(expect.stringContaining('build-tool=tsup'));
expect(metaMap.get('botframework-webchat:api')).toEqual(expect.stringContaining('module-format='));
expect(metaMap.get('botframework-webchat:api')).toEqual(expect.stringContaining('version='));
expect(metaMap.get('botframework-webchat:api:version')).toEqual(expect.stringMatching(/^\d+\.\d+\.\d+($|-)/u));
// THEN: It should have `<meta name="botframework-webchat">`.
expect(metaMap.has('botframework-webchat')).toBe(true);
expect(metaMap.get('botframework-webchat')).toEqual(expect.stringContaining('build-tool=tsup'));
expect(metaMap.get('botframework-webchat')).toEqual(expect.stringContaining('module-format=global'));
expect(metaMap.get('botframework-webchat')).toEqual(expect.stringContaining(`variant=${variant}`));
expect(metaMap.get('botframework-webchat')).toEqual(expect.stringContaining('version='));
expect(metaMap.get('botframework-webchat:version')).toEqual(expect.stringMatching(/^\d+\.\d+\.\d+($|-)/u));
// THEN: It should have `<meta name="botframework-webchat:component">`.
expect(metaMap.has('botframework-webchat:component')).toBe(true);
expect(metaMap.get('botframework-webchat:component')).toEqual(expect.stringContaining('build-tool=tsup'));
expect(metaMap.get('botframework-webchat:component')).toEqual(expect.stringContaining('module-format='));
expect(metaMap.get('botframework-webchat:component')).toEqual(expect.stringContaining('version='));
expect(metaMap.get('botframework-webchat:component:version')).toEqual(expect.stringMatching(/^\d+\.\d+\.\d+($|-)/u));
// THEN: It should have `<meta name="botframework-webchat:core">`.
expect(metaMap.has('botframework-webchat:core')).toBe(true);
expect(metaMap.get('botframework-webchat:core')).toEqual(expect.stringContaining('build-tool=tsup'));
expect(metaMap.get('botframework-webchat:core')).toEqual(expect.stringContaining('module-format='));
expect(metaMap.get('botframework-webchat:core')).toEqual(expect.stringContaining('version='));
expect(metaMap.get('botframework-webchat:core:version')).toEqual(expect.stringMatching(/^\d+\.\d+\.\d+($|-)/u));
// THEN: `window.WebChat` should be a plain object.
expect(typeof WebChat).toBe('object');
// THEN: It should have "ReactWebChat".
expect(WebChat).toHaveProperty('ReactWebChat', expect.any(Function));
// THEN: It should have bits from "core" package.
expect(WebChat).toHaveProperty('Constants', expect.any(Object));
// THEN: It should have bits from "api" package.
expect(WebChat).toHaveProperty('concatMiddleware', expect.any(Function));
// THEN: It should have bits from "api/decorator" package.
expect(WebChat).toHaveProperty('decorator', expect.any(Object));
expect(WebChat).toHaveProperty('decorator.ActivityGroupingDecorator', expect.any(Object));
// THEN: It should have bits from "api/middleware" package.
expect(WebChat).toHaveProperty('middleware', expect.any(Object));
expect(WebChat).toHaveProperty('middleware.activityComponent', expect.any(Function));
// THEN: It should have bits from "component" package.
expect(WebChat).toHaveProperty('Components', expect.any(Object));
expect(WebChat).toHaveProperty('Components.BasicWebChat', expect.any(Object));
// THEN: It should have bits from "component/decorator" package.
expect(WebChat).toHaveProperty('decorator.BorderFlair', expect.any(Object));
// THEN: It should have bits from "bundle/minimal" package.
expect(WebChat).toHaveProperty('createBrowserWebSpeechPonyfillFactory', expect.any(Function));
if (variant === 'full' || variant === 'full-es5') {
// THEN: It should have bits from "bundle/full" package.
expect(WebChat).toHaveProperty('Components.AdaptiveCardContent', expect.any(Object));
} else {
// THEN: It should not have bits from "bundle/full" package.
expect(WebChat.Components.AdaptiveCardContent).toBeUndefined();
}
// THEN: `buildInfo.buildTool` should be "tsup".
expect(WebChat).toHaveProperty('buildInfo.buildTool', 'tsup');
// THEN: `buildInfo.moduleFromat` should be "global".
expect(WebChat).toHaveProperty('buildInfo.moduleFormat', 'global'); // Bundle
// THEN: `buildInfo.variant` should match.
expect(WebChat).toHaveProperty('buildInfo.variant', variant);
});
</script>
</body>
</html>