Skip to content

Commit

Permalink
Added Tests for SearchableSelect
Browse files Browse the repository at this point in the history
Signed-off-by: Prathamesh Mutkure <pmutkure009@gmail.com>
  • Loading branch information
prathamesh-mutkure committed Oct 3, 2023
1 parent 71a1ac5 commit 388be22
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
60 changes: 60 additions & 0 deletions packages/jaeger-ui/src/components/common/SearchableSelect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2023 The Jaeger Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';

import { Select } from 'antd';
import SearchableSelect from './SearchableSelect';

describe('SearchableSelect', () => {
let wrapper;

const options = [
{ label: 'Test 1', value: 'test1' },
{ label: 'Test 2', value: 'test2' },
{ label: 'Test 3', value: 'test3' },
];

beforeEach(() => {
wrapper = shallow(
<SearchableSelect data-testid="search-select">
{options.map((option, i) => (
<Select.Option key={option.value} value={option.value} data-testid={`option-${i}`}>
{option.label}
</Select.Option>
))}
</SearchableSelect>
);
});

it('SearchableSelect renders with all props and options', () => {
expect(wrapper).toMatchSnapshot();
});

it('search is enabled', () => {
expect(wrapper.props().showSearch).toBe(true);
});

it('renders all the options correctly', () => {
const ops = wrapper.find(Select.Option);

expect(ops.length).toBe(3);

ops.forEach((op, i) => {
expect(op.props().value).toBe(options[i].value);
expect(op.props().children).toBe(options[i].label);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SearchableSelect SearchableSelect renders with all props and options 1`] = `
<ForwardRef(InternalSelect)
data-testid="search-select"
filterOption={[Function]}
showSearch={true}
>
<Option
data-testid="option-0"
key="test1"
value="test1"
>
Test 1
</Option>
<Option
data-testid="option-1"
key="test2"
value="test2"
>
Test 2
</Option>
<Option
data-testid="option-2"
key="test3"
value="test3"
>
Test 3
</Option>
</ForwardRef(InternalSelect)>
`;

0 comments on commit 388be22

Please sign in to comment.