From 520eee8a07d9c4ee812f0ebc67041617ac2dc0f4 Mon Sep 17 00:00:00 2001 From: Boris Serdiuk Date: Mon, 4 Sep 2023 11:48:18 +0200 Subject: [PATCH] fix: JSDOM compatibility in mixed line bar chart (#1502) --- src/internal/utils/node-belongs.ts | 5 ++++- .../__tests__/mixed-chart.test.tsx | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/internal/utils/node-belongs.ts b/src/internal/utils/node-belongs.ts index bdbc944c1c..a45c731819 100644 --- a/src/internal/utils/node-belongs.ts +++ b/src/internal/utils/node-belongs.ts @@ -15,7 +15,10 @@ export function nodeBelongs(container: Node | null, target: Node | EventTarget | if (!(target instanceof Node)) { return false; } - const portal = findUpUntil(target as HTMLElement, node => !!node.dataset.awsuiReferrerId); + const portal = findUpUntil( + target as HTMLElement, + node => node instanceof HTMLElement && !!node.dataset.awsuiReferrerId + ); const referrer = portal instanceof HTMLElement ? document.getElementById(portal.dataset.awsuiReferrerId ?? '') : null; return referrer ? nodeContains(container, referrer) : nodeContains(container, target); } diff --git a/src/mixed-line-bar-chart/__tests__/mixed-chart.test.tsx b/src/mixed-line-bar-chart/__tests__/mixed-chart.test.tsx index 555dbb94de..bfb3474fe7 100644 --- a/src/mixed-line-bar-chart/__tests__/mixed-chart.test.tsx +++ b/src/mixed-line-bar-chart/__tests__/mixed-chart.test.tsx @@ -772,7 +772,7 @@ describe('Filter', () => { describe('Dropdown', () => { const openDropdown = (wrapper: MixedLineBarChartWrapper) => { - wrapper.findDefaultFilter()?.openDropdown(); + wrapper.findDefaultFilter()!.openDropdown(); return wrapper.findDefaultFilter()!.findDropdown()!; }; @@ -804,6 +804,17 @@ describe('Filter', () => { expect(dropdownWrapper.findSelectedOptions()).toHaveLength(1); expect(dropdownWrapper.findSelectedOptions()[0].getElement()).toHaveTextContent(defaultData[1].title); }); + + test('allows filtering segments', () => { + const { wrapper } = renderMixedChart(); + + expect(wrapper.findSeries()).toHaveLength(2); + + wrapper.findDefaultFilter()!.openDropdown(); + wrapper.findDefaultFilter()!.selectOption(1); + wrapper.findDefaultFilter()!.closeDropdown(); + expect(wrapper.findSeries()).toHaveLength(1); + }); }); });