Skip to content

Commit

Permalink
fix: JSDOM compatibility in mixed line bar chart (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Sep 4, 2023
1 parent 060d090 commit 520eee8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/internal/utils/node-belongs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 12 additions & 1 deletion src/mixed-line-bar-chart/__tests__/mixed-chart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ describe('Filter', () => {

describe('Dropdown', () => {
const openDropdown = (wrapper: MixedLineBarChartWrapper) => {
wrapper.findDefaultFilter()?.openDropdown();
wrapper.findDefaultFilter()!.openDropdown();
return wrapper.findDefaultFilter()!.findDropdown()!;
};

Expand Down Expand Up @@ -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(<MixedLineBarChart series={defaultData} />);

expect(wrapper.findSeries()).toHaveLength(2);

wrapper.findDefaultFilter()!.openDropdown();
wrapper.findDefaultFilter()!.selectOption(1);
wrapper.findDefaultFilter()!.closeDropdown();
expect(wrapper.findSeries()).toHaveLength(1);
});
});
});

Expand Down

0 comments on commit 520eee8

Please sign in to comment.