diff --git a/e2e/screenshots/all.test.ts-snapshots/baselines/legend/legend-item-interaction-help-chrome-linux.png b/e2e/screenshots/all.test.ts-snapshots/baselines/legend/legend-item-interaction-help-chrome-linux.png new file mode 100644 index 0000000000..c557f23cb8 Binary files /dev/null and b/e2e/screenshots/all.test.ts-snapshots/baselines/legend/legend-item-interaction-help-chrome-linux.png differ diff --git a/e2e/tests/legend_stories.test.ts b/e2e/tests/legend_stories.test.ts index a5ddee3a1d..c41970e1e6 100644 --- a/e2e/tests/legend_stories.test.ts +++ b/e2e/tests/legend_stories.test.ts @@ -182,12 +182,56 @@ test.describe('Legend stories', () => { Array.from(document.getElementsByClassName('echLegendItem'), (e) => e.outerHTML), ); (await labels).forEach((label, index) => { - if (label.includes('Activate to show series')) { + const ariaInteractionLabel = label.split('; ')[1]; + if (ariaInteractionLabel && /show/.test(ariaInteractionLabel)) { hiddenResults.push(index); } }); expect(hiddenResults).toEqual([1]); }); + + test('title interactive help should change according to the legend context for the item', async ({ page }) => { + await common.loadElementFromURL(page)( + 'http://localhost:9001/?path=/story/legend--positioning&knob-position=right', + '.echLegendItem__label', + ); + + // check that the first item has a "isolate" title as second line + const initialLabels = await page.evaluate(() => + Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')), + ); + + expect(initialLabels.map((label) => (label ? label.split('\n')[1] : ''))).toEqual( + new Array(initialLabels.length).fill('Click: isolate series'), + ); + + // click on the first item + await page.keyboard.press('Tab'); + await page.keyboard.press(`Enter`); + + // now check that it has a "show all" title this time + // check that all the other items (hidden) have a "show" title + const secondRoundLabels = await page.evaluate(() => + Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')), + ); + expect(secondRoundLabels.map((label) => (label ? label.split('\n')[1] : ''))).toEqual( + ['Click: show all series'].concat(new Array(secondRoundLabels.length - 1).fill('Click: show series')), + ); + + // now click on the second item (hidden) + await page.keyboard.press('Tab'); + await page.keyboard.press(`Enter`); + + // check that the first two items have a "hide" title and the rest have a "show" title + const thirdRoundLabels = await page.evaluate(() => + Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')), + ); + expect(thirdRoundLabels.map((label) => (label ? label.split('\n')[1] : ''))).toEqual( + ['Click: hide series', 'Click: hide series'].concat( + new Array(secondRoundLabels.length - 2).fill('Click: show series'), + ), + ); + }); }); test.describe('Extra values', () => { diff --git a/packages/charts/src/components/__snapshots__/chart.test.tsx.snap b/packages/charts/src/components/__snapshots__/chart.test.tsx.snap index 3695910d87..635170f314 100644 --- a/packages/charts/src/components/__snapshots__/chart.test.tsx.snap +++ b/packages/charts/src/components/__snapshots__/chart.test.tsx.snap @@ -26,7 +26,7 @@ exports[`Chart should render the legend name test 1`] = `