|
28 | 28 | import React from 'react'; |
29 | 29 | import { createRoot } from 'react-dom/client'; |
30 | 30 |
|
31 | | - const aiMessageEntity = Object.freeze({ |
32 | | - '@context': 'https://schema.org', |
33 | | - '@id': '', |
34 | | - '@type': 'Message', |
35 | | - keywords: Object.freeze(['AIGeneratedContent']), |
36 | | - type: 'https://schema.org/Message' |
37 | | - }); |
38 | | - |
39 | | - // Programming languages are sent as-is in "programmingLanguage", often in lowercase or as an alias. |
40 | | - // Only JavaScript, Python, and TypeScript are highlighted by the bundled highlighter. |
41 | | - const COLLAPSIBLE_SAMPLES = Object.freeze([ |
42 | | - Object.freeze({ |
43 | | - isHighlighted: true, |
44 | | - programmingLanguage: 'javascript', |
45 | | - text: "console.log('Hello, World!');", |
46 | | - title: 'JavaScript' |
47 | | - }), |
48 | | - Object.freeze({ |
49 | | - isHighlighted: true, |
50 | | - programmingLanguage: 'TS', |
51 | | - text: "const greeting: string = 'Hello, World!';", |
52 | | - title: 'TypeScript' |
53 | | - }), |
54 | | - Object.freeze({ |
55 | | - isHighlighted: false, |
56 | | - programmingLanguage: 'c#', |
57 | | - text: 'Console.WriteLine("Hello, World!");', |
58 | | - title: 'C#' |
59 | | - }), |
60 | | - // The title of "sh" ("Shell") is overridden via "overrideLocalizedStrings" below. |
61 | | - Object.freeze({ |
62 | | - isHighlighted: false, |
63 | | - programmingLanguage: 'sh', |
64 | | - text: 'echo "Hello, World!"', |
65 | | - title: 'Shell script' |
66 | | - }), |
67 | | - // Shell dialects keep their own name: only the first letter is capitalized. |
68 | | - Object.freeze({ |
69 | | - isHighlighted: false, |
70 | | - programmingLanguage: 'bash', |
71 | | - text: "echo 'Hello, World!'", |
72 | | - title: 'Bash' |
73 | | - }), |
74 | | - // Unknown programming language: only the first letter is capitalized. |
75 | | - Object.freeze({ |
76 | | - isHighlighted: false, |
77 | | - programmingLanguage: 'cobol', |
78 | | - text: 'DISPLAY "Hello, World!".', |
79 | | - title: 'Cobol' |
80 | | - }) |
81 | | - ]); |
82 | | - |
83 | 31 | run(async function () { |
84 | 32 | const { |
85 | 33 | WebChat: { ReactWebChat, testIds } |
|
99 | 47 |
|
100 | 48 | await pageConditions.uiConnected(); |
101 | 49 |
|
| 50 | + const aiMessageEntity = Object.freeze({ |
| 51 | + '@context': 'https://schema.org', |
| 52 | + '@id': '', |
| 53 | + '@type': 'Message', |
| 54 | + keywords: Object.freeze(['AIGeneratedContent']), |
| 55 | + type: 'https://schema.org/Message' |
| 56 | + }); |
| 57 | + |
| 58 | + // Programming languages are sent as-is in "programmingLanguage", often in lowercase or as an alias. |
| 59 | + // Only JavaScript, Python, and TypeScript are highlighted by the bundled highlighter. |
| 60 | + const collapsibleSamples = Object.freeze([ |
| 61 | + Object.freeze({ |
| 62 | + isHighlighted: true, |
| 63 | + programmingLanguage: 'javascript', |
| 64 | + text: "console.log('Hello, World!');", |
| 65 | + title: 'JavaScript' |
| 66 | + }), |
| 67 | + Object.freeze({ |
| 68 | + isHighlighted: true, |
| 69 | + programmingLanguage: 'TS', |
| 70 | + text: "const greeting: string = 'Hello, World!';", |
| 71 | + title: 'TypeScript' |
| 72 | + }), |
| 73 | + Object.freeze({ |
| 74 | + isHighlighted: false, |
| 75 | + programmingLanguage: 'c#', |
| 76 | + text: 'Console.WriteLine("Hello, World!");', |
| 77 | + title: 'C#' |
| 78 | + }), |
| 79 | + // The title of "sh" ("Shell") is overridden via "overrideLocalizedStrings" above. |
| 80 | + Object.freeze({ |
| 81 | + isHighlighted: false, |
| 82 | + programmingLanguage: 'sh', |
| 83 | + text: 'echo "Hello, World!"', |
| 84 | + title: 'Shell script' |
| 85 | + }), |
| 86 | + // Shell dialects keep their own name: only the first letter is capitalized. |
| 87 | + Object.freeze({ |
| 88 | + isHighlighted: false, |
| 89 | + programmingLanguage: 'bash', |
| 90 | + text: "echo 'Hello, World!'", |
| 91 | + title: 'Bash' |
| 92 | + }), |
| 93 | + // Unknown programming language: only the first letter is capitalized. |
| 94 | + Object.freeze({ |
| 95 | + isHighlighted: false, |
| 96 | + programmingLanguage: 'cobol', |
| 97 | + text: 'DISPLAY "Hello, World!".', |
| 98 | + title: 'Cobol' |
| 99 | + }) |
| 100 | + ]); |
| 101 | + |
102 | 102 | // WHEN: The bot sends collapsible messages with code (emulated). |
103 | | - for (const { programmingLanguage, text } of COLLAPSIBLE_SAMPLES) { |
| 103 | + for (const { programmingLanguage, text } of collapsibleSamples) { |
104 | 104 | await directLine.emulateIncomingActivity({ |
105 | 105 | entities: [ |
106 | 106 | { |
|
116 | 116 | }); |
117 | 117 | } |
118 | 118 |
|
119 | | - await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length); |
| 119 | + await pageConditions.numActivitiesShown(collapsibleSamples.length); |
120 | 120 |
|
121 | 121 | // WHEN: Expand every message. |
122 | 122 | for (const summary of document.querySelectorAll('summary.collapsible-content__summary')) { |
|
129 | 129 | await waitFor(() => |
130 | 130 | expect( |
131 | 131 | Array.from(document.querySelectorAll('.code-block-content pre'), pre => pre.classList.contains('shiki')) |
132 | | - ).toEqual(COLLAPSIBLE_SAMPLES.map(({ isHighlighted }) => isHighlighted)) |
| 132 | + ).toEqual(collapsibleSamples.map(({ isHighlighted }) => isHighlighted)) |
133 | 133 | ); |
134 | 134 |
|
135 | 135 | await pageConditions.scrollStabilized(); |
136 | 136 |
|
137 | 137 | // THEN: The code blocks should show the title of the programming language. |
138 | 138 | expect( |
139 | 139 | Array.from(document.querySelectorAll('.code-block-content__title'), ({ textContent }) => textContent) |
140 | | - ).toEqual(COLLAPSIBLE_SAMPLES.map(({ title }) => title)); |
| 140 | + ).toEqual(collapsibleSamples.map(({ title }) => title)); |
141 | 141 |
|
142 | | - // THEN: Should match snapshot. |
| 142 | + // THEN: The 6 expanded messages show their code under the titles JavaScript, TypeScript, C#, Shell script, Bash, and Cobol, only the first 2 highlighted. |
143 | 143 | await host.snapshot('local'); |
144 | 144 |
|
145 | 145 | // WHEN: The bot sends a message with code in "py" (emulated). |
|
155 | 155 | type: 'message' |
156 | 156 | }); |
157 | 157 |
|
158 | | - await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length + 1); |
| 158 | + await pageConditions.numActivitiesShown(collapsibleSamples.length + 1); |
159 | 159 | await pageConditions.scrollStabilized(); |
160 | 160 |
|
161 | 161 | // WHEN: Click the "View code" button. |
|
168 | 168 | 'Code sample: Python' |
169 | 169 | ); |
170 | 170 |
|
171 | | - // THEN: Should match snapshot. |
| 171 | + // THEN: The "View code" dialog shows the Python code under the "Python" title. |
172 | 172 | await host.snapshot('local'); |
173 | 173 | }); |
174 | 174 | </script> |
|
0 commit comments