Skip to content

Commit

Permalink
refac: migrate ReferenceLink.test.js from enzyme to RTL (jaegertracin…
Browse files Browse the repository at this point in the history
…g#1959)

## Which problem is this PR solving?
Fixes part of jaegertracing#1668 

## Description of the changes
Migrated one component to RTL

## How was this change tested?
Ran the test suite and ensured all of them pass

## 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: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com>
  • Loading branch information
EshaanAgg committed Nov 10, 2023
1 parent 8902ff4 commit 87e22ff
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';
import { fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import ReferenceLink from './ReferenceLink';

Expand All @@ -37,24 +38,22 @@ describe(ReferenceLink, () => {

describe('rendering', () => {
it('render for this trace', () => {
const component = shallow(<ReferenceLink reference={sameTraceRef} focusSpan={focusMock} />);
const link = component.find('a');
expect(link.length).toBe(1);
expect(link.props().role).toBe('button');
render(<ReferenceLink reference={sameTraceRef} focusSpan={focusMock} />);
expect(screen.getAllByRole('button').length).toBe(1);
});

it('render for external trace', () => {
const component = shallow(<ReferenceLink reference={externalRef} focusSpan={focusMock} />);
const link = component.find('a[href="/trace/trace2?uiFind=span2"]');
expect(link.length).toBe(1);
render(<ReferenceLink reference={externalRef} focusSpan={focusMock} />);
expect(screen.getByRole('link')).toHaveAttribute('href', '/trace/trace2?uiFind=span2');
});
});

describe('focus span', () => {
it('call focusSpan', () => {
focusMock.mockReset();
const component = shallow(<ReferenceLink reference={sameTraceRef} focusSpan={focusMock} />);
const link = component.find('a');
link.simulate('click');
render(<ReferenceLink reference={sameTraceRef} focusSpan={focusMock} />);

fireEvent.click(screen.getByRole('button'));
expect(focusMock).toHaveBeenLastCalledWith('span1');
});
});
Expand Down

0 comments on commit 87e22ff

Please sign in to comment.