Convert packages/jaeger-ui-components/src/common/UiFindInput.test.js to RTL (#49994)

* Add selector

* Add test

* Remove snapshot

* Remove uiFindInput selector
This commit is contained in:
Joey Tawadrous 2022-06-02 09:46:31 +01:00 committed by GitHub
parent 52c775368b
commit 3d26502db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 56 deletions

View File

@ -98,9 +98,6 @@ exports[`no enzyme tests`] = {
"packages/jaeger-ui-components/src/TraceTimelineViewer/index.test.js:381298544": [
[14, 19, 13, "RegExp match", "2409514259"]
],
"packages/jaeger-ui-components/src/common/UiFindInput.test.js:2207118020": [
[14, 19, 13, "RegExp match", "2409514259"]
],
"packages/jaeger-ui-components/src/url/ReferenceLink.test.js:3249503373": [
[14, 26, 13, "RegExp match", "2409514259"]
],

View File

@ -12,58 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { shallow } from 'enzyme';
// eslint-disable-next-line lodash/import-scope
import _ from 'lodash';
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { Input } from '@grafana/ui';
import UiFindInput from './UiFindInput';
const debounceMock = jest.spyOn(_, 'debounce').mockImplementation((func) => {
return Object.assign(func, { cancel: jest.fn(), flush: jest.fn() });
});
describe('UiFindInput', () => {
const flushMock = jest.fn();
const uiFind = 'uiFind';
const ownInputValue = 'ownInputValue';
const props = {
uiFind: undefined,
history: {
replace: () => {},
},
location: {
search: null,
},
};
let wrapper;
beforeAll(() => {
debounceMock.mockImplementation((fn) => {
function debounceFunction(...args) {
fn(...args);
}
debounceFunction.flush = flushMock;
return debounceFunction;
});
});
beforeEach(() => {
flushMock.mockReset();
wrapper = shallow(<UiFindInput {...props} />);
});
describe('rendering', () => {
it('renders as expected', () => {
expect(wrapper).toMatchSnapshot();
it('renders as expected with no value', () => {
render(<UiFindInput value={undefined} />);
const uiFindInput = screen.queryByPlaceholderText('Find...');
expect(uiFindInput).toBeInTheDocument();
expect(uiFindInput['value']).toEqual('');
});
it('renders props.uiFind when state.ownInputValue is `undefined`', () => {
wrapper.setProps({ value: uiFind });
expect(wrapper.find(Input).prop('value')).toBe(uiFind);
it('renders as expected with value', () => {
render(<UiFindInput value="value" />);
const uiFindInput = screen.queryByPlaceholderText('Find...');
expect(uiFindInput).toBeInTheDocument();
expect(uiFindInput['value']).toEqual('value');
});
});
});

View File

@ -1,9 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UiFindInput rendering renders as expected 1`] = `
<Input
onChange={[Function]}
placeholder="Find..."
suffix={<React.Fragment />}
/>
`;