Skip to content

Commit

Permalink
fix EuiComboBox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkajtoch committed Jul 24, 2023
1 parent 0651419 commit 695dc42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ exports[`props option.prepend & option.append renders in pills 1`] = `
Array [
<span
class="euiBadge euiComboBoxPill emotion-euiBadge-hollow"
data-test-subj="euiComboBoxPill"
title="1"
>
<span
Expand All @@ -427,6 +428,7 @@ Array [
>
<span
class="euiComboBoxPill__prepend"
data-test-subj="euiComboBoxPillPrepend"
>
Pre
</span>
Expand All @@ -448,6 +450,7 @@ Array [
</span>,
<span
class="euiBadge euiComboBoxPill emotion-euiBadge-hollow"
data-test-subj="euiComboBoxPill"
title="2"
>
<span
Expand All @@ -459,6 +462,7 @@ Array [
2
<span
class="euiComboBoxPill__append"
data-test-subj="euiComboBoxPillAppend"
>
Post
</span>
Expand All @@ -483,9 +487,11 @@ Array [
exports[`props option.prepend & option.append renders in single selection 1`] = `
<span
class="euiComboBoxPill euiComboBoxPill--plainText"
data-test-subj="euiComboBoxPill"
>
<span
class="euiComboBoxPill__prepend"
data-test-subj="euiComboBoxPillPrepend"
>
Pre
</span>
Expand Down
13 changes: 7 additions & 6 deletions src/components/combo_box/combo_box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ describe('props', () => {
];

test('renders in pills', () => {
const component = render(
const { getByTestSubject, getAllByTestSubject } = render(
<EuiComboBox options={options} selectedOptions={options} />
);

expect(component.find('.euiComboBoxPill__prepend')).toHaveLength(1);
expect(component.find('.euiComboBoxPill__append')).toHaveLength(1);
expect(component.find('.euiComboBoxPill')).toMatchSnapshot();
expect(getByTestSubject('euiComboBoxPillPrepend')).toBeInTheDocument();
expect(getByTestSubject('euiComboBoxPillAppend')).toBeInTheDocument();
expect(getAllByTestSubject('euiComboBoxPill')).toMatchSnapshot();
});

test('renders in the options dropdown', () => {
Expand All @@ -146,14 +146,15 @@ describe('props', () => {
});

test('renders in single selection', () => {
const component = render(
const { getByTestSubject } = render(
<EuiComboBox
options={options}
selectedOptions={[options[0]]}
singleSelection={{ asPlainText: true }}
/>
);
expect(component.find('.euiComboBoxPill')).toMatchSnapshot();

expect(getByTestSubject('euiComboBoxPill')).toMatchSnapshot();
});
});

Expand Down
18 changes: 15 additions & 3 deletions src/components/combo_box/combo_box_input/combo_box_pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ export class EuiComboBoxPill<T> extends Component<EuiComboBoxPillProps<T>> {
const content = (
<>
{option.prepend && (
<span className="euiComboBoxPill__prepend">{option.prepend}</span>
<span
className="euiComboBoxPill__prepend"
data-test-subj="euiComboBoxPillPrepend"
>
{option.prepend}
</span>
)}
{children}
{option.append && (
<span className="euiComboBoxPill__append">{option.append}</span>
<span
className="euiComboBoxPill__append"
data-test-subj="euiComboBoxPillAppend"
>
{option.append}
</span>
)}
</>
);
Expand All @@ -89,6 +99,7 @@ export class EuiComboBoxPill<T> extends Component<EuiComboBoxPillProps<T>> {
<EuiBadge
className={classes}
color={color}
data-test-subj="euiComboBoxPill"
iconOnClick={this.onCloseButtonClick}
iconOnClickAriaLabel={removeSelection}
iconSide="right"
Expand All @@ -106,7 +117,7 @@ export class EuiComboBoxPill<T> extends Component<EuiComboBoxPillProps<T>> {

if (asPlainText) {
return (
<span className={classes} {...rest}>
<span className={classes} data-test-subj="euiComboBoxPill" {...rest}>
{content}
</span>
);
Expand All @@ -116,6 +127,7 @@ export class EuiComboBoxPill<T> extends Component<EuiComboBoxPillProps<T>> {
<EuiBadge
className={classes}
color={color}
data-test-subj="euiComboBoxPill"
title={children}
{...rest}
{...onClickProps}
Expand Down

0 comments on commit 695dc42

Please sign in to comment.