mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Refactor packages/jaeger-ui-components/src/TraceTimelineViewer/ListView
to TS (#59873)
This commit is contained in:
parent
df4f0343e5
commit
dd406e887b
@ -14,8 +14,8 @@ exports[`no enzyme tests`] = {
|
|||||||
"packages/jaeger-ui-components/src/TracePageHeader/SpanGraph/index.test.tsx:596989456": [
|
"packages/jaeger-ui-components/src/TracePageHeader/SpanGraph/index.test.tsx:596989456": [
|
||||||
[14, 35, 13, "RegExp match", "2409514259"]
|
[14, 35, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
"packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js:1734982398": [
|
"packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.tsx:3266788928": [
|
||||||
[14, 26, 13, "RegExp match", "2409514259"]
|
[14, 56, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
"packages/jaeger-ui-components/src/TraceTimelineViewer/TimelineHeaderRow/TimelineColumnResizer.test.js:989353473": [
|
"packages/jaeger-ui-components/src/TraceTimelineViewer/TimelineHeaderRow/TimelineColumnResizer.test.js:989353473": [
|
||||||
[15, 17, 13, "RegExp match", "2409514259"]
|
[15, 17, 13, "RegExp match", "2409514259"]
|
||||||
|
@ -16,8 +16,9 @@ import Positions from './Positions';
|
|||||||
|
|
||||||
describe('Positions', () => {
|
describe('Positions', () => {
|
||||||
const bufferLen = 1;
|
const bufferLen = 1;
|
||||||
const getHeight = (i) => i * 2 + 2;
|
const getHeight = (i: number) => i * 2 + 2;
|
||||||
let ps;
|
|
||||||
|
let ps: Positions;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ps = new Positions(bufferLen);
|
ps = new Positions(bufferLen);
|
@ -12,18 +12,30 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { mount, shallow } from 'enzyme';
|
import { mount, ReactWrapper, shallow, ShallowWrapper } from 'enzyme';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { TNil } from '../../types';
|
||||||
import { polyfill as polyfillAnimationFrame } from '../../utils/test/requestAnimationFrame';
|
import { polyfill as polyfillAnimationFrame } from '../../utils/test/requestAnimationFrame';
|
||||||
|
|
||||||
import ListView from './index';
|
import ListView, { TListViewProps } from './index';
|
||||||
|
|
||||||
// Util to get list of all callbacks added to an event emitter by event type.
|
// Util to get list of all callbacks added to an event emitter by event type.
|
||||||
// jest adds "error" event listeners to window, this util makes it easier to
|
// jest adds "error" event listeners to window, this util makes it easier to
|
||||||
// ignore those calls.
|
// ignore those calls.
|
||||||
function getListenersByType(mockFn) {
|
function getListenersByType(
|
||||||
const rv = {};
|
mockFn: jest.MockContext<
|
||||||
|
void,
|
||||||
|
[
|
||||||
|
type: string,
|
||||||
|
listener: EventListenerOrEventListenerObject,
|
||||||
|
options?: boolean | AddEventListenerOptions | undefined
|
||||||
|
]
|
||||||
|
>
|
||||||
|
) {
|
||||||
|
const rv: {
|
||||||
|
[eventType: string]: EventListenerOrEventListenerObject[];
|
||||||
|
} = {};
|
||||||
mockFn.calls.forEach(([eventType, callback]) => {
|
mockFn.calls.forEach(([eventType, callback]) => {
|
||||||
if (!rv[eventType]) {
|
if (!rv[eventType]) {
|
||||||
rv[eventType] = [callback];
|
rv[eventType] = [callback];
|
||||||
@ -40,25 +52,24 @@ describe('<ListView>', () => {
|
|||||||
|
|
||||||
const DATA_LENGTH = 40;
|
const DATA_LENGTH = 40;
|
||||||
|
|
||||||
function getHeight(index) {
|
function getHeight(index: number) {
|
||||||
return index * 2 + 2;
|
return index * 2 + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Item(props) {
|
function Item(props: React.HTMLProps<HTMLDivElement>) {
|
||||||
const { children, ...rest } = props;
|
const { children, ...rest } = props;
|
||||||
return <div {...rest}>{children}</div>;
|
return <div {...rest}>{children}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderItem(itemKey, styles, itemIndex, attrs) {
|
const renderItem: TListViewProps['itemRenderer'] = (itemKey, styles, itemIndex, attrs) => {
|
||||||
return (
|
return (
|
||||||
<Item key={itemKey} style={styles} {...attrs}>
|
<Item key={itemKey} style={styles} {...attrs}>
|
||||||
{itemIndex}
|
{itemIndex}
|
||||||
</Item>
|
</Item>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
let wrapper;
|
let instance: ListView;
|
||||||
let instance;
|
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
dataLength: DATA_LENGTH,
|
dataLength: DATA_LENGTH,
|
||||||
@ -74,6 +85,7 @@ describe('<ListView>', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('shallow tests', () => {
|
describe('shallow tests', () => {
|
||||||
|
let wrapper: ShallowWrapper<TListViewProps, {}, ListView>;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<ListView {...props} />);
|
wrapper = shallow(<ListView {...props} />);
|
||||||
});
|
});
|
||||||
@ -92,10 +104,10 @@ describe('<ListView>', () => {
|
|||||||
|
|
||||||
it('sets the height of the items according to the height func', () => {
|
it('sets the height of the items according to the height func', () => {
|
||||||
const items = wrapper.find(Item);
|
const items = wrapper.find(Item);
|
||||||
const expectedHeights = [];
|
const expectedHeights: number[] = [];
|
||||||
const heights = items.map((node, i) => {
|
const heights = items.map((node, i) => {
|
||||||
expectedHeights.push(getHeight(i));
|
expectedHeights.push(getHeight(i));
|
||||||
return node.prop('style').height;
|
return node.prop('style')?.height;
|
||||||
});
|
});
|
||||||
expect(heights.length).toBe(props.initialDraw);
|
expect(heights.length).toBe(props.initialDraw);
|
||||||
expect(heights).toEqual(expectedHeights);
|
expect(heights).toEqual(expectedHeights);
|
||||||
@ -109,12 +121,13 @@ describe('<ListView>', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('mount tests', () => {
|
describe('mount tests', () => {
|
||||||
|
let wrapper: ReactWrapper<TListViewProps, {}, ListView>;
|
||||||
describe('accessor functions', () => {
|
describe('accessor functions', () => {
|
||||||
const clientHeight = 2;
|
const clientHeight = 2;
|
||||||
const scrollTop = 3;
|
const scrollTop = 3;
|
||||||
|
|
||||||
let oldRender;
|
let oldRender: () => JSX.Element;
|
||||||
let oldInitWrapper;
|
let oldInitWrapper: (elm: HTMLElement | TNil) => void;
|
||||||
const initWrapperMock = jest.fn((elm) => {
|
const initWrapperMock = jest.fn((elm) => {
|
||||||
if (elm != null) {
|
if (elm != null) {
|
||||||
// jsDom requires `defineProperties` instead of just setting the props
|
// jsDom requires `defineProperties` instead of just setting the props
|
||||||
@ -173,14 +186,28 @@ describe('<ListView>', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('windowScroller', () => {
|
describe('windowScroller', () => {
|
||||||
let windowAddListenerSpy;
|
let windowAddListenerSpy: jest.SpyInstance<
|
||||||
let windowRmListenerSpy;
|
void,
|
||||||
|
[
|
||||||
|
type: string,
|
||||||
|
listener: EventListenerOrEventListenerObject,
|
||||||
|
options?: boolean | AddEventListenerOptions | undefined
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
let windowRmListenerSpy: jest.SpyInstance<
|
||||||
|
void,
|
||||||
|
[
|
||||||
|
type: string,
|
||||||
|
listener: EventListenerOrEventListenerObject,
|
||||||
|
options?: boolean | AddEventListenerOptions | undefined
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
windowAddListenerSpy = jest.spyOn(window, 'addEventListener');
|
windowAddListenerSpy = jest.spyOn(window, 'addEventListener');
|
||||||
windowRmListenerSpy = jest.spyOn(window, 'removeEventListener');
|
windowRmListenerSpy = jest.spyOn(window, 'removeEventListener');
|
||||||
const wsProps = { ...props, windowScroller: true };
|
const wsProps = { ...props, windowScroller: true };
|
||||||
wrapper = mount(<ListView {...wsProps} />);
|
wrapper = mount(<ListView {...(wsProps as unknown as TListViewProps)} />);
|
||||||
instance = wrapper.instance();
|
instance = wrapper.instance();
|
||||||
});
|
});
|
||||||
|
|
@ -27,7 +27,7 @@ type TWrapperProps = {
|
|||||||
/**
|
/**
|
||||||
* @typedef
|
* @typedef
|
||||||
*/
|
*/
|
||||||
type TListViewProps = {
|
export type TListViewProps = {
|
||||||
/**
|
/**
|
||||||
* Number of elements in the list.
|
* Number of elements in the list.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user