Skip to content

Commit 835996a

Browse files
[base-components] ellipsis test
1 parent 7bbfae6 commit 835996a

File tree

79 files changed

+157
-109
lines changed

Some content is hidden

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

79 files changed

+157
-109
lines changed

semcore/base-components/__tests__/ellipsis.browser-test.tsx

Lines changed: 99 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,24 @@ Visual states, hover and focus styles, paddings, margins, and snapshots.
1616
test.describe(`${TAG.VISUAL}`, () => {
1717
test.describe('Link with ellipsis', () => {
1818
const ellipsisVariants = [
19-
{ ellipsis: true, description: 'true' },
19+
{ ellipsis: true, size: 200, description: 'true and size: 200' },
2020
{ ellipsis: { cropPosition: 'middle' }, description: 'cropPosition: middle' },
21-
{ ellipsis: { cropPosition: 'end' }, description: 'cropPosition: end' },
21+
{ ellipsis: { cropPosition: 'end' }, color: 'text-success', description: 'cropPosition: end, color: text- success' },
22+
{ ellipsis: { cropPosition: 'middle', lastRequiredSymbols: 2 }, description: 'cropPosition: middle, , lastRequiredSymbols: 2' },
2223
{ ellipsis: { cropPosition: 'end', maxLine: 2 }, description: 'cropPosition: end, maxLine: 2' },
2324
];
2425

2526
ellipsisVariants.forEach((variant) => {
26-
test(`Verify ellipsis on link with keyboard focus and mouse hover when ${variant.description}`, {
27+
test(`Verify ellipsis on link with keyboard focus when ${variant.description}`, {
2728
tag: [TAG.PRIORITY_HIGH, TAG.KEYBOARD, TAG.MOUSE, '@ellipsis', '@link'],
2829
}, async ({ page }) => {
2930
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', variant);
31+
await locators.link(page).waitFor({ state: 'visible' });
32+
await page.waitForTimeout(200);
3033

3134
await test.step('Focus link with keyboard', async () => {
3235
await page.keyboard.press('Tab');
3336
await expect(locators.link(page)).toBeFocused();
34-
});
35-
36-
await test.step('Hover link and verify hint appears', async () => {
37-
await locators.link(page).hover();
38-
const hasMaxLine = typeof variant.ellipsis === 'object' && 'maxLine' in variant.ellipsis;
39-
if (!hasMaxLine) {
40-
await locators.hint(page).waitFor({ state: 'visible' });
41-
}
4237
await expect(page).toHaveScreenshot();
4338
});
4439
});
@@ -47,9 +42,12 @@ test.describe(`${TAG.VISUAL}`, () => {
4742
tag: [TAG.PRIORITY_HIGH, TAG.MOUSE, '@ellipsis', '@link'],
4843
}, async ({ page }) => {
4944
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', variant);
45+
await page.waitForTimeout(100);
5046

5147
await test.step('Hover link and verify hint appears', async () => {
5248
await locators.link(page).hover();
49+
await page.waitForTimeout(200);
50+
5351
const hasMaxLine = typeof variant.ellipsis === 'object' && 'maxLine' in variant.ellipsis;
5452
if (!hasMaxLine) {
5553
await locators.hint(page).waitFor({ state: 'visible' });
@@ -71,6 +69,7 @@ test.describe(`${TAG.VISUAL}`, () => {
7169
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, TAG.KEYBOARD, '@ellipsis', '@link'],
7270
}, async ({ page }) => {
7371
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', variant);
72+
await page.waitForTimeout(100);
7473

7574
await test.step('Focus and hover link - no hint should appear', async () => {
7675
await page.keyboard.press('Tab');
@@ -92,8 +91,8 @@ test.describe(`${TAG.VISUAL}`, () => {
9291
{ ellipsis: { cropPosition: 'end' }, size: 600 },
9392
{ ellipsis: true, size: 700 },
9493
{ ellipsis: { cropPosition: 'end' }, size: 800 },
95-
{ ellipsis: { cropPosition: 'middle' }, size: 100 },
96-
{ ellipsis: { cropPosition: 'middle' }, size: 200 },
94+
{ ellipsis: { cropPosition: 'middle', lastRequiredSymbols: 2 }, size: 100 },
95+
{ ellipsis: { cropPosition: 'middle', lastRequiredSymbols: 7 }, size: 200 },
9796
{ ellipsis: { cropPosition: 'middle' }, size: 300 },
9897
{ ellipsis: { cropPosition: 'middle' }, size: 400 },
9998
{ ellipsis: { cropPosition: 'middle' }, size: 500 },
@@ -108,6 +107,8 @@ test.describe(`${TAG.VISUAL}`, () => {
108107
tag: [TAG.PRIORITY_HIGH, TAG.MOUSE, '@ellipsis', '@text'],
109108
}, async ({ page }) => {
110109
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/trim_with_special_text_size.tsx', 'en', variant);
110+
await locators.text(page).waitFor({ state: 'visible' });
111+
await page.waitForTimeout(200);
111112

112113
await test.step('Hover text and verify hint appears', async () => {
113114
await locators.text(page).hover();
@@ -129,6 +130,7 @@ test.describe(`${TAG.VISUAL}`, () => {
129130
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis', '@text'],
130131
}, async ({ page }) => {
131132
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/trim_with_special_text_size.tsx', 'en', variant);
133+
await page.waitForTimeout(100);
132134

133135
await test.step('Hover text - no hint should appear', async () => {
134136
await locators.text(page).hover();
@@ -139,29 +141,26 @@ test.describe(`${TAG.VISUAL}`, () => {
139141
});
140142
});
141143

142-
test('Verify ellipsis with required last symbols', {
143-
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
144-
}, async ({ page }) => {
145-
await loadPage(page, 'stories/components/base-components/ellipsis/docs/examples/with_required_last_symbols.tsx', 'en');
146-
147-
await test.step('Hover first text with lastRequiredSymbols: 5', async () => {
148-
await locators.text(page).first().hover();
149-
await locators.hint(page).waitFor({ state: 'visible' });
150-
await expect(page).toHaveScreenshot();
151-
});
152-
});
153-
154144
test('Verify basic ellipsis usage', {
155145
tag: [TAG.PRIORITY_HIGH, TAG.MOUSE, '@ellipsis'],
156146
}, async ({ page }) => {
157147
await loadPage(page, 'stories/components/base-components/ellipsis/docs/examples/basic_usage.tsx', 'en');
148+
await page.waitForTimeout(100);
158149

159150
await test.step('Hover text and verify hint appears', async () => {
160151
await locators.text(page).hover();
161152
await locators.hint(page).waitFor({ state: 'visible' });
162153
await expect(page).toHaveScreenshot();
163154
});
164155
});
156+
157+
test('Verify search highlight works well', {
158+
tag: [TAG.PRIORITY_HIGH, TAG.MOUSE, '@ellipsis'],
159+
}, async ({ page }) => {
160+
await loadPage(page, 'stories/components/base-components/ellipsis/docs/examples/with_search_selection.tsx', 'en');
161+
162+
await expect(page).toHaveScreenshot();
163+
});
165164
});
166165

167166
/* =====================================================
@@ -190,40 +189,32 @@ test.describe(`${TAG.FUNCTIONAL}`, () => {
190189
});
191190
});
192191

193-
test.skip('Verify hint shows on link focus and hides on blur', { // hint not shown
192+
test('Verify hint shows on link focus and hides when enableHintTriggerRef', {
194193
tag: [TAG.PRIORITY_HIGH, TAG.KEYBOARD, '@ellipsis', '@link'],
195194
}, async ({ page }) => {
196-
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', { ellipsis: true });
195+
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', { ellipsis: true, enableHintTriggerRef: true });
196+
await locators.link(page).waitFor({ state: 'visible' });
197+
await page.waitForTimeout(200);
197198

198199
await test.step('Focus link with keyboard - hint should appear', async () => {
199200
await page.keyboard.press('Tab');
200201
await expect(locators.link(page)).toBeFocused();
202+
await locators.hint(page).waitFor({ state: 'visible' });
203+
201204
await expect(locators.hint(page)).toHaveCount(1);
202205
});
203206

204-
await test.step('Tab away - hint should hide', async () => {
205-
await page.keyboard.press('Tab');
207+
await test.step('Escape - hint should hide', async () => {
208+
await page.keyboard.press('Escape');
206209
await expect(locators.hint(page)).toHaveCount(0);
207210
});
208211
});
209212

210-
test.skip('Verify ellipsis with maxLine multiline truncation', { // hint not shown, looks like bug
211-
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
212-
}, async ({ page }) => {
213-
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', {
214-
ellipsis: { cropPosition: 'end', maxLine: 2 },
215-
});
216-
217-
await test.step('Hover and verify hint appears for multiline', async () => {
218-
await locators.link(page).hover();
219-
await expect(locators.hint(page)).toHaveCount(1);
220-
});
221-
});
222-
223213
test('Verify no hint when text is not truncated', {
224214
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
225215
}, async ({ page }) => {
226216
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/link_with_ellipsis.tsx', 'en', { ellipsis: false });
217+
await page.waitForTimeout(100);
227218

228219
await test.step('Hover - no hint should appear', async () => {
229220
await locators.link(page).hover();
@@ -235,6 +226,7 @@ test.describe(`${TAG.FUNCTIONAL}`, () => {
235226
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
236227
}, async ({ page }) => {
237228
await loadPage(page, 'stories/components/base-components/ellipsis/docs/examples/with_required_last_symbols.tsx', 'en');
229+
await page.waitForTimeout(100);
238230

239231
await test.step('Verify first text preserves last 5 symbols', async () => {
240232
const textContent = await locators.text(page).first().textContent();
@@ -254,6 +246,7 @@ test.describe(`${TAG.FUNCTIONAL}`, () => {
254246
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
255247
}, async ({ page }) => {
256248
await loadPage(page, 'stories/components/base-components/ellipsis/docs/examples/basic_usage.tsx', 'en');
249+
await page.waitForTimeout(100);
257250

258251
await test.step('Show hint and verify it is positioned above text', async () => {
259252
const textElement = locators.text(page);
@@ -272,4 +265,68 @@ test.describe(`${TAG.FUNCTIONAL}`, () => {
272265
}
273266
});
274267
});
268+
269+
test('Verify observe children truncation', {
270+
tag: [TAG.PRIORITY_MEDIUM, TAG.MOUSE, '@ellipsis'],
271+
}, async ({ page }) => {
272+
await loadPage(page, 'stories/components/base-components/ellipsis/tests/examples/observe_children_mutations.tsx', 'en');
273+
274+
await test.step('Initial state - short text without ellipsis', async () => {
275+
const textElement = locators.text(page);
276+
await expect(textElement).toBeVisible();
277+
const textContent = await textElement.textContent();
278+
expect(textContent).toBe('Short text');
279+
280+
// No ellipsis structure initially
281+
const ariaHiddenSpan = textElement.locator('span[aria-hidden="true"]');
282+
await expect(ariaHiddenSpan).toHaveCount(0);
283+
});
284+
285+
await test.step('Click button to change text to long text', async () => {
286+
await page.getByRole('button').first().click();
287+
288+
// Wait for text to change
289+
const textElement = locators.text(page);
290+
await expect(textElement.locator('span[aria-hidden="true"]')).toBeVisible();
291+
292+
// Verify ellipsis structure appeared
293+
const ariaHiddenSpan = textElement.locator('span[aria-hidden="true"]');
294+
const ariaHiddenText = await ariaHiddenSpan.textContent();
295+
expect(ariaHiddenText).toContain('...');
296+
});
297+
298+
await test.step('Hover on ellipsis text - hint should appear with full text', async () => {
299+
await page.getByRole('button').nth(0).click();
300+
301+
const textElement = locators.text(page);
302+
await textElement.hover();
303+
304+
await locators.hint(page).waitFor({ state: 'visible' });
305+
await expect(locators.hint(page)).toHaveCount(1);
306+
307+
const hintText = await locators.hint(page).textContent();
308+
expect(hintText).toContain('This is a very long text that was changed directly in DOM');
309+
});
310+
311+
await test.step('Verify return to Initial state - short text without ellipsis', async () => {
312+
await page.mouse.move(0, 0);
313+
await locators.hint(page).waitFor({ state: 'hidden' });
314+
315+
await expect(locators.hint(page)).toHaveCount(0);
316+
317+
await page.getByRole('button').nth(1).click();
318+
319+
const textElement = locators.text(page);
320+
await expect(textElement).toBeVisible();
321+
const textContent = await textElement.textContent();
322+
expect(textContent).toBe('Short text');
323+
324+
// No ellipsis structure
325+
const ariaHiddenSpan = textElement.locator('span[aria-hidden="true"]');
326+
await expect(ariaHiddenSpan).toHaveCount(0);
327+
328+
await textElement.hover();
329+
await expect(locators.hint(page)).toHaveCount(0);
330+
});
331+
});
275332
});

semcore/base-components/__tests__/ellipsis.browser-test.tsx-snapshots/-visual-Link-with-ellipsis-Verify-ellipsis-on--ee55b-ouse-hover-when-cropPosition-end-maxLine-2-1-firefox-linux.png renamed to semcore/base-components/__tests__/ellipsis.browser-test.tsx-snapshots/-visual-Link-with-ellipsis-Verify-ellipsis-on--546aa-oard-focus-when-cropPosition-end-maxLine-2-1-firefox-linux.png

File renamed without changes.

0 commit comments

Comments
 (0)