Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Add testSkipIf and describeSkipIf #16049

Merged
merged 24 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 58 additions & 65 deletions packages/x-charts/src/BarChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { createRenderer, fireEvent } from '@mui/internal-test-utils';
import { spy } from 'sinon';
import { BarChart } from '@mui/x-charts/BarChart';
import { testSkipIf, isJSDOM } from 'test/utils/skipIf';
import { firePointerEvent } from '../tests/firePointerEvent';

const config = {
Expand All @@ -23,17 +24,12 @@ const config = {
// | X X X X
// ---A---B-

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('BarChart - click event', () => {
const { render } = createRenderer();

describe('onAxisClick', () => {
it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onAxisClick = spy();
render(
<div
Expand Down Expand Up @@ -81,62 +77,62 @@ describe('BarChart - click event', () => {
});
});

it('should provide the right context as second argument with layout="horizontal"', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
const onAxisClick = spy();
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
>
<BarChart
{...config}
layout="horizontal"
series={[
{ dataKey: 'v1', id: 's1' },
{ dataKey: 'v2', id: 's2' },
]}
yAxis={[{ scaleType: 'band', dataKey: 'x' }]}
onAxisClick={onAxisClick}
/>
</div>,
);
const svg = document.querySelector<HTMLElement>('svg')!;

firePointerEvent(svg, 'pointermove', {
clientX: 60,
clientY: 198,
});
fireEvent.click(svg);

expect(onAxisClick.lastCall.args[1]).to.deep.equal({
dataIndex: 0,
axisValue: 'A',
seriesValues: { s1: 4, s2: 2 },
});

firePointerEvent(svg, 'pointermove', {
clientX: 60,
clientY: 201,
});
fireEvent.click(svg);

expect(onAxisClick.lastCall.args[1]).to.deep.equal({
dataIndex: 1,
axisValue: 'B',
seriesValues: { s1: 1, s2: 1 },
});
});
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)(
'should provide the right context as second argument with layout="horizontal"',
() => {
const onAxisClick = spy();
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
>
<BarChart
{...config}
layout="horizontal"
series={[
{ dataKey: 'v1', id: 's1' },
{ dataKey: 'v2', id: 's2' },
]}
yAxis={[{ scaleType: 'band', dataKey: 'x' }]}
onAxisClick={onAxisClick}
/>
</div>,
);
const svg = document.querySelector<HTMLElement>('svg')!;

firePointerEvent(svg, 'pointermove', {
clientX: 60,
clientY: 198,
});
fireEvent.click(svg);

expect(onAxisClick.lastCall.args[1]).to.deep.equal({
dataIndex: 0,
axisValue: 'A',
seriesValues: { s1: 4, s2: 2 },
});

firePointerEvent(svg, 'pointermove', {
clientX: 60,
clientY: 201,
});
fireEvent.click(svg);

expect(onAxisClick.lastCall.args[1]).to.deep.equal({
dataIndex: 1,
axisValue: 'B',
seriesValues: { s1: 1, s2: 1 },
});
},
);
});

describe('onItemClick', () => {
it('should add cursor="pointer" to bar elements', function test() {
it('should add cursor="pointer" to bar elements', () => {
render(
<BarChart
{...config}
Expand All @@ -155,11 +151,8 @@ describe('BarChart - click event', () => {
).to.deep.equal(['pointer', 'pointer', 'pointer', 'pointer']);
});

it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onItemClick = spy();
render(
<div
Expand Down
9 changes: 3 additions & 6 deletions packages/x-charts/src/ChartsSurface/ChartsSurface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import * as React from 'react';
import { createRenderer } from '@mui/internal-test-utils';
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
import { expect } from 'chai';
import { describeSkipIf, isJSDOM } from 'test/utils/skipIf';
import { SizeProvider } from '../context/SizeProvider';
import { ChartProvider } from '../context/ChartProvider';

describe('<ChartsSurface />', () => {
// JSDOM doesn't implement SVGElement
if (/jsdom/.test(window.navigator.userAgent)) {
return;
}

// JSDOM doesn't implement SVGElement
describeSkipIf(isJSDOM)('<ChartsSurface />', () => {
const { render } = createRenderer();

it('should pass ref when it is added directly to component', () => {
Expand Down
36 changes: 8 additions & 28 deletions packages/x-charts/src/ChartsTooltip/contentDisplayed.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, fireEvent } from '@mui/internal-test-utils';
import { BarChart } from '@mui/x-charts/BarChart';
import { describeSkipIf, isJSDOM } from 'test/utils/skipIf';

const config = {
dataset: [
Expand All @@ -21,18 +22,12 @@ const config = {
// | X X X X
// ---A---B-

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('ChartsTooltip', () => {
const { render } = createRenderer();

describe('axis trigger', () => {
it('should show right values with vertical layout', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}

// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
describeSkipIf(isJSDOM)('axis trigger', () => {
it('should show right values with vertical layout on axis', () => {
render(
<div
style={{
Expand Down Expand Up @@ -93,12 +88,7 @@ describe('ChartsTooltip', () => {
]);
});

it('should show right values with horizontal layout', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}

it('should show right values with horizontal layout on axis', () => {
render(
<div
style={{
Expand Down Expand Up @@ -161,13 +151,8 @@ describe('ChartsTooltip', () => {
});
});

describe('item trigger', () => {
it('should show right values with vertical layout', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}

describeSkipIf(isJSDOM)('item trigger', () => {
JCQuintas marked this conversation as resolved.
Show resolved Hide resolved
it('should show right values with vertical layout on item', () => {
render(
<div
style={{
Expand Down Expand Up @@ -206,12 +191,7 @@ describe('ChartsTooltip', () => {
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S2', '1']);
});

it('should show right values with horizontal layout', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}

it('should show right values with horizontal layout on item', () => {
render(
<div
style={{
Expand Down
37 changes: 12 additions & 25 deletions packages/x-charts/src/LineChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { createRenderer, fireEvent } from '@mui/internal-test-utils';
import { spy } from 'sinon';
import { LineChart } from '@mui/x-charts/LineChart';
import { testSkipIf, isJSDOM } from 'test/utils/skipIf';
import { firePointerEvent } from '../tests/firePointerEvent';

const config = {
Expand All @@ -17,17 +18,12 @@ const config = {
height: 400,
};

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('LineChart - click event', () => {
const { render } = createRenderer();

describe('onAxisClick', () => {
it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onAxisClick = spy();
render(
<div
Expand Down Expand Up @@ -77,7 +73,7 @@ describe('LineChart - click event', () => {
});

describe('onMarkClick', () => {
it('should add cursor="pointer" to bar elements', function test() {
it('should add cursor="pointer" to bar elements', () => {
render(
<LineChart
{...config}
Expand All @@ -103,11 +99,8 @@ describe('LineChart - click event', () => {
]);
});

it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onMarkClick = spy();
render(
<div
Expand Down Expand Up @@ -155,7 +148,7 @@ describe('LineChart - click event', () => {
});

describe('onAreaClick', () => {
it('should add cursor="pointer" to bar elements', function test() {
it('should add cursor="pointer" to bar elements', () => {
render(
<LineChart
{...config}
Expand All @@ -175,11 +168,8 @@ describe('LineChart - click event', () => {
]);
});

it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onAreaClick = spy();
render(
<div
Expand Down Expand Up @@ -218,7 +208,7 @@ describe('LineChart - click event', () => {
});

describe('onLineClick', () => {
it('should add cursor="pointer" to bar elements', function test() {
it('should add cursor="pointer" to bar elements', () => {
render(
<LineChart
{...config}
Expand All @@ -238,11 +228,8 @@ describe('LineChart - click event', () => {
]);
});

it('should provide the right context as second argument', function test() {
if (isJSDOM) {
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
this.skip();
}
// can't do Pointer event with JSDom /~https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onLineClick = spy();
render(
<div
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/PieChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('PieChart - click event', () => {
const { render } = createRenderer();

describe('onItemClick', () => {
it('should add cursor="pointer" to bar elements', function test() {
it('should add cursor="pointer" to bar elements', () => {
render(
<PieChart
{...config}
Expand All @@ -37,7 +37,7 @@ describe('PieChart - click event', () => {
]);
});

it('should provide the right context as second argument', function test() {
it('should provide the right context as second argument', () => {
const onItemClick = spy();
render(
<PieChart
Expand Down
Loading
Loading