Skip to content

Commit

Permalink
[tests] Migrate TraceIDSearchInput.test from Enzyme to RTL (#1691)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- This PR migrates the `TraceIDSearchInput.test.js` from Enzyme to RTL
- Snapshot testing is replaced with specific expect statement
- Part of: #1668

## How was this change tested?
- Using yarn lint && yarn test-ci TraceIDSearchInput --coverage

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Ansh Goyal <[email protected]>
  • Loading branch information
anshgoyalevil authored Aug 16, 2023
1 parent a5c02b5 commit cebc608
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 62 deletions.
16 changes: 16 additions & 0 deletions packages/jaeger-ui/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"production": {
"plugins": [
[
"babel-plugin-react-remove-properties",
{
"properties": [
"data-testid"
]
}
]
]
}
}
}
1 change: 1 addition & 0 deletions packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"babel-jest": "^29.5.0",
"babel-plugin-inline-react-svg": "^2.0.2",
"babel-plugin-react-remove-properties": "^0.3.0",
"enzyme": "^3.8.0",
"enzyme-to-json": "^3.6.2",
"jest": "^28.1.3",
Expand Down
20 changes: 9 additions & 11 deletions packages/jaeger-ui/src/components/App/TraceIDSearchInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,40 @@
*/

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

import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import TraceIDSearchInput from './TraceIDSearchInput';

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

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

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

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

wrapper.simulate('submit');
const idInput = screen.getByPlaceholderText('Lookup by Trace ID...');
fireEvent.change(idInput, { target: { value: traceId } });
fireEvent.submit(screen.getByTestId('TraceIDSearchInput--form'));

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');
fireEvent.submit(screen.getByTestId('TraceIDSearchInput--form'));

expect(history.length).toEqual(1);
});
Expand Down
14 changes: 12 additions & 2 deletions packages/jaeger-ui/src/components/App/TraceIDSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ class TraceIDSearchInput extends React.PureComponent<Props> {

render() {
return (
<Form layout="horizontal" onSubmit={this.goToTrace} className="TraceIDSearchInput--form">
<Input name="idInput" placeholder="Lookup by Trace ID..." prefix={<Icon type="search" />} />
<Form
data-testid="TraceIDSearchInput--form"
layout="horizontal"
onSubmit={this.goToTrace}
className="TraceIDSearchInput--form"
>
<Input
data-testid="idInput"
name="idInput"
placeholder="Lookup by Trace ID..."
prefix={<Icon type="search" />}
/>
</Form>
);
}
Expand Down

This file was deleted.

6 changes: 5 additions & 1 deletion packages/jaeger-ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export default defineConfig({
},
},
plugins: [
react(),
react({
babel: {
babelrc: true,
},
}),
legacy({
targets: ['>0.5%', 'not dead', 'not ie <= 11', 'not op_mini all'],
}),
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,11 @@ babel-plugin-polyfill-regenerator@^0.5.2:
dependencies:
"@babel/helper-define-polyfill-provider" "^0.4.2"

babel-plugin-react-remove-properties@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/babel-plugin-react-remove-properties/-/babel-plugin-react-remove-properties-0.3.0.tgz#7b623fb3c424b6efb4edc9b1ae4cc50e7154b87f"
integrity sha512-vbxegtXGyVcUkCvayLzftU95vuvpYFV85pRpeMpohMHeEY46Qe0VNWfkVVcCbaZ12CXHzDFOj0esumATcW83ng==

[email protected]:
version "0.4.24"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz#f2edaf9b4c6a5fbe5c1d678bfb531078c1555f3a"
Expand Down

0 comments on commit cebc608

Please sign in to comment.