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

[icons] Expose a data-testid attribute on all svg icons #22634

Merged
merged 7 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('<Autocomplete />', () => {
multiple
/>,
);
fireEvent.click(container.querySelectorAll('svg[data-mui-test="CancelIcon"]')[1]);
fireEvent.click(container.querySelectorAll('svg[data-testid="CancelIcon"]')[1]);
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.deep.equal([options[0]]);
});
Expand Down
18 changes: 6 additions & 12 deletions packages/material-ui-lab/src/Pagination/Pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@ describe('<Pagination />', () => {

const buttons = getAllByRole('button');

expect(buttons[0].querySelector('svg')).to.have.attribute('data-mui-test', 'LastPageIcon');
expect(buttons[1].querySelector('svg')).to.have.attribute('data-mui-test', 'NavigateNextIcon');
expect(buttons[0].querySelector('svg')).to.have.attribute('data-testid', 'LastPageIcon');
expect(buttons[1].querySelector('svg')).to.have.attribute('data-testid', 'NavigateNextIcon');
expect(buttons[2].textContent).to.equal('1');
expect(buttons[6].textContent).to.equal('5');
expect(buttons[7].querySelector('svg')).to.have.attribute(
'data-mui-test',
'NavigateBeforeIcon',
);
expect(buttons[8].querySelector('svg')).to.have.attribute('data-mui-test', 'FirstPageIcon');
expect(buttons[7].querySelector('svg')).to.have.attribute('data-testid', 'NavigateBeforeIcon');
expect(buttons[8].querySelector('svg')).to.have.attribute('data-testid', 'FirstPageIcon');
});

it('renders correct amount of buttons on correct order when boundaryCount is zero', () => {
Expand All @@ -86,13 +83,10 @@ describe('<Pagination />', () => {
);

const buttons = getAllByRole('button');
expect(buttons[4].querySelector('svg')).to.have.attribute(
'data-mui-test',
'NavigateBeforeIcon',
);
expect(buttons[4].querySelector('svg')).to.have.attribute('data-testid', 'NavigateBeforeIcon');
expect(buttons[1].textContent).to.equal('5');
expect(buttons[2].textContent).to.equal('6');
expect(buttons[3].textContent).to.equal('7');
expect(buttons[0].querySelector('svg')).to.have.attribute('data-mui-test', 'NavigateNextIcon');
expect(buttons[0].querySelector('svg')).to.have.attribute('data-testid', 'NavigateNextIcon');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('<SpeedDialIcon />', () => {

it('should render the Add icon by default', () => {
const wrapper = mount(<SpeedDialIcon />);
expect(findOutermostIntrinsic(wrapper).find('svg[data-mui-test="AddIcon"]').length).to.equal(1);
expect(findOutermostIntrinsic(wrapper).find('svg[data-testid="AddIcon"]').length).to.equal(1);
});

it('should render an Icon', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Avatar/Avatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('<Avatar />', () => {
it('should render a div containing an svg icon', () => {
expect(avatar.tagName).to.equal('DIV');
const cancelIcon = avatar.firstChild;
expect(cancelIcon).to.have.attribute('data-mui-test', 'CancelIcon');
expect(cancelIcon).to.have.attribute('data-testid', 'CancelIcon');
});

it('should merge user classes & spread custom props to the root node', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Breadcrumbs/Breadcrumbs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('<Breadcrumbs />', () => {

expect(listitems).to.have.length(3);
expect(getByRole('list')).to.have.text('first//ninth');
expect(getByRole('button').querySelector('[data-mui-test="MoreHorizIcon"]')).not.to.equal(null);
expect(getByRole('button').querySelector('[data-testid="MoreHorizIcon"]')).not.to.equal(null);
});

it('should expand when `BreadcrumbCollapsed` is clicked', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/src/Checkbox/Checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe('<Checkbox />', () => {
describe('prop: indeterminate', () => {
it('should render an indeterminate icon', () => {
const { container } = render(<Checkbox indeterminate />);
expect(
container.querySelector('svg[data-mui-test="IndeterminateCheckBoxIcon"]'),
).not.to.equal(null);
expect(container.querySelector('svg[data-testid="IndeterminateCheckBoxIcon"]')).not.to.equal(
null,
);
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/material-ui/src/Chip/Chip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('<Chip />', () => {
<Chip label="Custom delete icon Chip" onDelete={() => {}} />,
);

const icon = container.querySelector('svg[data-mui-test="CancelIcon"]');
const icon = container.querySelector('svg[data-testid="CancelIcon"]');
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
expect(getByRole('button')).to.contain(icon);
expect(icon).to.have.class(classes.deleteIcon);
});
Expand All @@ -267,7 +267,7 @@ describe('<Chip />', () => {
<Chip label="Custom delete icon Chip" onDelete={() => {}} />,
);

const icon = container.querySelector('svg[data-mui-test="CancelIcon"]');
const icon = container.querySelector('svg[data-testid="CancelIcon"]');
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
expect(getByRole('button')).to.contain(icon);
expect(icon).to.have.class(classes.deleteIcon);
});
Expand All @@ -281,7 +281,7 @@ describe('<Chip />', () => {
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorPrimary);
const icon = chip.querySelector('svg[data-mui-test="CancelIcon"]');
const icon = chip.querySelector('svg[data-testid="CancelIcon"]');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorPrimary);
});
Expand All @@ -295,7 +295,7 @@ describe('<Chip />', () => {
expect(chip).to.have.class(classes.colorSecondary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorSecondary);
const icon = chip.querySelector('svg[data-mui-test="CancelIcon"]');
const icon = chip.querySelector('svg[data-testid="CancelIcon"]');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorSecondary);
});
Expand All @@ -306,7 +306,7 @@ describe('<Chip />', () => {
<Chip label="Custom delete icon Chip" onDelete={handleDelete} deleteIcon={<CheckBox />} />,
);

fireEvent.click(container.querySelector('svg[data-mui-test="CheckBoxIcon"]'));
fireEvent.click(container.querySelector('svg[data-testid="CheckBoxIcon"]'));
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

expect(handleDelete.callCount).to.equal(1);
});
Expand Down Expand Up @@ -534,7 +534,7 @@ describe('<Chip />', () => {
it('should render the delete icon with the deleteIcon and deleteIconSmall classes', () => {
const { container } = render(<Chip size="small" onDelete={() => {}} />);

const icon = container.querySelector('svg[data-mui-test="CancelIcon"]');
const icon = container.querySelector('svg[data-testid="CancelIcon"]');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconSmall);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/MobileStepper/MobileStepper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ describe('<MobileStepper />', () => {
const wrapper = mount(<MobileStepper {...defaultProps} />);
const backButton = wrapper.find('button[aria-label="back"]');
expect(backButton.exists()).to.equal(true);
expect(backButton.find('svg[data-mui-test="KeyboardArrowLeftIcon"]')).to.have.lengthOf(1);
expect(backButton.find('svg[data-testid="KeyboardArrowLeftIcon"]')).to.have.lengthOf(1);
});

it('should render next button', () => {
const wrapper = mount(<MobileStepper {...defaultProps} />);
const nextButton = wrapper.find('button[aria-label="next"]');
expect(nextButton.exists()).to.equal(true);
expect(nextButton.find('svg[data-mui-test="KeyboardArrowRightIcon"]')).to.have.lengthOf(1);
expect(nextButton.find('svg[data-testid="KeyboardArrowRightIcon"]')).to.have.lengthOf(1);
});

it('should render two buttons and text displaying progress when supplied with variant text', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Radio/Radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('<Radio />', () => {
it('should render an unchecked icon', () => {
const { container } = render(<Radio />);
expect(
container.querySelectorAll('svg[data-mui-test="RadioButtonUncheckedIcon"]').length,
container.querySelectorAll('svg[data-testid="RadioButtonUncheckedIcon"]').length,
).to.equal(1);
});
});
Expand All @@ -43,7 +43,7 @@ describe('<Radio />', () => {
it('should render a checked icon', () => {
const { container } = render(<Radio checked />);
expect(
container.querySelectorAll('svg[data-mui-test="RadioButtonCheckedIcon"]').length,
container.querySelectorAll('svg[data-testid="RadioButtonCheckedIcon"]').length,
).to.equal(1);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/StepIcon/StepIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ describe('<StepIcon />', () => {
it('renders <CheckCircle> when completed', () => {
const { container } = render(<StepIcon completed icon={1} />);

expect(container.querySelectorAll('svg[data-mui-test="CheckCircleIcon"]')).to.have.length(1);
expect(container.querySelectorAll('svg[data-testid="CheckCircleIcon"]')).to.have.length(1);
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
});

it('renders <Warning> when error occurred', () => {
const { container } = render(<StepIcon icon={1} error />);
expect(container.querySelectorAll('svg[data-mui-test="WarningIcon"]')).to.have.length(1);
expect(container.querySelectorAll('svg[data-testid="WarningIcon"]')).to.have.length(1);
});

it('contains text "3" when position is "3"', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/StepLabel/StepLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('<StepLabel />', () => {

const icon = container.querySelector(`.${iconClasses.root}`);
// Should render WarningIcon instead of CheckCircleIcon because of { error: true } props
expect(icon).to.have.attribute('data-mui-test').equal('WarningIcon');
expect(icon).to.have.attribute('data-testid').equal('WarningIcon');
});
});

Expand All @@ -65,7 +65,7 @@ describe('<StepLabel />', () => {

getByTestId('custom-icon');
expect(icon).to.not.equal(null);
expect(icon).to.not.have.attribute('data-mui-test').equal('CheckCircleIcon');
expect(icon).to.not.have.attribute('data-testid').equal('CheckCircleIcon');
expect(label).to.have.class(classes.active);
expect(label).to.have.class(classes.completed);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('<TabScrollButton />', () => {
<TabScrollButton {...defaultProps} {...defaultProps} direction="left" disabled />,
);
expect(
container.querySelectorAll('svg[data-mui-test="KeyboardArrowLeftIcon"]').length,
container.querySelectorAll('svg[data-testid="KeyboardArrowLeftIcon"]').length,
).to.equal(1);
});

Expand All @@ -52,7 +52,7 @@ describe('<TabScrollButton />', () => {
<TabScrollButton {...defaultProps} {...defaultProps} direction="right" disabled />,
);
expect(
container.querySelectorAll('svg[data-mui-test="KeyboardArrowRightIcon"]').length,
container.querySelectorAll('svg[data-testid="KeyboardArrowRightIcon"]').length,
).to.equal(1);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('<TableSortLabel />', () => {

it('should accept a custom icon for the sort icon', () => {
const { container } = render(<TableSortLabel IconComponent={SortIcon} />);
const icon = container.querySelector(`svg.${classes.icon}[data-mui-test="SortIcon"]`);
const icon = container.querySelector(`svg.${classes.icon}[data-testid="SortIcon"]`);
expect(icon).to.not.equal(null);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Tabs/Tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Tabs from './Tabs';
import { createMuiTheme, ThemeProvider } from '../styles';

function findScrollButton(container, direction) {
return container.querySelector(`svg[data-mui-test="KeyboardArrow${capitalize(direction)}Icon"]`);
return container.querySelector(`svg[data-testid="KeyboardArrow${capitalize(direction)}Icon"]`);
}

function hasLeftScrollButton(container) {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/createSvgIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SvgIcon from '../SvgIcon';
*/
export default function createSvgIcon(path, displayName) {
const Component = (props, ref) => (
<SvgIcon data-mui-test={`${displayName}Icon`} ref={ref} {...props}>
<SvgIcon data-testid={`${displayName}Icon`} ref={ref} {...props}>
{path}
</SvgIcon>
);
Expand Down