-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(accordion): refactor from enzyme to RTL * chore(test): remove enzyme --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
da1781b
commit 184d1a9
Showing
40 changed files
with
349 additions
and
814 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file removed
BIN
-74.9 KB
.yarn/cache/@wojtekmaj-enzyme-adapter-react-17-npm-0.8.0-898ccbe6bd-aa9674f06f.zip
Binary file not shown.
Binary file removed
BIN
-52.8 KB
.yarn/cache/@wojtekmaj-enzyme-adapter-utils-npm-0.2.0-733e83a927-837741f138.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-4.84 KB
.yarn/cache/discontinuous-range-npm-1.0.0-572abfd975-8ee88d7082.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-6.36 KB
.yarn/cache/enzyme-shallow-equal-npm-1.0.4-208ea272dd-54bbad0955.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-33.4 KB
.yarn/cache/react-shallow-renderer-npm-16.14.1-b8a4f845ff-f344c663c4.zip
Binary file not shown.
Binary file removed
BIN
-306 KB
.yarn/cache/react-test-renderer-npm-17.0.2-1086717127-e6b5c6ed2a.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-11.7 KB
.yarn/cache/string.prototype.trim-npm-1.2.1-d9e9f2fdd7-ff77c2b022.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
packages/react/src/components/Accordion/__tests__/Accordion.Skeleton-test.js
This file was deleted.
Oops, something went wrong.
189 changes: 98 additions & 91 deletions
189
packages/react/src/components/Accordion/__tests__/AccordionItem-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,118 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2023 | ||
* Copyright IBM Corp. 2022 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { getByText } from '@carbon/test-utils/dom'; | ||
import { render, cleanup } from '@carbon/test-utils/react'; | ||
import React from 'react'; | ||
import { Simulate } from 'react-dom/test-utils'; | ||
import AccordionItem from '../AccordionItem'; | ||
import { mount } from 'enzyme'; | ||
|
||
const prefix = 'cds'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
describe('AccordionItem', () => { | ||
afterEach(cleanup); | ||
|
||
it('should render', () => { | ||
const wrapper = mount( | ||
<AccordionItem title="A heading" className="extra-class"> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
describe('renders as expected - Component API', () => { | ||
it('should spread extra props onto outermost element', () => { | ||
const { container } = render(<AccordionItem data-testid="test-id" />); | ||
|
||
it('should update the item open state when the `open` prop changes', () => { | ||
const wrapper = mount( | ||
<AccordionItem title="A heading" open> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
|
||
expect( | ||
wrapper | ||
.find(`.${prefix}--accordion__item`) | ||
.hasClass(`${prefix}--accordion__item--active`) | ||
).toBe(true); | ||
|
||
wrapper.setProps({ open: false }); | ||
wrapper.update(); | ||
|
||
expect( | ||
wrapper | ||
.find(`.${prefix}--accordion__item`) | ||
.hasClass(`${prefix}--accordion__item--active`) | ||
).toBe(false); | ||
}); | ||
expect(container.firstChild).toHaveAttribute('data-testid', 'test-id'); | ||
}); | ||
|
||
it('should call `onClick` when the accordion list item is clicked', () => { | ||
const title = 'test title'; | ||
const onClick = jest.fn(); | ||
const { container } = render( | ||
<AccordionItem title={title} open onClick={onClick}> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
|
||
Simulate.click(getByText(container, title)); | ||
expect(onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should render and match snapshot', () => { | ||
const { container } = render( | ||
<AccordionItem title="Test title" className="extra-class"> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
|
||
it('should call `onHeadingClick` when the accordion header is clicked', () => { | ||
const onHeadingClick = jest.fn(); | ||
const wrapper = mount( | ||
<AccordionItem title="A heading" open onHeadingClick={onHeadingClick}> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
wrapper.find('button').simulate('click'); | ||
expect(onHeadingClick).toHaveBeenCalledTimes(1); | ||
}); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should support a custom `className` prop on the outermost element', () => { | ||
const { container } = render(<AccordionItem className="custom-class" />); | ||
|
||
it('should close an open AccordionItem panel when the Esc key is pressed', () => { | ||
const wrapper = mount( | ||
<AccordionItem title="A heading" open> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
wrapper.find('button').simulate('keydown', { | ||
key: 'Escape', | ||
keyCode: 27, | ||
which: 27, | ||
expect(container.firstChild).toHaveClass('custom-class'); | ||
}); | ||
|
||
it('should respect disabled prop', () => { | ||
render(<AccordionItem title="Test title" disabled />); | ||
|
||
expect(screen.getByRole('button')).toBeDisabled(); | ||
}); | ||
|
||
it('should call onClick when expected', () => { | ||
const onClick = jest.fn(); | ||
render(<AccordionItem title="Test title" onClick={onClick} />); | ||
|
||
userEvent.click(screen.getByText('Test title')); | ||
|
||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onHeadingClick prop when expected', () => { | ||
const onHeadingClick = jest.fn(); | ||
render( | ||
<AccordionItem title="Test title" onHeadingClick={onHeadingClick} /> | ||
); | ||
|
||
userEvent.click(screen.getByText('Test title')); | ||
|
||
expect(onHeadingClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should respect open prop', () => { | ||
render(<AccordionItem open />); | ||
|
||
expect(screen.getByRole('button')).toHaveAttribute( | ||
'aria-expanded', | ||
'true' | ||
); | ||
}); | ||
|
||
it('should respect renderToggle prop', () => { | ||
const renderToggle = jest.fn((props) => ( | ||
<svg {...props} data-testid="icon"> | ||
<circle cx="16" cy="16" r="8" /> | ||
</svg> | ||
)); | ||
render(<AccordionItem renderToggle={renderToggle} />); | ||
|
||
expect(renderToggle).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should respect title prop', () => { | ||
render(<AccordionItem title="Test title" />); | ||
|
||
expect(screen.getByText('Test title')).toBeInTheDocument(); | ||
}); | ||
expect( | ||
wrapper | ||
.find(`.${prefix}--accordion__item`) | ||
.hasClass(`${prefix}--accordion__item--active`) | ||
).toBe(false); | ||
}); | ||
|
||
it('should not close an open AccordionItem panel if the Esc key is pressed in the panel', () => { | ||
const wrapper = mount( | ||
<AccordionItem title="A heading" open> | ||
<input data-test-id="input" /> | ||
</AccordionItem> | ||
); | ||
wrapper.find('[data-test-id="input"]').simulate('keydown', { | ||
key: 'Escape', | ||
keyCode: 27, | ||
which: 27, | ||
describe('behaves as expected', () => { | ||
it('should close an open AccordionItem panel when the Esc key is pressed', () => { | ||
render( | ||
<AccordionItem title="A heading" open> | ||
Lorem ipsum. | ||
</AccordionItem> | ||
); | ||
userEvent.type(screen.getByRole('button'), '{esc}'); | ||
|
||
expect(screen.getByRole('button')).toHaveAttribute( | ||
'aria-expanded', | ||
'false' | ||
); | ||
}); | ||
|
||
it('should not close an open AccordionItem panel if the Esc key is pressed in the panel', () => { | ||
render( | ||
<AccordionItem title="A heading" open> | ||
<input type="text" /> | ||
</AccordionItem> | ||
); | ||
userEvent.type(screen.getByRole('textbox'), '{esc}'); | ||
expect(screen.getByRole('button')).toHaveAttribute( | ||
'aria-expanded', | ||
'true' | ||
); | ||
}); | ||
expect( | ||
wrapper | ||
.find(`.${prefix}--accordion__item`) | ||
.hasClass(`${prefix}--accordion__item--active`) | ||
).toBe(true); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
packages/react/src/components/Accordion/__tests__/AccordionSkeleton-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright IBM Corp. 2022 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import AccordionSkeleton from '../Accordion.Skeleton'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
describe('AccordionSkeleton', () => { | ||
describe('renders as expected - Component API', () => { | ||
it('should spread extra props onto outermost element', () => { | ||
const { container } = render(<AccordionSkeleton data-testid="test-id" />); | ||
|
||
expect(container.firstChild).toHaveAttribute('data-testid', 'test-id'); | ||
}); | ||
|
||
it('should render and match snapshot', () => { | ||
const { container } = render(<AccordionSkeleton />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should respect align prop', () => { | ||
const { container, rerender } = render( | ||
<AccordionSkeleton align="start" /> | ||
); | ||
expect(container.firstChild).toHaveClass('cds--accordion--start'); | ||
|
||
rerender(<AccordionSkeleton align="end" />); | ||
expect(container.firstChild).toHaveClass('cds--accordion--end'); | ||
}); | ||
|
||
it('should support a custom `className` prop on the outermost element', () => { | ||
const { container } = render( | ||
<AccordionSkeleton className="custom-class" /> | ||
); | ||
|
||
expect(container.firstChild).toHaveClass('custom-class'); | ||
}); | ||
|
||
it('should respect count prop', () => { | ||
render(<AccordionSkeleton count={8} />); | ||
|
||
expect(screen.getAllByRole('listitem').length).toBe(8); | ||
}); | ||
|
||
it('should respect isFlush prop', () => { | ||
const { container } = render(<AccordionSkeleton isFlush />); | ||
|
||
expect(container.firstChild).toHaveClass('cds--accordion--flush'); | ||
}); | ||
|
||
it('should respect open prop', () => { | ||
render(<AccordionSkeleton open />); | ||
expect(screen.getAllByRole('listitem')[0]).toHaveClass( | ||
'cds--accordion__item--active' | ||
); | ||
}); | ||
}); | ||
|
||
describe('behaves as expected', () => { | ||
// Add tests for relevant component behavior. For more information, visit https://github.com/carbon-design-system/carbon/issues/10184#issuecomment-992978122 | ||
}); | ||
}); |
Oops, something went wrong.