Repository navigation
Show the proper title of the programming language in code samples #5896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ac0724
Show the proper title of the programming language in code samples
e2f15ea
Add PR number to changelog
9909fca
Keep shell dialect names, drop strings equal to the fallback, highlig…
66423df
Update part-grouping snapshots for the programming language title
9617233
Merge branch 'main' into OEvgeny/fix-code-block-language-title
OEvgeny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-8 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-11 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-25 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-19 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+70 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+132 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+137 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+142 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1 Byte
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+136 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+107 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+85 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+72 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <title>Code: shows the title of the programming language</title> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", | ||
| "react": "https://esm.sh/react@18", | ||
| "react-dom": "https://esm.sh/react-dom@18", | ||
| "react-dom/": "https://esm.sh/react-dom@18/" | ||
| } | ||
| } | ||
| </script> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| <script type="module"> | ||
| import React from 'react'; | ||
| window.React = React; | ||
| </script> | ||
| <script defer crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="module"> | ||
| import { waitFor } from '@testduet/wait-for'; | ||
| import React from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| const aiMessageEntity = Object.freeze({ | ||
| '@context': 'https://schema.org', | ||
| '@id': '', | ||
| '@type': 'Message', | ||
| keywords: Object.freeze(['AIGeneratedContent']), | ||
| type: 'https://schema.org/Message' | ||
| }); | ||
|
|
||
| // Programming languages are sent as-is in "programmingLanguage", often in lowercase or as an alias. | ||
| // Only JavaScript, Python, and TypeScript are highlighted by the bundled highlighter. | ||
| const COLLAPSIBLE_SAMPLES = Object.freeze([ | ||
| Object.freeze({ | ||
| isHighlighted: true, | ||
| programmingLanguage: 'javascript', | ||
| text: "console.log('Hello, World!');", | ||
| title: 'JavaScript' | ||
| }), | ||
| Object.freeze({ | ||
| isHighlighted: true, | ||
| programmingLanguage: 'TS', | ||
| text: "const greeting: string = 'Hello, World!';", | ||
| title: 'TypeScript' | ||
| }), | ||
| Object.freeze({ | ||
| isHighlighted: false, | ||
| programmingLanguage: 'c#', | ||
| text: 'Console.WriteLine("Hello, World!");', | ||
| title: 'C#' | ||
| }), | ||
| // The title of "sh" ("Shell") is overridden via "overrideLocalizedStrings" below. | ||
| Object.freeze({ | ||
| isHighlighted: false, | ||
| programmingLanguage: 'sh', | ||
| text: 'echo "Hello, World!"', | ||
| title: 'Shell script' | ||
| }), | ||
| // Shell dialects keep their own name: only the first letter is capitalized. | ||
| Object.freeze({ | ||
| isHighlighted: false, | ||
| programmingLanguage: 'bash', | ||
| text: "echo 'Hello, World!'", | ||
| title: 'Bash' | ||
| }), | ||
| // Unknown programming language: only the first letter is capitalized. | ||
| Object.freeze({ | ||
| isHighlighted: false, | ||
| programmingLanguage: 'cobol', | ||
| text: 'DISPLAY "Hello, World!".', | ||
| title: 'Cobol' | ||
| }) | ||
| ]); | ||
|
|
||
| run(async function () { | ||
| const { | ||
| WebChat: { ReactWebChat, testIds } | ||
| } = window; // Imports in UMD fashion. | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| await host.windowSize(360, 1024, document.getElementById('webchat')); | ||
|
|
||
| createRoot(document.getElementById('webchat')).render( | ||
| React.createElement(ReactWebChat, { | ||
| directLine, | ||
| overrideLocalizedStrings: { PROGRAMMING_LANGUAGE_SHELL: 'Shell script' }, | ||
| store | ||
| }) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // WHEN: The bot sends collapsible messages with code (emulated). | ||
| for (const { programmingLanguage, text } of COLLAPSIBLE_SAMPLES) { | ||
| await directLine.emulateIncomingActivity({ | ||
| entities: [ | ||
| { | ||
| ...aiMessageEntity, | ||
| abstract: `Code in ${programmingLanguage}`, | ||
| isBasedOn: { '@type': 'SoftwareSourceCode', programmingLanguage, text }, | ||
| keywords: [...aiMessageEntity.keywords, 'Collapsible'] | ||
| } | ||
| ], | ||
| from: { role: 'bot' }, | ||
| text: '', | ||
| type: 'message' | ||
| }); | ||
| } | ||
|
|
||
| await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length); | ||
|
|
||
| // WHEN: Expand every message. | ||
| for (const summary of document.querySelectorAll('summary.collapsible-content__summary')) { | ||
| await host.click(summary); | ||
|
|
||
| await waitFor(() => expect(summary.getAttribute('aria-expanded')).toBe('true')); | ||
| } | ||
|
|
||
| // THEN: Code in JavaScript and TypeScript should be highlighted, regardless of the case of the programming language. | ||
| await waitFor(() => | ||
| expect( | ||
| Array.from(document.querySelectorAll('.code-block-content pre'), pre => pre.classList.contains('shiki')) | ||
| ).toEqual(COLLAPSIBLE_SAMPLES.map(({ isHighlighted }) => isHighlighted)) | ||
| ); | ||
|
|
||
| await pageConditions.scrollStabilized(); | ||
|
|
||
| // THEN: The code blocks should show the title of the programming language. | ||
| expect( | ||
| Array.from(document.querySelectorAll('.code-block-content__title'), ({ textContent }) => textContent) | ||
| ).toEqual(COLLAPSIBLE_SAMPLES.map(({ title }) => title)); | ||
|
|
||
| // THEN: Should match snapshot. | ||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: The bot sends a message with code in "py" (emulated). | ||
| await directLine.emulateIncomingActivity({ | ||
| entities: [ | ||
| { | ||
| ...aiMessageEntity, | ||
| isBasedOn: { '@type': 'SoftwareSourceCode', programmingLanguage: 'py', text: "print('Hello, World!')" } | ||
| } | ||
| ], | ||
| from: { role: 'bot' }, | ||
| text: 'Here is a sample in Python.', | ||
| type: 'message' | ||
| }); | ||
|
|
||
| await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length + 1); | ||
| await pageConditions.scrollStabilized(); | ||
|
|
||
| // WHEN: Click the "View code" button. | ||
| await host.click(document.querySelector(`[data-testid="${testIds.viewCodeButton}"]`)); | ||
|
|
||
| // THEN: The "View code" dialog should show and be labelled with the title of the programming language. | ||
| await waitFor(() => expect(document.querySelector('dialog[open] pre.shiki')).toBeTruthy()); | ||
| expect(document.querySelector('dialog[open] h2').textContent).toBe('Python'); | ||
| await expect(testHelpers.getAccessibleName(document.querySelector('dialog[open]'))).resolves.toBe( | ||
| 'Code sample: Python' | ||
| ); | ||
|
|
||
| // THEN: Should match snapshot. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+37 Bytes
(100%)
..._/html2/markdown/codeBlock/contrast.code-block-dark.fluent.dark.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+84 Bytes
(100%)
..._/html2/markdown/codeBlock/contrast.code-block-dark.fluent.dark.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+43 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.code-block-dark.fluent.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+120 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.code-block-dark.fluent.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+98 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.code-block-dark.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+70 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.code-block-dark.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+6 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.dark.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+130 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.dark.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+45 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.dark.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
+36 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+152 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+46 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.fluent.html.snap-3.png
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+118 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+143 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+33 Bytes
(100%)
__tests__/html2/markdown/codeBlock/contrast.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
-10 Bytes
(100%)
__tests__/html2/part-grouping/copilot.dark.html.snap-8.png
Oops, something went wrong.
Binary file modified
BIN
+10 Bytes
(100%)
__tests__/html2/part-grouping/copilot.dark.html.snap-9.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.