Skip to content

Commit

Permalink
Remove defaultProps from AccordianText.tsx (#2612)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Part of #2596 

## Description of the changes
- 

## How was this change tested?
- 

## Checklist
- [ ] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [ ] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `npm run lint` and `npm run test`

---------

Signed-off-by: cs-308-2023 <[email protected]>
  • Loading branch information
ADI-ROXX authored Jan 26, 2025
1 parent 57f5648 commit 649ac4f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ describe('<AccordianText>', () => {
const props = {
compact: false,
data: warnings,
highContrast: false,
isOpen: false,
label: 'le-label',
onToggle: jest.fn(),
};

beforeEach(() => {
Expand All @@ -52,4 +50,33 @@ describe('<AccordianText>', () => {
expect(content.length).toBe(1);
expect(content.prop('data')).toBe(warnings);
});

it('disables onClick if data is empty', () => {
wrapper = shallow(<AccordianText {...props} data={[]} />);
const headerProps = wrapper.find('.AccordianText--header').props();
expect(headerProps.onClick).toBeNull();
});

it('has role="switch" when interactive = true', () => {
wrapper = shallow(<AccordianText {...props} isOpen />);
const headerProps = wrapper.find('.AccordianText--header').props();
expect(headerProps.role).toBe('switch');
});

it('has class "is-empty" class if data is empty', () => {
wrapper = shallow(<AccordianText {...props} data={[]} />);
expect(wrapper.find('.AccordianText--header').hasClass('is-empty')).toBe(true);
});

it('has class "is-high-contrast" class if highContrast=true', () => {
wrapper = shallow(<AccordianText {...props} highContrast />);
expect(wrapper.find('.AccordianText--header').hasClass('is-high-contrast')).toBe(true);
});

it('does not render arrow or clickable header if interactive = false', () => {
wrapper = shallow(<AccordianText {...props} interactive={false} />);
const header = wrapper.find('.AccordianText--header');
expect(header.prop('role')).toBeUndefined();
expect(header.find('.u-align-icon').exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ type AccordianTextProps = {
onToggle?: null | (() => void);
};

export default function AccordianText(props: AccordianTextProps) {
const { className, data, headerClassName, highContrast, interactive, isOpen, label, onToggle } = props;
export default function AccordianText({
className = null,
data,
headerClassName,
highContrast = false,
interactive = true,
isOpen,
label,
onToggle = null,
}: AccordianTextProps) {
const isEmpty = !Array.isArray(data) || !data.length;
const iconCls = cx('u-align-icon', { 'AccordianKeyValues--emptyIcon': isEmpty });

Expand Down Expand Up @@ -64,10 +72,3 @@ export default function AccordianText(props: AccordianTextProps) {
</div>
);
}

AccordianText.defaultProps = {
className: null,
highContrast: false,
interactive: true,
onToggle: null,
};

0 comments on commit 649ac4f

Please sign in to comment.