Skip to content

Commit 506adb4

Browse files
OEvgenyEugene Olonov
andauthored
Make the snapshots of recently added html2 tests easier to review (#5908)
* Make weekend html2 tests easier to review: snapshot every keyboard step and describe every snapshot - Take a snapshot after every key press in keyboard focus tests, each preceded by a THEN comment - Hide the send box where it is not under test - Replace "Should match snapshot" with what the snapshot shows - Keep test data next to the assertions that use it * Address review: snapshot after every move in carousel arrow key tests * Move carousel test helpers to testHelpers and pageConditions, split formControls arrow key test by scenario --------- Co-authored-by: Eugene Olonov <eugeneolonov@microsoft.com>
1 parent a002cbf commit 506adb4

128 files changed

Lines changed: 784 additions & 299 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎__tests__/html2/activity/programmingLanguageTitle.html‎

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,6 @@
2828
import React from 'react';
2929
import { createRoot } from 'react-dom/client';
3030

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-
8331
run(async function () {
8432
const {
8533
WebChat: { ReactWebChat, testIds }
@@ -99,8 +47,60 @@
9947

10048
await pageConditions.uiConnected();
10149

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+
102102
// WHEN: The bot sends collapsible messages with code (emulated).
103-
for (const { programmingLanguage, text } of COLLAPSIBLE_SAMPLES) {
103+
for (const { programmingLanguage, text } of collapsibleSamples) {
104104
await directLine.emulateIncomingActivity({
105105
entities: [
106106
{
@@ -116,7 +116,7 @@
116116
});
117117
}
118118

119-
await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length);
119+
await pageConditions.numActivitiesShown(collapsibleSamples.length);
120120

121121
// WHEN: Expand every message.
122122
for (const summary of document.querySelectorAll('summary.collapsible-content__summary')) {
@@ -129,17 +129,17 @@
129129
await waitFor(() =>
130130
expect(
131131
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))
133133
);
134134

135135
await pageConditions.scrollStabilized();
136136

137137
// THEN: The code blocks should show the title of the programming language.
138138
expect(
139139
Array.from(document.querySelectorAll('.code-block-content__title'), ({ textContent }) => textContent)
140-
).toEqual(COLLAPSIBLE_SAMPLES.map(({ title }) => title));
140+
).toEqual(collapsibleSamples.map(({ title }) => title));
141141

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.
143143
await host.snapshot('local');
144144

145145
// WHEN: The bot sends a message with code in "py" (emulated).
@@ -155,7 +155,7 @@
155155
type: 'message'
156156
});
157157

158-
await pageConditions.numActivitiesShown(COLLAPSIBLE_SAMPLES.length + 1);
158+
await pageConditions.numActivitiesShown(collapsibleSamples.length + 1);
159159
await pageConditions.scrollStabilized();
160160

161161
// WHEN: Click the "View code" button.
@@ -168,7 +168,7 @@
168168
'Code sample: Python'
169169
);
170170

171-
// THEN: Should match snapshot.
171+
// THEN: The "View code" dialog shows the Python code under the "Python" title.
172172
await host.snapshot('local');
173173
});
174174
</script>
-5.33 KB
Loading
-2.91 KB
Loading
11.5 KB
Loading

‎__tests__/html2/carousel/flipperButton.focusVisible.html‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
run(async function () {
3535
const { directLine, store } = testHelpers.createDirectLineEmulator();
3636
const variant = new URLSearchParams(location.search).get('variant');
37-
const webChatElement = createElement(ReactWebChat, { directLine, store });
37+
// The send box is not under test: hide it, including the send box of the Fluent theme.
38+
const webChatElement = createElement(ReactWebChat, {
39+
directLine,
40+
sendBoxMiddleware: [() => () => () => false],
41+
store
42+
});
3843

3944
createRoot(document.getElementById('webchat')).render(
4045
variant ? createElement(FluentThemeProvider, { variant }, webChatElement) : webChatElement
@@ -97,6 +102,14 @@
97102
pageObjects.focusTranscript();
98103
await host.sendKeys('ENTER');
99104

105+
// THEN: The first attachment should have the focus, both flippers should stay hidden.
106+
await waitFor(() => expect(document.activeElement).toBe(pageElements.activityAttachments()[0][0]));
107+
expect(getFlipperBodyOffset(nextFlipper)).toBe(50);
108+
expect(previousFlipper.querySelector('.react-film__main__slider--hide')).toBeTruthy();
109+
110+
// THEN: The first card shows the focus indicator, no flipper is shown.
111+
await host.snapshot('local');
112+
100113
// WHEN: Press SHIFT-TAB to move focus to the "Next" flipper.
101114
await host.sendShiftTab();
102115

@@ -106,6 +119,7 @@
106119
await waitFor(() => expect(getFlipperBodyOffset(nextFlipper)).toBe(0));
107120
expect(getFocusIndicatorStyle(nextFlipper)).toEqual(visibleFocusIndicatorStyle);
108121

122+
// THEN: The "Next" flipper shows at the right edge with a two-tone focus indicator, the first card has no focus indicator.
109123
await host.snapshot('local');
110124

111125
// WHEN: Press SHIFT-TAB to move focus to the "Previous" flipper.
@@ -123,6 +137,7 @@
123137
// THEN: The "Next" flipper should auto-hide after losing focus (1s delay, then 300ms slide out).
124138
await waitFor(() => expect(getFlipperBodyOffset(nextFlipper)).toBe(50), { timeout: 2000 });
125139

140+
// THEN: The "Previous" flipper shows at the left edge with a two-tone focus indicator, the "Next" flipper is hidden.
126141
await host.snapshot('local');
127142
});
128143
</script>
-4.85 KB
Loading
-2.36 KB
Loading
11.5 KB
Loading
479 Bytes
Loading
40 Bytes
Loading

0 commit comments

Comments
 (0)