-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[test] Remove data-mui-test from tests #23498
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ describe('<Backdrop />', () => { | |
|
||
it('should render a backdrop div with content of nested children', () => { | ||
const { container } = render( | ||
<Backdrop open className="woofBackdrop"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by removal of unused props |
||
<Backdrop open> | ||
<h1>Hello World</h1> | ||
</Backdrop>, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
act, | ||
createClientRender, | ||
fireEvent, | ||
screen, | ||
} from 'test/utils'; | ||
import Modal from '../Modal'; | ||
import Dialog from './Dialog'; | ||
|
@@ -25,17 +26,17 @@ function userClick(element) { | |
} | ||
|
||
/** | ||
* @param {HTMLElement} container | ||
* @param {typeof import('test/utils').screen} view | ||
*/ | ||
function findBackdrop(container) { | ||
return container.querySelector('[data-mui-test="FakeBackdrop"]'); | ||
function findBackdrop(view) { | ||
return view.getByRole('dialog').parentElement; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} container | ||
* @param {typeof import('test/utils').screen} view | ||
*/ | ||
function clickBackdrop(container) { | ||
userClick(findBackdrop(container)); | ||
function clickBackdrop(view) { | ||
userClick(findBackdrop(view)); | ||
} | ||
|
||
describe('<Dialog />', () => { | ||
|
@@ -108,7 +109,9 @@ describe('<Dialog />', () => { | |
dialog.click(); | ||
}); | ||
|
||
fireEvent.keyDown(document.querySelector('[data-mui-test="FakeBackdrop"]'), { key: 'Esc' }); | ||
// keyDown not targetted at anything specific | ||
// eslint-disable-next-line material-ui/disallow-active-element-as-key-event-target | ||
fireEvent.keyDown(document.activeElement, { key: 'Esc' }); | ||
expect(onEscapeKeyDown.calledOnce).to.equal(true); | ||
expect(onClose.calledOnce).to.equal(true); | ||
|
||
|
@@ -136,30 +139,22 @@ describe('<Dialog />', () => { | |
|
||
act(() => { | ||
dialog.click(); | ||
fireEvent.keyDown(document.querySelector('[data-mui-test="FakeBackdrop"]'), { key: 'Esc' }); | ||
// keyDown is not targetted at anything specific. | ||
// eslint-disable-next-line material-ui/disallow-active-element-as-key-event-target | ||
fireEvent.keyDown(document.activeElement, { key: 'Esc' }); | ||
}); | ||
|
||
expect(onClose.callCount).to.equal(0); | ||
|
||
clickBackdrop(document.body); | ||
clickBackdrop(screen); | ||
expect(onClose.callCount).to.equal(0); | ||
}); | ||
|
||
it('should spread custom props on the modal root node', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by removal of a duplicate test (describeConformance covers this case). |
||
render( | ||
<Dialog data-my-prop="woofDialog" open> | ||
foo | ||
</Dialog>, | ||
); | ||
const modal = document.querySelector('[data-mui-test="Modal"]'); | ||
expect(modal).to.have.attribute('data-my-prop', 'woofDialog'); | ||
}); | ||
|
||
describe('backdrop', () => { | ||
it('does have `role` `none presentation`', () => { | ||
render(<Dialog open>foo</Dialog>); | ||
|
||
expect(findBackdrop(document.body)).to.have.attribute('role', 'none presentation'); | ||
expect(findBackdrop(screen)).to.have.attribute('role', 'none presentation'); | ||
}); | ||
|
||
it('calls onBackdropClick and onClose when clicked', () => { | ||
|
@@ -171,7 +166,7 @@ describe('<Dialog />', () => { | |
</Dialog>, | ||
); | ||
|
||
clickBackdrop(document); | ||
clickBackdrop(screen); | ||
expect(onBackdropClick.callCount).to.equal(1); | ||
expect(onClose.callCount).to.equal(1); | ||
}); | ||
|
@@ -198,7 +193,7 @@ describe('<Dialog />', () => { | |
); | ||
|
||
fireEvent.mouseDown(getByRole('heading')); | ||
findBackdrop(document.body).click(); | ||
findBackdrop(screen).click(); | ||
expect(getByRole('dialog')).not.to.equal(null); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,11 +178,11 @@ describe('<Popover />', () => { | |
|
||
it('uses Grow as the Transition of the modal', () => { | ||
const wrapper = mount( | ||
<Popover {...defaultProps} open> | ||
<Popover {...defaultProps} open data-testid="Modal"> | ||
<div /> | ||
</Popover>, | ||
); | ||
const modal = wrapper.find('[data-mui-test="Modal"]'); | ||
const modal = wrapper.find('[data-testid="Modal"]'); | ||
const transition = modal.find(Grow); | ||
|
||
expect(transition.exists()).to.equal(true); | ||
|
@@ -332,9 +332,10 @@ describe('<Popover />', () => { | |
anchorEl={anchorEl} | ||
anchorOrigin={anchorOrigin} | ||
transitionDuration={0} | ||
PaperProps={{ 'data-testid': 'Popover' }} | ||
TransitionProps={{ | ||
onEntered: () => { | ||
popoverEl = document.querySelector('[data-mui-test="Popover"]'); | ||
popoverEl = document.querySelector('[data-testid="Popover"]'); | ||
resolve(); | ||
}, | ||
}} | ||
|
@@ -348,9 +349,8 @@ describe('<Popover />', () => { | |
}; | ||
|
||
expectPopover = (top, left) => { | ||
expect(popoverEl.style.top).to.equal(`${top}px`); | ||
expect(popoverEl).toHaveInlineStyle({ top: `${top}px`, left: `${left}px` }); | ||
|
||
expect(popoverEl.style.left).to.equal(`${left}px`); | ||
wrapper.unmount(); | ||
}; | ||
}); | ||
|
@@ -473,9 +473,10 @@ describe('<Popover />', () => { | |
anchorPosition={anchorPosition} | ||
anchorOrigin={anchorOrigin} | ||
transitionDuration={0} | ||
PaperProps={{ 'data-testid': 'Popover' }} | ||
TransitionProps={{ | ||
onEntered: () => { | ||
popoverEl = document.querySelector('[data-mui-test="Popover"]'); | ||
popoverEl = document.querySelector('[data-testid="Popover"]'); | ||
resolve(); | ||
}, | ||
}} | ||
|
@@ -487,9 +488,11 @@ describe('<Popover />', () => { | |
}); | ||
|
||
expectPopover = (top, left) => { | ||
expect(popoverEl.style.top).to.equal(`${top}px`); | ||
expect(popoverEl).toHaveInlineStyle({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated refactor while I was working with the test. |
||
top: `${top}px`, | ||
left: `${left}px`, | ||
}); | ||
|
||
expect(popoverEl.style.left).to.equal(`${left}px`); | ||
wrapper.unmount(); | ||
}; | ||
}); | ||
|
@@ -521,11 +524,12 @@ describe('<Popover />', () => { | |
transitionDuration={0} | ||
TransitionProps={{ | ||
onEntered: () => { | ||
popoverEl = document.querySelector('[data-mui-test="Popover"]'); | ||
popoverEl = document.querySelector('[data-testid="Popover"]'); | ||
resolve(); | ||
}, | ||
}} | ||
PaperProps={{ | ||
'data-testid': 'Popover', | ||
style: { | ||
top: 11, | ||
left: 12, | ||
|
@@ -539,9 +543,11 @@ describe('<Popover />', () => { | |
}); | ||
|
||
expectPopover = (top, left) => { | ||
expect(popoverEl.style.top).to.equal(`${top}px`); | ||
expect(popoverEl).toHaveInlineStyle({ | ||
top: `${top}px`, | ||
left: `${left}px`, | ||
}); | ||
|
||
expect(popoverEl.style.left).to.equal(`${left}px`); | ||
wrapper.unmount(); | ||
}; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only change touching pickers since I didn't need to alter pickers implementation