Skip to content

Commit 552762f

Browse files
committed
Added tests
1 parent 73903da commit 552762f

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

packages/react-core/src/components/DualListSelector/DualListSelector.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ class DualListSelector extends Component<DualListSelectorProps> {
4444
<GenerateId>
4545
{(randomId) => (
4646
<div
47-
className={css(styles.dualListSelector, hasAnimations && 'pf-m-animate-expand', className)}
47+
className={css(
48+
styles.dualListSelector,
49+
hasAnimations && isTree && styles.modifiers.animateExpand,
50+
className
51+
)}
4852
id={id || randomId}
4953
{...props}
5054
>

packages/react-core/src/components/DualListSelector/__tests__/DualListSelector.test.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1-
import { render } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
2+
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
3+
import { DualListSelector } from '../DualListSelector';
24
import { DualListSelectorPane } from '../DualListSelectorPane';
35
import { SearchInput } from '../../SearchInput';
6+
7+
// The following tests can be removed as part of https://github.com/patternfly/patternfly-react/issues/11838
8+
describe('Opt-in animations', () => {
9+
test(`Does not render with class ${styles.modifiers.animateExpand} by default`, () => {
10+
render(<DualListSelector data-testid="test-id" />);
11+
12+
expect(screen.getByTestId('test-id')).not.toHaveClass(styles.modifiers.animateExpand);
13+
});
14+
15+
test(`Does not render with class ${styles.modifiers.animateExpand} when hasAnimations is true and isTree is false`, () => {
16+
render(<DualListSelector hasAnimations data-testid="test-id" />);
17+
18+
expect(screen.getByTestId('test-id')).not.toHaveClass(styles.modifiers.animateExpand);
19+
});
20+
21+
test(`Does not render with class ${styles.modifiers.animateExpand} by default when isTree is true`, () => {
22+
render(<DualListSelector isTree data-testid="test-id" />);
23+
24+
expect(screen.getByTestId('test-id')).not.toHaveClass(styles.modifiers.animateExpand);
25+
});
26+
27+
test(`Renders with class ${styles.modifiers.animateExpand} when both isTree and hasAnimations are true`, () => {
28+
render(<DualListSelector isTree hasAnimations data-testid="test-id" />);
29+
30+
expect(screen.getByTestId('test-id')).toHaveClass(styles.modifiers.animateExpand);
31+
});
32+
});
33+
34+
// Following tests should be moved to a separate DualListSelectorPane test file
435
describe('DualListSelector', () => {
536
test('basic', () => {
637
const { asFragment } = render(<DualListSelectorPane id="basicTest" />);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { render, screen } from '@testing-library/react';
2+
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
3+
import { DualListSelectorTreeItem } from '../DualListSelectorTreeItem';
4+
5+
// The following tests checking for children to not be/to be rendered will need to be refactored
6+
// as part of https://github.com/patternfly/patternfly-react/issues/11838
7+
test('Does not render children by default', () => {
8+
render(
9+
<DualListSelectorTreeItem id="item-id" text="Test text">
10+
Children content
11+
</DualListSelectorTreeItem>
12+
);
13+
14+
expect(screen.queryByText('Children content')).not.toBeInTheDocument();
15+
});
16+
17+
test('Renders children when defaultExpanded is true', () => {
18+
render(
19+
<DualListSelectorTreeItem defaultExpanded id="item-id" text="Test text">
20+
Children content
21+
</DualListSelectorTreeItem>
22+
);
23+
24+
expect(screen.getByText('Children content')).toBeVisible();
25+
});
26+
27+
test('Renders children when hasAnimations is true', () => {
28+
render(
29+
<DualListSelectorTreeItem hasAnimations id="item-id" text="Test text">
30+
Children content
31+
</DualListSelectorTreeItem>
32+
);
33+
34+
expect(screen.getByText('Children content')).toBeVisible();
35+
});

0 commit comments

Comments
 (0)