Skip to content

Commit

Permalink
add unit coverage for component TraceIDSearchInput
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Klever <[email protected]>
  • Loading branch information
tklever committed Aug 12, 2020
1 parent 6340b9a commit d9fce82
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/jaeger-ui/src/components/App/TraceIDSearchInput.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2020 Uber Technologies, Inc.
*
* 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 { mount } from 'enzyme';

import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import TraceIDSearchInput from './TraceIDSearchInput';

describe('<TraceIDSearchInput />', () => {
let wrapper;
let history;

beforeEach(() => {
history = createMemoryHistory();
wrapper = mount(
<Router history={history}>
<TraceIDSearchInput />
</Router>
).find('form');
});

it('renders as expected', () => {
expect(wrapper).toMatchSnapshot();
});

it('pushes input id to history', () => {
const idInput = wrapper.find('input');
const traceId = 'MOCK-TRACE-ID';
idInput.instance().value = traceId;

wrapper.simulate('submit');

expect(history.length).toEqual(2);
expect(history.location.pathname).toEqual(`/trace/${traceId}`);
});

it('does not push to history on falsy input value', () => {
wrapper.simulate('submit');

expect(history.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<TraceIDSearchInput /> renders as expected 1`] = `
<form
className="ant-form ant-form-horizontal TraceIDSearchInput--form"
onSubmit={[Function]}
>
<input
autosize={null}
className="ant-input"
disabled={false}
name="idInput"
onKeyDown={[Function]}
placeholder="Lookup by Trace ID..."
type="text"
/>
</form>
`;

0 comments on commit d9fce82

Please sign in to comment.