Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Added jest tests for the new prop
Browse files Browse the repository at this point in the history
  • Loading branch information
MadalinaStelea committed Jun 28, 2023
1 parent 6b365f6 commit a51f768
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/terra-clinical-label-value-view/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
* Added
* Added a new prop `topicTextId` on the LabelValueView component.

* Changed
* Applied the aria-labelledby attribute on the definition list returned by the LabelValueView, to link it to a topic text defined by the consumer.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import LabelValueView from '../../src/LabelValueView';

describe('LabelValueView', () => {
const defaultView = <LabelValueView label="Label" />;
const topicText = <h4 id="topicText">Topic Text</h4>;
const viewWithTopicTextId = <LabelValueView label="Label" topicTextId="topicText" />;
const viewAsChildOfDescriptionLIst = <LabelValueView label="Label" isChildOfDescriptionList />;

// Snapshot Tests
it('should render a default LabelValueView', () => {
Expand Down Expand Up @@ -76,4 +79,28 @@ describe('LabelValueView', () => {
const wrapper = shallow(defaultView);
expect(wrapper).toMatchSnapshot();
});

it('correctly applies the aria-labelledby attribute when a topicTextId is provided', () => {
const wrapper = shallow(viewWithTopicTextId);
expect(wrapper.prop('aria-labelledby')).toEqual(topicText.props.id);
});

it('does not apply the aria-labelledby attribute when a topicTextId is not provided', () => {
const wrapper = shallow(defaultView);
expect(wrapper.prop('aria-labelledby')).toEqual(undefined);
});

it('returns a React Fragment with a term and a definition when isChildOfDescriptionList = true', () => {
const wrapper = shallow(viewAsChildOfDescriptionLIst);
expect(wrapper.type().toString()).toEqual('Symbol(react.fragment)');
expect((wrapper.childAt(0).type())).toEqual('dt');
expect(wrapper.childAt(1).type()).toEqual('dd');
});

it('returns a description list when isChildOfDescriptionList is not given', () => {
const wrapper = shallow(defaultView);
expect(wrapper.type()).toEqual('dl');
expect((wrapper.childAt(0).type())).toEqual('dt');
expect(wrapper.childAt(1).type()).toEqual('dd');
});
});

0 comments on commit a51f768

Please sign in to comment.