level_0
int64
0
10k
index
int64
0
0
repo_id
stringlengths
22
152
file_path
stringlengths
41
203
content
stringlengths
11
11.5M
7,129
0
petrpan-code/airbnb/visx/packages/visx-annotation
petrpan-code/airbnb/visx/packages/visx-annotation/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,149
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/Axis.test.tsx
import React from 'react'; import { shallow, ShallowWrapper } from 'enzyme'; import { render } from '@testing-library/react'; import { Line } from '@visx/shape'; import { Text } from '@visx/text'; import { scaleBand, scaleLinear } from '@visx/scale'; import { Axis } from '../src'; const getTickLine = ( wrapper: ShallowWrapper<unknown, Readonly<{}>, React.Component<{}, {}, unknown>>, ) => wrapper.children().find('.visx-axis-tick').not('.visx-axis-line').find('Line').first(); const axisProps = { orientation: 'left' as const, scale: scaleLinear({ range: [10, 0], round: true, domain: [0, 10], }), label: 'test axis', }; describe('<Axis />', () => { it('should be defined', () => { expect(Axis).toBeDefined(); }); it('should render with class .visx-axis', () => { const wrapper = shallow(<Axis {...axisProps} />); expect(wrapper.prop('className')).toBe('visx-axis'); }); it('should call children function with required args', () => { const mockFn = jest.fn(); shallow(<Axis {...axisProps}>{mockFn}</Axis>); const args = mockFn.mock.calls[0][0]; expect(args.axisFromPoint).toBeDefined(); expect(args.axisToPoint).toBeDefined(); expect(args.horizontal).toBeDefined(); expect(args.tickSign).toBeDefined(); expect(args.numTicks).toBeDefined(); expect(args.label).toBeDefined(); expect(args.rangePadding).toBeDefined(); expect(args.tickLength).toBeDefined(); expect(args.tickFormat).toBeDefined(); expect(args.tickPosition).toBeDefined(); expect(args.ticks).toBeDefined(); expect(Object.keys(args.ticks[0])).toEqual(['value', 'index', 'from', 'to', 'formattedValue']); }); it('should set user-specified axisClassName, axisLineClassName, labelClassName, and tickClassName', () => { const axisClassName = 'axis-test-class'; const axisLineClassName = 'axisline-test-class'; const labelClassName = 'label-test-class'; const tickClassName = 'tick-test-class'; const wrapper = shallow( <Axis {...axisProps} axisClassName={axisClassName} axisLineClassName={axisLineClassName} labelClassName={labelClassName} tickClassName={tickClassName} />, ).dive(); expect(wrapper.find(`.${axisClassName}`)).toHaveLength(1); expect(wrapper.find(`.${axisLineClassName}`)).toHaveLength(1); expect(wrapper.find(`.${labelClassName}`)).toHaveLength(1); expect(wrapper.find(`.${tickClassName}`).length).toBeGreaterThan(0); }); it('should pass the output of tickLabelProps to tick labels', () => { const tickProps = { fontSize: 50, fill: 'magenta' }; const wrapper = shallow(<Axis {...axisProps} tickLabelProps={() => tickProps} />); const ticks = wrapper.find('.visx-axis-tick'); ticks.forEach((tick) => { expect(tick.find(Text).props()).toEqual(expect.objectContaining(tickProps)); }); expect.hasAssertions(); }); it('should call the tickLabelProps func with the signature (value, index, values)', () => { expect.hasAssertions(); shallow( <Axis {...axisProps} tickLabelProps={(value, index, values) => { expect(value).toEqual(expect.any(Number)); expect(index).toBeGreaterThan(-1); expect(values).toEqual( expect.arrayContaining([ expect.objectContaining({ value: expect.any(Number), index: expect.any(Number), }), ]), ); return {}; }} />, ); expect.hasAssertions(); }); it('should pass labelProps to the axis label', () => { const labelProps = { fontSize: 50, fill: 'magenta' }; const wrapper = shallow(<Axis {...axisProps} labelProps={labelProps} />); const label = wrapper.find('.visx-axis-label'); expect(label.find(Text).props()).toEqual(expect.objectContaining(labelProps)); }); it('should render the 0th tick if hideZero is false', () => { const wrapper = shallow(<Axis {...axisProps} hideZero={false} />); expect(wrapper.find('.visx-axis-tick').at(0).key()).toBe('visx-tick-0-0'); }); it('should not show 0th tick if hideZero is true', () => { const wrapper = shallow(<Axis {...axisProps} hideZero />); expect(wrapper.find('.visx-axis-tick').at(0).key()).toBe('visx-tick-1-0'); }); it('should SHOW an axis line if hideAxisLine is false', () => { const wrapper = shallow(<Axis {...axisProps} hideAxisLine={false} />); expect(wrapper.children().not('.visx-axis-tick').find('.visx-axis-line')).toHaveLength(1); }); it('should HIDE an axis line if hideAxisLine is true', () => { const wrapper = shallow(<Axis {...axisProps} hideAxisLine />); expect(wrapper.children().not('.visx-axis-tick').find('Line')).toHaveLength(0); }); it('should SHOW ticks if hideTicks is false', () => { const wrapper = shallow(<Axis {...axisProps} hideTicks={false} />); expect(wrapper.children().find('.visx-axis-tick').length).toBeGreaterThan(0); }); it('should HIDE ticks if hideTicks is true', () => { const wrapper = shallow(<Axis {...axisProps} hideTicks />); expect(wrapper.children().find('.visx-axis-tick').find('Line')).toHaveLength(0); }); it('should render one tick for each value specified in tickValues', () => { let wrapper = shallow(<Axis {...axisProps} tickValues={[]} />); expect( wrapper.children().find('.visx-axis-tick').not('.visx-axis-line').find('Line'), ).toHaveLength(0); wrapper = shallow(<Axis {...axisProps} tickValues={[2]} />); expect(wrapper.children().find('.visx-axis-tick')).toHaveLength(1); wrapper = shallow(<Axis {...axisProps} tickValues={[0, 1, 2, 3, 4, 5, 6]} />); expect(wrapper.children().find('.visx-axis-tick')).toHaveLength(7); }); it('should use tickFormat to format ticks if passed', () => { const wrapper = shallow(<Axis {...axisProps} tickValues={[0]} tickFormat={() => 'test!!!'} />); expect(wrapper.children().find('.visx-axis-tick').find(Text).prop('children')).toBe('test!!!'); }); test('tickFormat should have access to tick index', () => { const wrapper = shallow( <Axis {...axisProps} tickValues={[9]} tickFormat={(val, i) => `${i}`} />, ); expect(wrapper.children().find('.visx-axis-tick').find(Text).prop('children')).toBe('0'); }); test('tick default should follow parent', () => { const wrapper = shallow(<Axis {...axisProps} strokeWidth={2} />); expect(getTickLine(wrapper).prop('strokeWidth')).toBe(2); expect(getTickLine(wrapper).prop('strokeLinecap')).toBe('square'); }); test('tick stroke width should be different parent and equal to tickStrokeWidth', () => { const wrapper = shallow( <Axis {...axisProps} strokeWidth={2} tickLineProps={{ strokeWidth: 3, strokeLinecap: 'round' }} />, ); expect(getTickLine(wrapper).prop('strokeWidth')).toBe(3); expect(getTickLine(wrapper).prop('strokeLinecap')).toBe('round'); }); test('default tick stroke width should be 1', () => { const wrapper = shallow(<Axis {...axisProps} />); expect(getTickLine(wrapper).prop('strokeWidth')).toBe(1); }); it('should use center if scale is band', () => { const wrapper = shallow( <Axis orientation="bottom" scale={scaleBand({ range: [10, 0], round: true, domain: ['a', 'b'], })} tickStroke="blue" />, ); const points = wrapper.children().find(Line); // First point expect(points.at(0).prop('from')).toEqual({ x: 8, y: 0 }); expect(points.at(0).prop('to')).toEqual({ x: 8, y: 8 }); // Second point expect(points.at(1).prop('from')).toEqual({ x: 3, y: 0 }); expect(points.at(1).prop('to')).toEqual({ x: 3, y: 8 }); // Third point expect(points.at(2).prop('from')).toEqual({ x: 10.5, y: 0 }); expect(points.at(2).prop('to')).toEqual({ x: 0.5, y: 0 }); }); test('should expose its ref via an innerRef prop', () => { const fakeRef = React.createRef<SVGGElement>(); const { container } = render( <svg> <Axis {...axisProps} innerRef={fakeRef} /> </svg>, ); const AxisGroupElement = container.querySelector('g.visx-axis'); expect(fakeRef.current).toBe(AxisGroupElement); }); });
7,150
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/AxisBottom.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Axis, AxisBottom } from '../src'; const axisProps = { scale: scaleLinear({ range: [10, 0], round: true, domain: [0, 10], }), }; describe('<AxisBottom />', () => { it('should be defined', () => { expect(AxisBottom).toBeDefined(); }); it('should render with class .visx-axis-bottom', () => { const wrapper = shallow(<AxisBottom {...axisProps} />); expect(wrapper.prop('axisClassName')).toBe('visx-axis-bottom'); }); it('should set user-specified axisClassName, axisLineClassName, labelClassName, and tickClassName', () => { const axisClassName = 'axis-test-class'; const axisLineClassName = 'axisline-test-class'; const labelClassName = 'label-test-class'; const tickClassName = 'tick-test-class'; const wrapper = shallow( <AxisBottom {...axisProps} axisClassName={axisClassName} axisLineClassName={axisLineClassName} labelClassName={labelClassName} tickClassName={tickClassName} />, ); const axis = wrapper.find(Axis); expect(axis.prop('axisClassName')).toMatch(axisClassName); expect(axis.prop('axisLineClassName')).toBe(axisLineClassName); expect(axis.prop('labelClassName')).toBe(labelClassName); expect(axis.prop('tickClassName')).toBe(tickClassName); }); it('should default labelOffset prop to 8', () => { const wrapper = shallow(<AxisBottom {...axisProps} />); expect(wrapper.prop('labelOffset')).toBe(8); }); it('should set labelOffset prop', () => { const labelOffset = 3; const wrapper = shallow(<AxisBottom {...axisProps} labelOffset={labelOffset} />); expect(wrapper.prop('labelOffset')).toEqual(labelOffset); }); it('should default tickLength prop to 8', () => { const wrapper = shallow(<AxisBottom {...axisProps} />); expect(wrapper.prop('tickLength')).toBe(8); }); it('should set tickLength prop', () => { const tickLength = 15; const wrapper = shallow(<AxisBottom {...axisProps} tickLength={tickLength} />); expect(wrapper.prop('tickLength')).toEqual(tickLength); }); it('should set label prop', () => { const label = 'test'; const wrapper = shallow(<AxisBottom {...axisProps} label={label} />).dive(); const text = wrapper.find('.visx-axis-label'); expect(text.prop('children')).toEqual(label); }); });
7,151
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/AxisLeft.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Axis, AxisLeft } from '../src'; const axisProps = { scale: scaleLinear({ range: [10, 0], round: true, domain: [0, 10], }), }; describe('<AxisLeft />', () => { it('should be defined', () => { expect(AxisLeft).toBeDefined(); }); it('should render with class .visx-axis-left', () => { const wrapper = shallow(<AxisLeft {...axisProps} />); expect(wrapper.prop('axisClassName')).toBe('visx-axis-left'); }); it('should set user-specified axisClassName, axisLineClassName, labelClassName, and tickClassName', () => { const axisClassName = 'axis-test-class'; const axisLineClassName = 'axisline-test-class'; const labelClassName = 'label-test-class'; const tickClassName = 'tick-test-class'; const wrapper = shallow( <AxisLeft {...axisProps} axisClassName={axisClassName} axisLineClassName={axisLineClassName} labelClassName={labelClassName} tickClassName={tickClassName} />, ); const axis = wrapper.find(Axis); expect(axis.prop('axisClassName')).toMatch(axisClassName); expect(axis.prop('axisLineClassName')).toBe(axisLineClassName); expect(axis.prop('labelClassName')).toBe(labelClassName); expect(axis.prop('tickClassName')).toBe(tickClassName); }); it('should default labelOffset prop to 36', () => { const wrapper = shallow(<AxisLeft {...axisProps} />); expect(wrapper.prop('labelOffset')).toBe(36); }); it('should set labelOffset prop', () => { const labelOffset = 3; const wrapper = shallow(<AxisLeft {...axisProps} labelOffset={labelOffset} />); expect(wrapper.prop('labelOffset')).toEqual(labelOffset); }); it('should default tickLength prop to 8', () => { const wrapper = shallow(<AxisLeft {...axisProps} />); expect(wrapper.prop('tickLength')).toBe(8); }); it('should set tickLength prop', () => { const tickLength = 15; const wrapper = shallow(<AxisLeft {...axisProps} tickLength={tickLength} />); expect(wrapper.prop('tickLength')).toEqual(tickLength); }); it('should set label prop', () => { const label = 'test'; const wrapper = shallow(<AxisLeft {...axisProps} label={label} />).dive(); const text = wrapper.find('.visx-axis-label'); expect(text.prop('children')).toEqual(label); }); });
7,152
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/AxisRight.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Axis, AxisRight } from '../src'; const axisProps = { scale: scaleLinear({ range: [10, 0], round: true, domain: [0, 10], }), }; describe('<AxisRight />', () => { it('should be defined', () => { expect(AxisRight).toBeDefined(); }); it('should render with class .visx-axis-right', () => { const wrapper = shallow(<AxisRight {...axisProps} />); expect(wrapper.prop('axisClassName')).toBe('visx-axis-right'); }); it('should set user-specified axisClassName, axisLineClassName, labelClassName, and tickClassName', () => { const axisClassName = 'axis-test-class'; const axisLineClassName = 'axisline-test-class'; const labelClassName = 'label-test-class'; const tickClassName = 'tick-test-class'; const wrapper = shallow( <AxisRight {...axisProps} axisClassName={axisClassName} axisLineClassName={axisLineClassName} labelClassName={labelClassName} tickClassName={tickClassName} />, ); const axis = wrapper.find(Axis); expect(axis.prop('axisClassName')).toMatch(axisClassName); expect(axis.prop('axisLineClassName')).toBe(axisLineClassName); expect(axis.prop('labelClassName')).toBe(labelClassName); expect(axis.prop('tickClassName')).toBe(tickClassName); }); it('should default labelOffset prop to 36', () => { const wrapper = shallow(<AxisRight {...axisProps} />); expect(wrapper.prop('labelOffset')).toBe(36); }); it('should set labelOffset prop', () => { const labelOffset = 3; const wrapper = shallow(<AxisRight {...axisProps} labelOffset={labelOffset} />); expect(wrapper.prop('labelOffset')).toEqual(labelOffset); }); it('should default tickLength prop to 8', () => { const wrapper = shallow(<AxisRight {...axisProps} />); expect(wrapper.prop('tickLength')).toBe(8); }); it('should set tickLength prop', () => { const tickLength = 15; const wrapper = shallow(<AxisRight {...axisProps} tickLength={tickLength} />); expect(wrapper.prop('tickLength')).toEqual(tickLength); }); it('should set label prop', () => { const label = 'test'; const wrapper = shallow(<AxisRight {...axisProps} label={label} />).dive(); const text = wrapper.find('.visx-axis-label'); expect(text.prop('children')).toEqual(label); }); });
7,153
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/AxisTop.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Axis, AxisTop } from '../src'; const axisProps = { scale: scaleLinear({ range: [10, 0], round: true, domain: [0, 10], }), }; describe('<AxisTop />', () => { it('should be defined', () => { expect(AxisTop).toBeDefined(); }); it('should render with class .visx-axis-top', () => { const wrapper = shallow(<AxisTop {...axisProps} />); expect(wrapper.prop('axisClassName')).toBe('visx-axis-top'); }); it('should set user-specified axisClassName, axisLineClassName, labelClassName, and tickClassName', () => { const axisClassName = 'axis-test-class'; const axisLineClassName = 'axisline-test-class'; const labelClassName = 'label-test-class'; const tickClassName = 'tick-test-class'; const wrapper = shallow( <AxisTop {...axisProps} axisClassName={axisClassName} axisLineClassName={axisLineClassName} labelClassName={labelClassName} tickClassName={tickClassName} />, ); const axis = wrapper.find(Axis); expect(axis.prop('axisClassName')).toMatch(axisClassName); expect(axis.prop('axisLineClassName')).toBe(axisLineClassName); expect(axis.prop('labelClassName')).toBe(labelClassName); expect(axis.prop('tickClassName')).toBe(tickClassName); }); it('should default labelOffset prop to 8', () => { const wrapper = shallow(<AxisTop {...axisProps} />); expect(wrapper.prop('labelOffset')).toBe(8); }); it('should set labelOffset prop', () => { const labelOffset = 3; const wrapper = shallow(<AxisTop {...axisProps} labelOffset={labelOffset} />); expect(wrapper.prop('labelOffset')).toEqual(labelOffset); }); it('should default tickLength prop to 8', () => { const wrapper = shallow(<AxisTop {...axisProps} />); expect(wrapper.prop('tickLength')).toBe(8); }); it('should set tickLength prop', () => { const tickLength = 15; const wrapper = shallow(<AxisTop {...axisProps} tickLength={tickLength} />); expect(wrapper.prop('tickLength')).toEqual(tickLength); }); it('should set label prop', () => { const label = 'test'; const wrapper = shallow(<AxisTop {...axisProps} label={label} />).dive(); const text = wrapper.find('.visx-axis-label'); expect(text.prop('children')).toEqual(label); }); });
7,154
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/Orientation.test.ts
import { Orientation } from '../src'; describe('Orientation', () => { it('should have keys for top/right/bottom/left', () => { expect(Orientation).toEqual({ top: expect.any(String), right: expect.any(String), bottom: expect.any(String), left: expect.any(String), }); }); });
7,155
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/scales.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleBand, scaleLinear, scaleLog, scaleOrdinal, scalePoint, scalePower, scaleQuantile, scaleQuantize, scaleSymlog, scaleThreshold, scaleTime, scaleUtc, } from '@visx/scale'; import { Axis } from '../src'; const axisProps = { orientation: 'left' as const, label: 'test axis', }; describe('Axis scales', () => { it('should render with scaleBand', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleBand({ range: [10, 0], round: true, domain: ['a', 'b', 'c'], })} />, ), ).not.toThrow(); }); it('should render with scaleLinear', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleLinear({ range: [10, 0], round: true, domain: [0, 10], })} />, ), ).not.toThrow(); }); it('should render with scaleLog', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleLog({ range: [10, 0], round: true, domain: [1, 10, 100, 1000], })} />, ), ).not.toThrow(); }); it('should render with scaleOrdinal', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleOrdinal({ range: [0, 10], domain: ['a', 'b', 'c'], })} />, ), ).not.toThrow(); }); it('should render with scalePoint', () => { expect(() => shallow( <Axis {...axisProps} scale={scalePoint({ range: [0, 10], round: true, domain: ['a', 'b', 'c'], })} />, ), ).not.toThrow(); }); it('should render with scalePower', () => { expect(() => shallow( <Axis {...axisProps} scale={scalePower({ range: [1, 2, 3, 4, 5], domain: [1, 10, 100, 1000, 10000], })} />, ), ).not.toThrow(); }); it('should render with scaleQuantile', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleQuantile({ range: [0, 2, 4, 6, 8, 10], domain: [1, 10, 100, 1000, 10000], })} />, ), ).not.toThrow(); }); it('should render with scaleQuantize', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleQuantize({ range: [1, 10], domain: [1, 10], })} />, ), ).not.toThrow(); }); it('should render with scaleSymlog', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleSymlog({ range: [1, 10], domain: [1, 10], })} />, ), ).not.toThrow(); }); it('should render with scaleThreshold', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleThreshold({ range: [1, 10], domain: [1, 10], })} />, ), ).not.toThrow(); }); it('should render with scaleTime', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleTime({ range: [1, 10], domain: [new Date('2020-01-01'), new Date('2020-01-05')], })} />, ), ).not.toThrow(); }); it('should render with scaleUtc', () => { expect(() => shallow( <Axis {...axisProps} scale={scaleUtc({ range: [1, 10], domain: [new Date('2020-01-01'), new Date('2020-01-05')], })} />, ), ).not.toThrow(); }); });
7,156
0
petrpan-code/airbnb/visx/packages/visx-axis
petrpan-code/airbnb/visx/packages/visx-axis/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,157
0
petrpan-code/airbnb/visx/packages/visx-axis/test
petrpan-code/airbnb/visx/packages/visx-axis/test/utils/getAxisRangePaddingConfig.test.ts
import getAxisRangePaddingConfig, { defaultAxisRangePadding, } from '../../src/utils/getAxisRangePaddingConfig'; describe('getAxisRangePaddingConfig(rangePadding)', () => { it('should return default range padding config', () => { const actualResult = getAxisRangePaddingConfig(); const expectedResult = { start: defaultAxisRangePadding, end: defaultAxisRangePadding }; expect(actualResult).toEqual(expectedResult); }); it('should support range padding as a number', () => { const actualResult = getAxisRangePaddingConfig(8); const expectedResult = { start: 8, end: 8 }; expect(actualResult).toEqual(expectedResult); }); it('should support range padding as a config object', () => { const testCases = [ { input: { start: 5 }, expectedResult: { start: 5, end: defaultAxisRangePadding } }, { input: { end: 10 }, expectedResult: { start: defaultAxisRangePadding, end: 10 } }, { input: { start: 15, end: 5 }, expectedResult: { start: 15, end: 5 } }, ]; testCases.forEach(({ input, expectedResult }) => { const actualResult = getAxisRangePaddingConfig(input); expect(actualResult).toEqual(expectedResult); }); }); });
7,158
0
petrpan-code/airbnb/visx/packages/visx-axis/test
petrpan-code/airbnb/visx/packages/visx-axis/test/utils/getTickPosition.test.ts
import { scaleLinear, scaleBand } from '@visx/scale'; import getTickPosition from '../../src/utils/getTickPosition'; describe('getTickPosition(scale, align)', () => { describe('scales without band', () => { it('return center position', () => { const position = getTickPosition(scaleLinear({ domain: [0, 10], range: [0, 100] })); expect(position(5)).toBe(50); }); }); describe('scales with band', () => { describe('align', () => { const scale = scaleBand({ domain: ['a', 'b', 'c'], range: [0, 100] }); it('default to center', () => { expect(getTickPosition(scale)('b')).toBe(50); }); it('center', () => { expect(getTickPosition(scale, 'center')('b')).toBe(50); }); it('start', () => { expect((getTickPosition(scale, 'start')('b') as number).toFixed(2)).toBe('33.33'); }); it('end', () => { expect((getTickPosition(scale, 'end')('b') as number).toFixed(2)).toBe('66.67'); }); }); describe('with rounding', () => { const scale = scaleBand({ domain: ['a', 'b', 'c'], range: [0, 100], round: true }); it('center', () => { expect(getTickPosition(scale, 'center')('b')).toBe(51); }); it('start', () => { expect(getTickPosition(scale, 'start')('b')).toBe(34); }); it('end', () => { expect(getTickPosition(scale, 'end')('b')).toBe(67); }); }); }); });
7,165
0
petrpan-code/airbnb/visx/packages/visx-bounds
petrpan-code/airbnb/visx/packages/visx-bounds/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,166
0
petrpan-code/airbnb/visx/packages/visx-bounds
petrpan-code/airbnb/visx/packages/visx-bounds/test/withBoundingRects.test.tsx
/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ import React, { ReactNode } from 'react'; import { render, waitFor } from '@testing-library/react'; import fireEvent from '@testing-library/user-event'; import { withBoundingRects } from '../src'; import '@testing-library/jest-dom'; type RectShape = { top?: number; right?: number; bottom?: number; left?: number; width?: number; height?: number; }; const emptyRect = { top: 0, right: 0, bottom: 0, left: 0, }; const mockRect = { top: 50, left: 50, bottom: 0, right: 0, }; type BoundingRectsComponentProps = { rect?: RectShape; parentRect?: RectShape; getRects?: () => DOMRect; children?: ReactNode; otherProps?: object; }; // Component created for testing purpose function BoundingRectsComponent({ rect, parentRect, getRects, children, ...otherProps }: BoundingRectsComponentProps) { const parentRectStyle = { top: parentRect?.top, left: parentRect?.left, bottom: parentRect?.bottom, right: parentRect?.right, }; const rectStyle = { top: rect?.top, left: rect?.left, bottom: rect?.bottom, right: rect?.right, }; return ( <div data-testid="BoundingRectsComponentParent" style={parentRectStyle}> <div data-testid="BoundingRectsComponent" style={rectStyle} onClick={() => getRects?.()}> {children} {JSON.stringify(otherProps)} </div> </div> ); } const Component = () => null; describe('withBoundingRects()', () => { beforeAll(() => { // mock getBoundingClientRect jest.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(() => ({ ...mockRect, x: 0, y: 0, width: 100, height: 100, toJSON: jest.fn(), })); }); test('it should be defined', () => { expect(withBoundingRects).toBeDefined(); }); test('it should pass rect, parentRect, and getRect props to the wrapped component', async () => { const HOC = withBoundingRects(BoundingRectsComponent); const { getByTestId } = render(<HOC />); // getBoundingClientRect should be called twice, once for the component, and once for its parent await waitFor(() => expect(Element.prototype.getBoundingClientRect).toHaveBeenCalledTimes(2)); const RenderedComponent = getByTestId('BoundingRectsComponent'); const RenderedComponentParent = getByTestId('BoundingRectsComponentParent'); const expectedStyle = `top: ${mockRect.top}px; bottom: ${mockRect.bottom}px; left: ${mockRect.left}px; right: ${mockRect.right}px;`; expect(RenderedComponent).toHaveStyle(expectedStyle); expect(RenderedComponentParent).toHaveStyle(expectedStyle); fireEvent.click(RenderedComponent); // upon onClick time, getBoundingClientRect should be called extra 2 times expect(Element.prototype.getBoundingClientRect).toHaveBeenCalledTimes(4); }); test('it should pass additional props to the wrapped component', () => { const HOC = withBoundingRects(BoundingRectsComponent); // @ts-expect-error const { getByText } = render(<HOC bananas="are yellow" />); expect(getByText('are yellow', { exact: false })).toBeInTheDocument(); }); test('it should not render if no node', () => { const HOC = withBoundingRects(Component); const { container } = render(<HOC />); expect(container.innerHTML).toHaveLength(0); }); test('it should set rect and parentRect to empty state if no getBoundingClient()', () => { (Element.prototype.getBoundingClientRect as unknown) = null; const HOC = withBoundingRects(BoundingRectsComponent); const { getByTestId } = render(<HOC />); const RenderedComponent = getByTestId('BoundingRectsComponent'); const RenderedComponentParent = getByTestId('BoundingRectsComponentParent'); expect(RenderedComponent).toHaveStyle(emptyRect); expect(RenderedComponentParent).toHaveStyle(emptyRect); }); });
7,179
0
petrpan-code/airbnb/visx/packages/visx-brush
petrpan-code/airbnb/visx/packages/visx-brush/test/Brush.test.tsx
import { Brush } from '../src'; describe('<Brush />', () => { test('it should be defined', () => { expect(Brush).toBeDefined(); }); });
7,180
0
petrpan-code/airbnb/visx/packages/visx-brush
petrpan-code/airbnb/visx/packages/visx-brush/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,181
0
petrpan-code/airbnb/visx/packages/visx-brush
petrpan-code/airbnb/visx/packages/visx-brush/test/utils.test.ts
import { createScale } from '@visx/scale'; import { getDomainFromExtent, scaleInvert } from '../src/utils'; describe('getDomainFromExtent()', () => { test('it should return { start, end } if scale.invert', () => { const scale = createScale({ domain: [0, 10], range: [2, 4] }); const start = 0; const end = 1; const tolerentDelta = 0.5; const result = getDomainFromExtent(scale, start, end, tolerentDelta); expect(result.start).toBeDefined(); expect(result.end).toBeDefined(); expect(result.start).toEqual(scale.invert(start - tolerentDelta)); expect(result.end).toEqual(scale.invert(end + tolerentDelta)); }); test('it should handle start > end', () => { const scale = createScale({ domain: [0, 10], range: [2, 4] }); const start = 1; const end = 0; const tolerentDelta = 0.5; const result = getDomainFromExtent(scale, start, end, tolerentDelta); expect(result.start).toEqual(scale.invert(end - tolerentDelta)); expect(result.end).toEqual(scale.invert(start + tolerentDelta)); }); test('it should return { values } for band scales', () => { const scale = createScale({ type: 'band', domain: ['a', 'b', 'c'], range: [1.1, 3.5], round: false, }); const domain = scale.domain(); const start = 0; const end = 1; const tolerentDelta = 0.5; const result = getDomainFromExtent(scale, start, end, tolerentDelta); expect(result.values).toBeDefined(); expect(result.values).toEqual([domain[0]]); }); }); describe('scaleInvert()', () => { test('it should return scale.invert(value) if scale.invert', () => { const scale = createScale({ domain: [0, 10], range: [2, 4] }); const value = 3; const result = scaleInvert(scale, value); expect(result).toEqual(scale.invert(value)); }); test('it should return the index of domain item for scales without invert (like band)', () => { const scale = createScale({ type: 'band', domain: ['a', 'b', 'c'], range: [1.1, 3.5], round: false, }); const value = 3; const result = scaleInvert(scale, value); expect(result).toBe(2); }); test('it should handle band scales where end < start', () => { const scale = createScale({ type: 'band', domain: ['a', 'b', 'c'], range: [20, 1], round: false, }); const value = 3; const result = scaleInvert(scale, value); expect(result).toBe(2); }); });
7,189
0
petrpan-code/airbnb/visx/packages/visx-chord
petrpan-code/airbnb/visx/packages/visx-chord/test/Chord.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { Chord } from '../src'; const matrix = [ [11975, 5871, 8916, 2868], [1951, 10048, 2060, 6171], [8010, 16145, 8090, 8045], [1013, 990, 940, 6907], ]; type WrapperProps = { matrix: number[][]; children: () => React.ReactNode; }; const ChordWrapper = ({ ...restProps }: WrapperProps) => shallow(<Chord {...restProps} />); describe('<Chord />', () => { test('it should be defined', () => { expect(Chord).toBeDefined(); }); test('it should call children as a function with required args', () => { const children = jest.fn(); ChordWrapper({ children, matrix }); const args = children.mock.calls[0][0]; expect(children.mock.calls).toHaveLength(1); expect(args.chords).toBeDefined(); }); });
7,190
0
petrpan-code/airbnb/visx/packages/visx-chord
petrpan-code/airbnb/visx/packages/visx-chord/test/Ribbon.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { chord as d3Chord } from 'd3-chord'; import { Ribbon } from '../src'; const matrix = [ [11975, 5871, 8916, 2868], [1951, 10048, 2060, 6171], [8010, 16145, 8090, 8045], [1013, 990, 940, 6907], ]; const chords = d3Chord()(matrix); describe('<Ribbon />', () => { test('it should be defined', () => { expect(Ribbon).toBeDefined(); }); test('it should call children as a function with required args', () => { const children = jest.fn(() => 'test'); shallow(<Ribbon chord={chords[0]} children={children} />); // we don't know type of the arguments const args = (children.mock.calls[0] as { path?: unknown }[])[0]; expect(children.mock.calls).toHaveLength(1); expect(args.path).toBeDefined(); }); });
7,191
0
petrpan-code/airbnb/visx/packages/visx-chord
petrpan-code/airbnb/visx/packages/visx-chord/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,200
0
petrpan-code/airbnb/visx/packages/visx-clip-path
petrpan-code/airbnb/visx/packages/visx-clip-path/test/ClipPaths.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { ClipPath, CircleClipPath, RectClipPath } from '../src'; describe('<ClipPath />', () => { test('it should be defined', () => { expect(ClipPath).toBeDefined(); }); test('it should render defs and clipPath elements', () => { const wrapper = shallow(<ClipPath id="test" />); expect(wrapper.type()).toBe('defs'); expect(wrapper.find('clipPath')).toHaveLength(1); }); test('it should assign the passed id to the clipPath', () => { const wrapper = shallow(<ClipPath id="best_clip" />); expect(wrapper.find('clipPath#best_clip')).toHaveLength(1); }); }); describe('<RectClipPath />', () => { test('it should be defined', () => { expect(RectClipPath).toBeDefined(); }); test('it should render a rect', () => { const wrapper = shallow(<RectClipPath id="test" />); expect(wrapper.find('rect')).toHaveLength(1); }); }); describe('<CircleClipPath />', () => { test('it should be defined', () => { expect(CircleClipPath).toBeDefined(); }); test('it should render a circle', () => { const wrapper = shallow(<CircleClipPath id="test" />); expect(wrapper.find('circle')).toHaveLength(1); }); });
7,201
0
petrpan-code/airbnb/visx/packages/visx-clip-path
petrpan-code/airbnb/visx/packages/visx-clip-path/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,207
0
petrpan-code/airbnb/visx/packages/visx-curve
petrpan-code/airbnb/visx/packages/visx-curve/test/curve.test.ts
import { curveBasis, curveBasisClosed, curveBasisOpen, curveStep, curveStepAfter, curveStepBefore, curveBundle, curveLinear, curveLinearClosed, curveCardinal, curveCardinalClosed, curveCardinalOpen, curveCatmullRom, curveCatmullRomClosed, curveCatmullRomOpen, curveMonotoneX, curveMonotoneY, curveNatural, } from '../src'; describe('curves', () => { test('curveBasis', () => { expect(curveBasis).toBeDefined(); }); test('curveBasisClosed', () => { expect(curveBasisClosed).toBeDefined(); }); test('curveBasisOpen', () => { expect(curveBasisOpen).toBeDefined(); }); test('curveStep', () => { expect(curveStep).toBeDefined(); }); test('curveStepAfter', () => { expect(curveStepAfter).toBeDefined(); }); test('curveStepBefore', () => { expect(curveStepBefore).toBeDefined(); }); test('curveBundle', () => { expect(curveBundle).toBeDefined(); }); test('curveLinear', () => { expect(curveLinear).toBeDefined(); }); test('curveLinearClosed', () => { expect(curveLinearClosed).toBeDefined(); }); test('curveCardinal', () => { expect(curveCardinal).toBeDefined(); }); test('curveCardinalClosed', () => { expect(curveCardinalClosed).toBeDefined(); }); test('curveCardinalOpen', () => { expect(curveCardinalOpen).toBeDefined(); }); test('curveCatmullRom', () => { expect(curveCatmullRom).toBeDefined(); }); test('curveCatmullRomClosed', () => { expect(curveCatmullRomClosed).toBeDefined(); }); test('curveCatmullRomOpen', () => { expect(curveCatmullRomOpen).toBeDefined(); }); test('curveMonotoneX', () => { expect(curveMonotoneX).toBeDefined(); }); test('curveMonotoneY', () => { expect(curveMonotoneY).toBeDefined(); }); test('curveNatural', () => { expect(curveNatural).toBeDefined(); }); });
7,208
0
petrpan-code/airbnb/visx/packages/visx-curve
petrpan-code/airbnb/visx/packages/visx-curve/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,217
0
petrpan-code/airbnb/visx/packages/visx-delaunay
petrpan-code/airbnb/visx/packages/visx-delaunay/test/Polygon.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { Polygon } from '../src'; describe('<Polygon />', () => { const polygon: [number, number][] = new Array(3).fill(null).map((_, i) => [i, i]); const props = { polygon }; test('it should be defined', () => { expect(Polygon).toBeDefined(); }); test('it should not render without a polygon', () => { const wrapper = shallow(<Polygon />); expect(wrapper.type()).toBeNull(); }); test('it should render a path', () => { const wrapper = shallow(<Polygon {...props} />); expect(wrapper.find('path')).toHaveLength(1); }); test('it should set a d attribute based on the polygon prop', () => { const wrapper = shallow(<Polygon {...props} />); const d = 'M0,0L1,1L2,2Z'; expect(wrapper.find('path').props().d).toEqual(d); }); test('it should add extra (non-func) props to the path element', () => { const wrapper = shallow(<Polygon {...props} fill="orange" />); expect(wrapper.find('path').props().fill).toBe('orange'); }); });
7,218
0
petrpan-code/airbnb/visx/packages/visx-delaunay
petrpan-code/airbnb/visx/packages/visx-delaunay/test/delaunay.test.ts
import { delaunay } from '../src'; const data = [ { x: 10, y: 10 }, { x: 10, y: 20 }, { x: 20, y: 20 }, { x: 20, y: 10 }, ]; describe('delaunay', () => { test('it should be defined', () => { expect(delaunay).toBeDefined(); }); test('it should find closest point', () => { const delaunayDiagram = delaunay({ data, x: (d) => d.x, y: (d) => d.y }); expect(delaunayDiagram.find(9, 11)).toBe(0); expect(delaunayDiagram.find(11, 19)).toBe(1); expect(delaunayDiagram.find(21, 19)).toBe(2); }); test('the delaunay triagulation of a square should contain two triangles', () => { const delaunayDiagram = delaunay({ data, x: (d) => d.x, y: (d) => d.y }); expect(Array.from(delaunayDiagram.trianglePolygons())).toHaveLength(2); }); });
7,219
0
petrpan-code/airbnb/visx/packages/visx-delaunay
petrpan-code/airbnb/visx/packages/visx-delaunay/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,220
0
petrpan-code/airbnb/visx/packages/visx-delaunay
petrpan-code/airbnb/visx/packages/visx-delaunay/test/voronoi.test.ts
import { voronoi } from '../src'; const x = () => 123; const y = () => 123; describe('voronoi', () => { test('it should be defined', () => { expect(voronoi).toBeDefined(); }); test('width and height params should define extent', () => { const width = 17; const height = 99; const v = voronoi({ width, height, x, y }); expect(v.xmin).toBe(-1); expect(v.ymin).toBe(-1); expect(v.xmax).toEqual(width + 1); expect(v.ymax).toEqual(height + 1); }); test('100 random points should give 100 cell polygons', () => { const data = new Array(100).fill(null).map(() => ({ x: Math.random(), y: Math.random(), })); const v = voronoi({ data, x: (d) => d.x, y: (d) => d.y }); expect(Array.from(v.cellPolygons())).toHaveLength(100); }); });
7,630
0
petrpan-code/airbnb/visx/packages/visx-drag
petrpan-code/airbnb/visx/packages/visx-drag/test/Drag.test.ts
import { Drag } from '../src'; describe('Drag', () => { test('it should be defined', () => { expect(Drag).toBeDefined(); }); });
7,631
0
petrpan-code/airbnb/visx/packages/visx-drag
petrpan-code/airbnb/visx/packages/visx-drag/test/raise.test.ts
import { raise } from '../src'; describe('raise', () => { test('it should be defined', () => { expect(raise).toBeDefined(); }); });
7,632
0
petrpan-code/airbnb/visx/packages/visx-drag
petrpan-code/airbnb/visx/packages/visx-drag/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,633
0
petrpan-code/airbnb/visx/packages/visx-drag
petrpan-code/airbnb/visx/packages/visx-drag/test/useDrag.test.tsx
import React, { useRef } from 'react'; import { render } from '@testing-library/react'; import { useDrag } from '../src'; import { UseDragOptions } from '../lib/useDrag'; describe('useDrag', () => { test('it should be defined', () => { expect(useDrag).toBeDefined(); }); test('should provide UseDrag', () => { expect.assertions(1); function Consumer() { const drag = useDrag({ x: 0, y: 0 }); expect(drag).toMatchObject({ x: 0, y: 0, dx: 0, dy: 0, isDragging: false, dragStart: expect.any(Function), dragMove: expect.any(Function), dragEnd: expect.any(Function), }); return null; } render(<Consumer />); }); test('should update drag state when useDrag options change', () => { expect.assertions(3); const options1 = { x: 1, y: 2, dx: 3, dy: 4 }; const options2 = { x: -1, y: -2, dx: -3, dy: -4 }; function Consumer({ x, y, dx, dy }: Pick<UseDragOptions, 'x' | 'y' | 'dx' | 'dy'>) { const renderCount = useRef(0); const drag = useDrag({ x, y, dx, dy }); // when this component's props change options1 => 2, it takes one // additional render for the `useDrag` state to update to options2 expect(drag).toMatchObject(renderCount.current <= 1 ? options1 : options2); renderCount.current += 1; return null; } const { rerender } = render(<Consumer {...options1} />); rerender(<Consumer {...options2} />); }); });
7,634
0
petrpan-code/airbnb/visx/packages/visx-drag
petrpan-code/airbnb/visx/packages/visx-drag/test/useStateWithCallback.test.ts
import useStateWithCallback from '../src/util/useStateWithCallback'; describe('useStateWithCallback', () => { test('it should be defined', () => { expect(useStateWithCallback).toBeDefined(); }); });
7,646
0
petrpan-code/airbnb/visx/packages/visx-event
petrpan-code/airbnb/visx/packages/visx-event/test/getXandYFromEvent.test.ts
import getXAndYFromEvent from '../src/getXAndYFromEvent'; describe('getXAndYFromEvent()', () => { it('should return { x: 0, y: 0 } if no event argument', () => { const result = getXAndYFromEvent(); // @ts-expect-error const result2 = getXAndYFromEvent(null); expect(result).toEqual({ x: 0, y: 0 }); expect(result2).toEqual({ x: 0, y: 0 }); }); it('should return { x, y } for mouse events', () => { const e = { clientX: 0, clientY: 0 }; const result = getXAndYFromEvent(e as MouseEvent); expect(result).toEqual({ x: e.clientX, y: e.clientY }); }); it('should return { x, y } for touch events with changedTouches', () => { const touch0 = { clientX: 0, clientY: 0 }; const touch1 = { clientX: 1, clientY: 1 }; const e = { changedTouches: [touch0, touch1] }; const result = getXAndYFromEvent(e as unknown as TouchEvent); expect(result).toEqual({ x: touch0.clientX, y: touch0.clientY }); }); it('should return { x: 0, y: 0 } for touch events with no changedTouches', () => { const e = { changedTouches: [] }; const result = getXAndYFromEvent(e as unknown as TouchEvent); expect(result).toEqual({ x: 0, y: 0 }); }); it('should return the middle of an element for focus events', () => { const e = { target: { getBoundingClientRect: () => ({ x: 5, y: 5, width: 10, height: 2 }) } }; const result = getXAndYFromEvent(e as unknown as FocusEvent); expect(result).toEqual({ x: 10, y: 6 }); }); });
7,647
0
petrpan-code/airbnb/visx/packages/visx-event
petrpan-code/airbnb/visx/packages/visx-event/test/localPoint.test.ts
import { Point } from '@visx/point'; import { localPoint } from '../src'; import localPointGeneric from '../src/localPointGeneric'; describe('localPoint', () => { test('it should be defined', () => { expect(localPoint).toBeDefined(); }); test('it should return null if called with no arguments', () => { // @ts-expect-error expect(localPoint()).toBeNull(); // @ts-expect-error expect(localPointGeneric(document.createElement('div'))).toBeNull(); }); test('it should handle localPoint(event) and get node from event.target', () => { const e = new MouseEvent('test', { clientX: 10, clientY: 10, }); Object.defineProperty(e, 'target', { writable: false, value: { clientLeft: 0, clientTop: 0, getBoundingClientRect: () => ({ left: 0, top: 0 }), }, }); const result = localPoint(e); expect(result).toEqual(new Point({ x: 10, y: 10 })); }); test('it should handle localPoint(node, event)', () => { const e = new MouseEvent('test', { clientX: 10, clientY: 10, }); const node = document.createElementNS('http://www.w3.org/2000/svg', 'path'); const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); // @ts-expect-error svg.createSVGPoint = () => ({ matrixTransform: () => ({ x: 10, y: 10 }) }); // @ts-expect-error svg.getScreenCTM = () => ({ inverse: () => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }); svg.appendChild(node); const result = localPoint(node, e); expect(result).toEqual(new Point({ x: 10, y: 10 })); }); });
7,648
0
petrpan-code/airbnb/visx/packages/visx-event
petrpan-code/airbnb/visx/packages/visx-event/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,664
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/Albers.test.tsx
import { Albers } from '../src'; describe('<Albers />', () => { test('it should be defined', () => { expect(Albers).toBeDefined(); }); });
7,665
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/AlbersUsa.test.tsx
import { AlbersUsa } from '../src'; describe('<AlbersUsa />', () => { test('it should be defined', () => { expect(AlbersUsa).toBeDefined(); }); });
7,666
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/CustomProjection.test.tsx
import { CustomProjection } from '../src'; describe('<CustomProjection />', () => { test('it should be defined', () => { expect(CustomProjection).toBeDefined(); }); });
7,667
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/EqualEarth.test.tsx
import { EqualEarth } from '../src'; describe('<EqualEarth />', () => { test('it should be defined', () => { expect(EqualEarth).toBeDefined(); }); });
7,668
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/Mercator.test.tsx
import { Mercator } from '../src'; describe('<Mercator />', () => { test('it should be defined', () => { expect(Mercator).toBeDefined(); }); });
7,669
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/Orthographic.test.tsx
import { Orthographic } from '../src'; describe('<Orthographic />', () => { test('it should be defined', () => { expect(Orthographic).toBeDefined(); }); });
7,670
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/Projection.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { feature } from 'topojson-client'; // eslint-disable-next-line import/no-unresolved import { GeometryCollection } from 'geojson'; import Projection from '../src/projections/Projection'; // @ts-expect-error doesn't like .json import topology from './topo.json'; describe('<Projection />', () => { // TopoJSON with two polygons // @ts-expect-error @TODO get this to method overload properly const data: GeometryCollection[] = feature(topology, topology.objects.collection).features; const props = { data }; test('it should be defined', () => { expect(Projection).toBeDefined(); }); test('it should pass className', () => { const wrapper = shallow(<Projection className="visx-new" {...props} />); expect(wrapper.find('path').get(0).props.className).toBe('visx-geo-mercator visx-new'); }); test('it should create two paths', () => { const wrapper = shallow(<Projection {...props} />); expect(wrapper.find('path')).toHaveLength(2); }); test('it should pass prop to path', () => { const wrapper = shallow(<Projection stroke="red" {...props} />); expect(wrapper.find('path').get(0).props.stroke).toBe('red'); expect(wrapper.find('path').get(1).props.stroke).toBe('red'); }); test('it should call projectionFunc prop function', () => { const projectionFunc = jest.fn(); shallow(<Projection projectionFunc={projectionFunc} {...props} />); expect(projectionFunc).toHaveBeenCalledTimes(1); }); test('it should call centroid prop function', () => { const centroid = jest.fn(); shallow(<Projection centroid={centroid} {...props} />); expect(centroid).toHaveBeenCalledTimes(2); }); });
7,672
0
petrpan-code/airbnb/visx/packages/visx-geo
petrpan-code/airbnb/visx/packages/visx-geo/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,687
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Circle.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphCircle } from '../src'; describe('<GlyphCircle />', () => { test('it should be defined', () => { expect(GlyphCircle).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphCircle />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphCircle className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphCircle>{fn}</GlyphCircle>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphCircle>{fn}</GlyphCircle>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphCircle size={42}>{fn}</GlyphCircle>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphCircle size={sizeFn}>{fn}</GlyphCircle>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,688
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Cross.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphCross } from '../src'; describe('<GlyphCross />', () => { test('it should be defined', () => { expect(GlyphCross).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphCross />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphCross className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphCross>{fn}</GlyphCross>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphCross>{fn}</GlyphCross>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphCross size={42}>{fn}</GlyphCross>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphCross size={sizeFn}>{fn}</GlyphCross>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,689
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Diamond.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphDiamond } from '../src'; describe('<GlyphDiamond />', () => { test('it should be defined', () => { expect(GlyphDiamond).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphDiamond />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphDiamond className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphDiamond>{fn}</GlyphDiamond>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphDiamond>{fn}</GlyphDiamond>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphDiamond size={42}>{fn}</GlyphDiamond>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphDiamond size={sizeFn}>{fn}</GlyphDiamond>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,690
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Dot.test.tsx
import { GlyphDot } from '../src'; describe('<GlyphDot />', () => { test('it should be defined', () => { expect(GlyphDot).toBeDefined(); }); });
7,691
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Glyph.test.tsx
import React from 'react'; import { shallow, render } from 'enzyme'; import { Glyph } from '../src'; describe('<Glyph />', () => { test('it should be defined', () => { expect(Glyph).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<Glyph />); expect(wrapper.prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<Glyph className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take top,left number props', () => { const wrapper = render(<Glyph top={2} left={2} />); expect(wrapper[0].attribs.transform as string).toBe('translate(2, 2)'); }); });
7,692
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Square.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphSquare } from '../src'; describe('<GlyphSquare />', () => { test('it should be defined', () => { expect(GlyphSquare).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphSquare />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphSquare className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphSquare>{fn}</GlyphSquare>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphSquare>{fn}</GlyphSquare>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphSquare size={42}>{fn}</GlyphSquare>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphSquare size={sizeFn}>{fn}</GlyphSquare>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,693
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Star.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphStar } from '../src'; describe('<GlyphStar />', () => { test('it should be defined', () => { expect(GlyphStar).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphStar />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphStar className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphStar>{fn}</GlyphStar>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphStar>{fn}</GlyphStar>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphStar size={42}>{fn}</GlyphStar>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphStar size={sizeFn}>{fn}</GlyphStar>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,694
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Triangle.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphTriangle } from '../src'; describe('<GlyphTriangle />', () => { test('it should be defined', () => { expect(GlyphTriangle).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphTriangle />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphTriangle className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphTriangle>{fn}</GlyphTriangle>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphTriangle>{fn}</GlyphTriangle>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphTriangle size={42}>{fn}</GlyphTriangle>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphTriangle size={sizeFn}>{fn}</GlyphTriangle>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,695
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/Wye.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { GlyphWye } from '../src'; describe('<GlyphWye />', () => { test('it should be defined', () => { expect(GlyphWye).toBeDefined(); }); test('it should be wrapped in a <Glyph />', () => { const wrapper = shallow(<GlyphWye />); expect(wrapper.dive().prop('className')).toBe('visx-glyph'); }); test('it should add className to <path />', () => { const wrapper = shallow(<GlyphWye className="test" />); expect(wrapper.find('.test')).toHaveLength(1); }); test('it should take a children as function prop', () => { const fn = jest.fn(); shallow(<GlyphWye>{fn}</GlyphWye>); expect(fn).toHaveBeenCalled(); }); test('it should call children function with { path }', () => { const fn = jest.fn(); shallow(<GlyphWye>{fn}</GlyphWye>); const args = fn.mock.calls[0][0]; const keys = Object.keys(args); expect(keys).toContain('path'); }); test('it should take a size prop as a number', () => { const fn = jest.fn(); shallow(<GlyphWye size={42}>{fn}</GlyphWye>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); test('it should take a size prop as a function', () => { const fn = jest.fn(); const sizeFn = () => 42; shallow(<GlyphWye size={sizeFn}>{fn}</GlyphWye>); const args = fn.mock.calls[0][0]; expect(args.path.size()()).toBe(42); }); });
7,696
0
petrpan-code/airbnb/visx/packages/visx-glyph
petrpan-code/airbnb/visx/packages/visx-glyph/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,714
0
petrpan-code/airbnb/visx/packages/visx-gradient
petrpan-code/airbnb/visx/packages/visx-gradient/test/Gradients.test.tsx
import React from 'react'; import { render } from '@testing-library/react'; import { GradientDarkgreenGreen, GradientLightgreenGreen, GradientOrangeRed, GradientPinkBlue, GradientPinkRed, GradientPurpleOrange, GradientPurpleRed, GradientPurpleTeal, GradientSteelPurple, GradientTealBlue, } from '../src'; describe('<GradientDarkgreenGreen />', () => { test('it should be defined', () => { expect(GradientDarkgreenGreen).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientDarkgreenGreen id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientLightgreenGreen />', () => { test('it should be defined', () => { expect(GradientLightgreenGreen).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientLightgreenGreen id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientOrangeRed />', () => { test('it should be defined', () => { expect(GradientOrangeRed).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientOrangeRed id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientPinkBlue />', () => { test('it should be defined', () => { expect(GradientPinkBlue).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientPinkBlue id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientPinkRed />', () => { test('it should be defined', () => { expect(GradientPinkRed).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientPinkRed id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientPurpleOrange />', () => { test('it should be defined', () => { expect(GradientPurpleOrange).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientPurpleOrange id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientPurpleRed />', () => { test('it should be defined', () => { expect(GradientPurpleRed).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientPurpleRed id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientPurpleTeal />', () => { test('it should be defined', () => { expect(GradientPurpleTeal).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientPurpleTeal id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientSteelPurple />', () => { test('it should be defined', () => { expect(GradientSteelPurple).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientSteelPurple id="gradient" /> </svg>, ), ).not.toThrow(); }); }); describe('<GradientTealBlue />', () => { test('it should be defined', () => { expect(GradientTealBlue).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <GradientTealBlue id="gradient" /> </svg>, ), ).not.toThrow(); }); });
7,715
0
petrpan-code/airbnb/visx/packages/visx-gradient
petrpan-code/airbnb/visx/packages/visx-gradient/test/LinearGradient.test.tsx
import React from 'react'; import { render } from '@testing-library/react'; import { LinearGradient } from '../src'; describe('<LinearGradient />', () => { test('it should be defined', () => { expect(LinearGradient).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <LinearGradient id="linear" /> </svg>, ), ).not.toThrow(); }); });
7,716
0
petrpan-code/airbnb/visx/packages/visx-gradient
petrpan-code/airbnb/visx/packages/visx-gradient/test/RadialGradient.test.tsx
import React from 'react'; import { render } from '@testing-library/react'; import { RadialGradient } from '../src'; describe('<RadialGradient />', () => { test('it should be defined', () => { expect(RadialGradient).toBeDefined(); }); test('it should render without crashing', () => { expect(() => render( <svg> <RadialGradient id="radial" /> </svg>, ), ).not.toThrow(); }); });
7,717
0
petrpan-code/airbnb/visx/packages/visx-gradient
petrpan-code/airbnb/visx/packages/visx-gradient/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,732
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/Grid.test.tsx
import React from 'react'; import { render } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Grid } from '../src'; describe('<Grid />', () => { it('should be defined', () => { expect(Grid).toBeDefined(); }); it('should create grid lines', () => { const wrapper = render( <Grid xScale={scaleLinear({ range: [0, 100] })} yScale={scaleLinear({ range: [0, 100] })} width={400} height={400} strokeDasharray="3,3" strokeOpacity={0.3} pointerEvents="none" />, ); expect(wrapper.find('.visx-rows')).toHaveLength(1); expect(wrapper.find('.visx-columns')).toHaveLength(1); expect(wrapper.find('.visx-line')).toHaveLength(22); }); });
7,733
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/GridAngle.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { Line } from '@visx/shape'; import { scaleLinear } from '@visx/scale'; import { GridAngle } from '../src'; import * as polarToCartesian from '../src/utils/polarToCartesian'; const gridProps = { innerRadius: 0, outerRadius: 10, scale: scaleLinear({ range: [0, 2 * Math.PI], domain: [1, 10], }), }; describe('<GridAngle />', () => { it('should render with class .vx-grid-angle', () => { const wrapper = shallow(<GridAngle {...gridProps} />); expect(wrapper.find('.visx-grid-angle')).toHaveLength(1); }); it('should set user-specified lineClassName', () => { const wrapper = shallow(<GridAngle {...gridProps} lineClassName="test-class" />); expect(wrapper.find('.test-class').length).toBeGreaterThan(0); }); it('should render `numTicks` grid lines', () => { const fiveTickWrapper = shallow(<GridAngle {...gridProps} numTicks={5} />); const tenTickWrapper = shallow(<GridAngle {...gridProps} numTicks={10} />); expect(fiveTickWrapper.find(Line)).toHaveLength(5); expect(tenTickWrapper.find(Line)).toHaveLength(10); }); it('should render grid lines according to tickValues', () => { const wrapper = shallow(<GridAngle {...gridProps} tickValues={[1, 2, 3]} />); expect(wrapper.find(Line)).toHaveLength(3); }); it('should compute radial lines using innerRadius and outerRadius', () => { const polarToCartesianSpy = jest.spyOn(polarToCartesian, 'default'); const innerRadius = 4; const outerRadius = 7; shallow(<GridAngle {...gridProps} innerRadius={innerRadius} outerRadius={outerRadius} />); expect(polarToCartesianSpy.mock.calls.length).toBeGreaterThanOrEqual(2); const fromPointCall = polarToCartesianSpy.mock.calls[0][0]; const toPointCall = polarToCartesianSpy.mock.calls[1][0]; expect(fromPointCall.radius).toBe(innerRadius); expect(toPointCall.radius).toBe(outerRadius); polarToCartesianSpy.mockRestore(); }); });
7,734
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/GridColumns.test.tsx
import React from 'react'; import { render } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { GridColumns } from '../src'; describe('<GridColumns />', () => { it('should be defined', () => { expect(GridColumns).toBeDefined(); }); it('should create grid lines', () => { const wrapper = render( <GridColumns scale={scaleLinear({ range: [0, 100] })} height={400} strokeDasharray="3,3" strokeOpacity={0.3} pointerEvents="none" />, ); expect(wrapper.find('.visx-line')).toHaveLength(11); }); });
7,735
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/GridPolar.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { GridPolar, GridAngle, GridRadial } from '../src'; const gridProps = { innerRadius: 0, outerRadius: 10, scaleAngle: scaleLinear({ range: [1, 100], domain: [1, 10] }), scaleRadial: scaleLinear({ range: [1, 100], domain: [1, 10] }), }; describe('<GridPolar />', () => { it('should be defined', () => { expect(GridPolar).toBeDefined(); }); it('should render with class .visx-grid-polar', () => { const wrapper = shallow(<GridPolar {...gridProps} />); expect(wrapper.find('.visx-grid-polar')).toHaveLength(1); }); it('should render both GridAngle & GridRadial', () => { const wrapper = shallow(<GridPolar {...gridProps} />); expect(wrapper.find(GridAngle)).toHaveLength(1); expect(wrapper.find(GridRadial)).toHaveLength(1); }); });
7,736
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/GridRadial.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { Arc } from '@visx/shape'; import { scaleLinear } from '@visx/scale'; import { GridRadial } from '../src'; const gridProps = { innerRadius: 0, outerRadius: 10, scale: scaleLinear({ range: [1, 100], domain: [1, 10] }), }; describe('<GridRadial />', () => { it('should be defined', () => { expect(GridRadial).toBeDefined(); }); it('should render with class .visx-grid-radial', () => { const wrapper = shallow(<GridRadial {...gridProps} />); expect(wrapper.find('.visx-grid-radial')).toHaveLength(1); }); it('should set user-specified lineClassName', () => { const wrapper = shallow(<GridRadial {...gridProps} lineClassName="test-class" />); expect(wrapper.find('.test-class').length).toBeGreaterThan(0); }); it('should render `numTicks` grid line arcs', () => { const fiveTickWrapper = shallow(<GridRadial {...gridProps} numTicks={5} />); const tenTickWrapper = shallow(<GridRadial {...gridProps} numTicks={10} />); expect(fiveTickWrapper.find(Arc)).toHaveLength(5); expect(tenTickWrapper.find(Arc)).toHaveLength(10); }); it('should render grid line arcs according to tickValues', () => { const wrapper = shallow(<GridRadial {...gridProps} tickValues={[1, 2, 3]} />); expect(wrapper.find(Arc)).toHaveLength(3); }); });
7,737
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/GridRows.test.tsx
import React from 'react'; import { render } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { GridRows } from '../src'; describe('<GridRows />', () => { it('should be defined', () => { expect(GridRows).toBeDefined(); }); it('should create grid lines', () => { const wrapper = render( <GridRows scale={scaleLinear({ range: [0, 100] })} width={400} strokeDasharray="3,3" strokeOpacity={0.3} pointerEvents="none" />, ); expect(wrapper.find('.visx-line')).toHaveLength(11); }); });
7,738
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,739
0
petrpan-code/airbnb/visx/packages/visx-grid
petrpan-code/airbnb/visx/packages/visx-grid/test/utils.test.ts
import { scaleLinear, scaleBand } from '@visx/scale'; import polarToCartesian from '../src/utils/polarToCartesian'; import getScaleBandwidth from '../src/utils/getScaleBandwidth'; describe('grid utils', () => { describe('polarToCartesian', () => { const config = { radius: 20, angle: 20, }; it('should return cartesian output for the given polar input config', () => { const expected = { x: config.radius * Math.cos(config.angle), y: config.radius * Math.sin(config.angle), }; expect(polarToCartesian(config)).toEqual(expected); }); }); describe('getScaleBandwidth', () => { it('should return 0 for non-band scales', () => { expect( getScaleBandwidth( scaleLinear({ range: [0, 90], domain: [0, 100], }), ), ).toBe(0); }); it('should return the size of the band for band scales', () => { expect( getScaleBandwidth( scaleBand({ range: [0, 90], domain: ['a', 'b', 'c'], padding: 0, }), ), ).toBe(30); }); }); });
7,746
0
petrpan-code/airbnb/visx/packages/visx-group
petrpan-code/airbnb/visx/packages/visx-group/test/Group.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { Group } from '../src'; describe('<Group />', () => { test('it should be defined', () => { expect(Group).toBeDefined(); }); test("it should have class='visx-group'", () => { const wrapper = shallow(<Group />); expect(wrapper.prop('className')).toBe('visx-group'); }); test('it should default props top=0 left=0', () => { const wrapper = shallow(<Group />); expect(wrapper.prop('transform')).toBe('translate(0, 0)'); }); test('it should set props top, left, className', () => { const wrapper = shallow(<Group className="test" top={3} left={4} />); expect(wrapper.prop('transform')).toBe('translate(4, 3)'); expect(wrapper.prop('className')).toBe('visx-group test'); }); test('it should set restProps', () => { const wrapper = shallow(<Group clipPath="url(#myClip)" stroke="mapleSyrup" />); expect(wrapper.prop('clipPath')).toBe('url(#myClip)'); expect(wrapper.prop('stroke')).toBe('mapleSyrup'); }); });
7,747
0
petrpan-code/airbnb/visx/packages/visx-group
petrpan-code/airbnb/visx/packages/visx-group/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,756
0
petrpan-code/airbnb/visx/packages/visx-heatmap
petrpan-code/airbnb/visx/packages/visx-heatmap/test/HeatmapCircle.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { HeatmapCircle } from '../src'; const data: { bin: number; bins: { bin: number; count: number }[]; }[] = [{ bin: 0, bins: [{ bin: 0, count: 1 }] }]; const xScale = () => 50; const yScale = () => 50; const HeatmapWrapper = (props = {}) => shallow(<HeatmapCircle data={data} xScale={xScale} yScale={yScale} {...props} />); describe('<HeatmapCircle />', () => { test('it should be defined', () => { expect(HeatmapCircle).toBeDefined(); }); test('it should have the .visx-heatmap-circles class', () => { const wrapper = HeatmapWrapper(); expect(wrapper.prop('className')).toBe('visx-heatmap-circles'); }); test('it should have the .visx-heatmap-circle class', () => { const wrapper = HeatmapWrapper({ className: 'test' }); expect(wrapper.find('circle').prop('className')).toBe('visx-heatmap-circle test'); }); test('it should set <circle /> r to radius - gap', () => { const wrapper = HeatmapWrapper({ radius: 10, gap: 2 }); expect(wrapper.find('circle').prop('r')).toBe(8); }); });
7,757
0
petrpan-code/airbnb/visx/packages/visx-heatmap
petrpan-code/airbnb/visx/packages/visx-heatmap/test/HeatmapRect.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { HeatmapRect } from '../src'; const data: { bin: number; bins: { bin: number; count: number }[]; }[] = [{ bin: 0, bins: [{ bin: 0, count: 1 }] }]; const xScale = () => 50; const yScale = () => 50; const HeatmapWrapper = (props = {}) => shallow(<HeatmapRect data={data} xScale={xScale} yScale={yScale} {...props} />); describe('<HeatmapRect />', () => { test('it should be defined', () => { expect(HeatmapRect).toBeDefined(); }); test('it should have the .visx-heatmap-rects class', () => { const wrapper = HeatmapWrapper(); expect(wrapper.prop('className')).toBe('visx-heatmap-rects'); }); test('it should have the .visx-heatmap-rect class', () => { const wrapper = HeatmapWrapper({ className: 'test' }); expect(wrapper.find('rect').prop('className')).toBe('visx-heatmap-rect test'); }); test('it should set <rect /> width & height to bin{Width,Height} - gap', () => { const wrapper = HeatmapWrapper({ binWidth: 10, binHeight: 14, gap: 2 }); expect(wrapper.find('rect').prop('width')).toBe(8); expect(wrapper.find('rect').prop('height')).toBe(12); }); });
7,758
0
petrpan-code/airbnb/visx/packages/visx-heatmap
petrpan-code/airbnb/visx/packages/visx-heatmap/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,774
0
petrpan-code/airbnb/visx/packages/visx-hierarchy
petrpan-code/airbnb/visx/packages/visx-hierarchy/test/Cluster.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { hierarchy } from 'd3-hierarchy'; import { Cluster } from '../src'; import { ClusterProps } from '../src/hierarchies/Cluster'; type Datum = { name: string; children: Datum[] }; const childrenFunc = jest.fn(); const mockHierarchy = hierarchy({ name: 'Eve', children: [ { name: 'Cain' }, { name: 'Seth', children: [{ name: 'Enos' }, { name: 'Noam' }], }, ], } as Datum); const ClusterWrapper = (props: ClusterProps<Datum>) => shallow(<Cluster {...props} />); describe('<Cluster />', () => { test('it should be defined', () => { expect(Cluster).toBeDefined(); }); test('it should call children as a function with required args', () => { ClusterWrapper({ children: childrenFunc, root: mockHierarchy }); const args = childrenFunc.mock.calls[0][0]; expect(childrenFunc.mock.calls).toHaveLength(1); expect(args.data).toBeDefined(); }); });
7,775
0
petrpan-code/airbnb/visx/packages/visx-hierarchy
petrpan-code/airbnb/visx/packages/visx-hierarchy/test/Defaults.test.tsx
import { HierarchyDefaultLink, HierarchyDefaultNode, HierarchyDefaultRectNode, hierarchy, stratify, treemapBinary, treemapDice, treemapResquarify, treemapSlice, treemapSliceDice, treemapSquarify, } from '../src'; describe('<DefaultLink />', () => { test('should be defined', () => { expect(HierarchyDefaultLink).toBeDefined(); }); }); describe('<DefaultNode />', () => { test('should be defined', () => { expect(HierarchyDefaultNode).toBeDefined(); }); }); describe('<DefaultRectNode />', () => { test('should be defined', () => { expect(HierarchyDefaultRectNode).toBeDefined(); }); }); describe('d3 exports', () => { test('should export hierarchy', () => { expect(hierarchy).toBeDefined(); }); test('should export stratify', () => { expect(stratify).toBeDefined(); }); test('should export treemap tiling functions', () => { const tilers = [ treemapBinary, treemapDice, treemapResquarify, treemapSlice, treemapSliceDice, treemapSquarify, ]; expect.assertions(tilers.length); tilers.forEach((tiler) => { expect(tiler).toBeDefined(); }); }); });
7,776
0
petrpan-code/airbnb/visx/packages/visx-hierarchy
petrpan-code/airbnb/visx/packages/visx-hierarchy/test/Tree.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { hierarchy } from 'd3-hierarchy'; import { Tree } from '../src'; import { TreeProps } from '../src/hierarchies/Tree'; type Datum = { name: string; children: Datum[] }; const childrenFunc = jest.fn(); const mockHierarchy = hierarchy({ name: 'Eve', children: [ { name: 'Cain' }, { name: 'Seth', children: [{ name: 'Enos' }, { name: 'Noam' }], }, ], } as Datum); const TreeWrapper = (props: TreeProps<Datum>) => shallow(<Tree {...props} />); describe('<Tree />', () => { test('it should be defined', () => { expect(Tree).toBeDefined(); }); test('it should call children as a function with required args', () => { TreeWrapper({ children: childrenFunc, root: mockHierarchy }); const args = childrenFunc.mock.calls[0][0]; expect(childrenFunc.mock.calls).toHaveLength(1); expect(args.data).toBeDefined(); }); });
7,777
0
petrpan-code/airbnb/visx/packages/visx-hierarchy
petrpan-code/airbnb/visx/packages/visx-hierarchy/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,801
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/Legend.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleLinear } from '@visx/scale'; import { Legend, LegendLabel } from '../src'; const defaultProps = { scale: scaleLinear<number>({ range: [10, 0], round: true, domain: [0, 10], }), }; describe('<Legend />', () => { test('it should be defined', () => { expect(Legend).toBeDefined(); }); test('it should default style to display: flex, flex-direction: column', () => { const wrapper = shallow(<Legend {...defaultProps} />); expect(wrapper.prop('style')).toEqual({ display: 'flex', flexDirection: 'column', }); }); test('it should extend style prop', () => { const wrapper = shallow(<Legend {...defaultProps} style={{ display: 'block' }} />); expect(wrapper.prop('style')).toEqual({ display: 'block', flexDirection: 'column', }); }); test('it should pass through direction prop to style prop', () => { const wrapper = shallow(<Legend {...defaultProps} direction="row" />); expect(wrapper.prop('style')).toEqual({ display: 'flex', flexDirection: 'row', }); }); test('it should pass through legendLabelProps to legend labels', () => { const style = { fontFamily: 'Comic Sans' }; const wrapper = shallow(<Legend {...defaultProps} legendLabelProps={{ style }} />); const label = wrapper.find(LegendLabel).first(); expect(label.prop('style')).toEqual(style); }); });
7,802
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/LegendLinear.test.tsx
import { LegendLinear } from '../src'; describe('<LegendLinear />', () => { test('it should be defined', () => { expect(LegendLinear).toBeDefined(); }); });
7,803
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/LegendOrdinal.test.tsx
import { LegendOrdinal } from '../src'; describe('<LegendLOrdinal />', () => { test('it should be defined', () => { expect(LegendOrdinal).toBeDefined(); }); });
7,804
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/LegendQuantile.test.tsx
import { LegendQuantile } from '../src'; describe('<LegendQuantile />', () => { test('it should be defined', () => { expect(LegendQuantile).toBeDefined(); }); });
7,805
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/LegendSize.test.tsx
import { LegendSize } from '../src'; describe('<LegendSize />', () => { test('it should be defined', () => { expect(LegendSize).toBeDefined(); }); });
7,806
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/LegendThreshold.test.tsx
import { LegendThreshold } from '../src'; describe('<LegendThreshold />', () => { test('it should be defined', () => { expect(LegendThreshold).toBeDefined(); }); });
7,807
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/scales.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { scaleBand, scaleLinear, scaleOrdinal, scaleThreshold, scaleQuantile } from '@visx/scale'; import { Legend, LegendLinear, LegendOrdinal, LegendSize, LegendThreshold, LegendQuantile, } from '../src'; describe('Legend scales', () => { it('should render with scaleLinear', () => { const linearScale = scaleLinear<number>({ domain: [0, 10], range: [1, 5, 10, 15, 20], }); expect(() => shallow(<LegendLinear scale={linearScale} />)).not.toThrow(); expect(() => shallow(<LegendSize scale={linearScale} />)).not.toThrow(); expect(() => shallow(<Legend scale={linearScale} />)).not.toThrow(); }); it('should render with scaleOrdinal', () => { const ordinalScale = scaleOrdinal<string, string>({ domain: ['a', 'b', 'c', 'd'], range: ['#66d981', '#71f5ef', '#4899f1', '#7d81f6'], }); expect(() => shallow(<LegendOrdinal scale={ordinalScale} />)).not.toThrow(); expect(() => shallow(<Legend scale={ordinalScale} />)).not.toThrow(); }); it('should render with scaleBand', () => { const bandScale = scaleBand<string>({ domain: ['a', 'b', 'c', 'd'], range: [1, 10], }); expect(() => shallow(<Legend scale={bandScale} />)).not.toThrow(); }); it('should render with scaleThreshold', () => { const thresholdScale = scaleThreshold<number, string>({ domain: [0.01, 0.02, 0.04, 0.06, 0.08, 0.1], range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f'], }); expect(() => shallow(<LegendThreshold scale={thresholdScale} />)).not.toThrow(); expect(() => shallow(<Legend scale={thresholdScale} />)).not.toThrow(); }); it('should render with scaleQuantile', () => { const quantileScale = scaleQuantile<string>({ domain: [0.01, 0.02, 0.04, 0.06, 0.08, 0.1], range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f'], }); expect(() => shallow(<LegendQuantile scale={quantileScale} />)).not.toThrow(); expect(() => shallow(<Legend scale={quantileScale} />)).not.toThrow(); }); });
7,808
0
petrpan-code/airbnb/visx/packages/visx-legend
petrpan-code/airbnb/visx/packages/visx-legend/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,820
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/Arrow.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { MarkerArrow, Marker } from '../src'; const Wrapper = (restProps = {}) => shallow(<MarkerArrow id="marker-circle-test" {...restProps} />); describe('<MarkerArrow />', () => { test('it should be defined', () => { expect(MarkerArrow).toBeDefined(); }); test('it should render a <Marker> containing a <g>, <polyline>', () => { const marker = Wrapper().find(Marker); const g = marker.dive().find('g'); const polyline = marker.dive().find('polyline'); expect(marker).toHaveLength(1); expect(g).toHaveLength(1); expect(polyline).toHaveLength(1); }); test('it should size correctly', () => { const size = 8; const strokeWidth = 1; const marker = Wrapper({ size, strokeWidth }).find(Marker); const g = marker.dive().find('g'); const polyline = marker.dive().find('polyline'); const max = size + strokeWidth * 2; const midX = size; const midY = max / 2; const points = `0 0, ${size} ${size / 2}, 0 ${size}`; expect(marker.prop('markerWidth')).toEqual(max); expect(marker.prop('markerHeight')).toEqual(max); expect(marker.prop('refX')).toEqual(midX); expect(marker.prop('refY')).toEqual(midY); expect(g.prop('transform')).toBe(`translate(${strokeWidth}, ${strokeWidth})`); expect(polyline.prop('points')).toEqual(points); }); });
7,821
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/Circle.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { MarkerCircle, Marker } from '../src'; const Wrapper = (restProps = {}) => shallow(<MarkerCircle id="marker-circle-test" {...restProps} />); describe('<MarkerCircle />', () => { test('it should be defined', () => { expect(MarkerCircle).toBeDefined(); }); test('it should render a <Marker> containing a <circle>', () => { const marker = Wrapper().find(Marker); const circle = marker.dive().find('circle'); expect(marker).toHaveLength(1); expect(circle).toHaveLength(1); }); test('it should size correctly', () => { const size = 8; const strokeWidth = 1; const marker = Wrapper({ size, strokeWidth }).find(Marker); const circle = marker.dive().find('circle'); const diameter = size * 2; const bounds = diameter + strokeWidth; const mid = bounds / 2; expect(marker.prop('markerWidth')).toEqual(bounds); expect(marker.prop('markerHeight')).toEqual(bounds); expect(marker.prop('refX')).toBe(0); expect(marker.prop('refY')).toEqual(mid); expect(circle.prop('r')).toEqual(size); expect(circle.prop('cx')).toEqual(mid); expect(circle.prop('cy')).toEqual(mid); }); });
7,822
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/Cross.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { MarkerCross, Marker } from '../src'; const Wrapper = (restProps = {}) => shallow(<MarkerCross id="marker-cross-test" {...restProps} />); describe('<MarkerCross />', () => { test('it should be defined', () => { expect(MarkerCross).toBeDefined(); }); test('it should render a <Marker> containing a <polyline>', () => { const marker = Wrapper().find(Marker); const polyline = marker.dive().find('polyline'); expect(marker).toHaveLength(1); expect(polyline).toHaveLength(1); }); test('it should size correctly', () => { const size = 8; const strokeWidth = 1; const marker = Wrapper({ size, strokeWidth }).find(Marker); const polyline = marker.dive().find('polyline'); const bounds = size + strokeWidth; const mid = size / 2; const points = `0 ${mid}, ${mid} ${mid}, ${mid} 0, ${mid} ${size}, ${mid} ${mid}, ${size} ${mid}`; expect(marker.prop('markerWidth')).toEqual(bounds); expect(marker.prop('markerHeight')).toEqual(bounds); expect(marker.prop('refX')).toEqual(mid); expect(marker.prop('refY')).toEqual(mid); expect(polyline.prop('points')).toEqual(points); }); });
7,823
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/Line.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { MarkerLine, Marker } from '../src'; const Wrapper = (restProps = {}) => shallow(<MarkerLine id="marker-line-test" {...restProps} />); describe('<MarkerLine />', () => { test('it should be defined', () => { expect(MarkerLine).toBeDefined(); }); test('it should render a <Marker> containing a <rect>', () => { const marker = Wrapper().find(Marker); const rect = marker.dive().find('rect'); expect(marker).toHaveLength(1); expect(rect).toHaveLength(1); }); test('it should size correctly', () => { const size = 8; const strokeWidth = 1; const stroke = 'blue'; const marker = Wrapper({ size, stroke, strokeWidth }).find(Marker); const rect = marker.dive().find('rect'); const max = Math.max(size, strokeWidth * 2); const midX = max / 2; const midY = size / 2; expect(marker.prop('markerWidth')).toEqual(max); expect(marker.prop('markerHeight')).toEqual(size); expect(marker.prop('refX')).toEqual(midX); expect(marker.prop('refY')).toEqual(midY); expect(marker.prop('fill')).toEqual(stroke); expect(rect.prop('width')).toEqual(strokeWidth); expect(rect.prop('height')).toEqual(size); expect(rect.prop('x')).toEqual(midX); }); });
7,824
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/Marker.test.tsx
import { Marker } from '../src'; describe('<Marker />', () => { test('it should be defined', () => { expect(Marker).toBeDefined(); }); });
7,825
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/X.test.tsx
import React from 'react'; import { shallow } from 'enzyme'; import { MarkerX, MarkerCross } from '../src'; const Wrapper = (restProps = {}) => shallow(<MarkerX id="marker-x-test" {...restProps} />); describe('<MarkerX />', () => { test('it should be defined', () => { expect(MarkerX).toBeDefined(); }); test('it should render a <MarkerCross /> rotated 45deg', () => { const cross = Wrapper().find(MarkerCross); expect(cross).toHaveLength(1); expect(cross.prop('orient')).toBe(45); }); });
7,826
0
petrpan-code/airbnb/visx/packages/visx-marker
petrpan-code/airbnb/visx/packages/visx-marker/test/tsconfig.json
{ "compilerOptions": { "composite": false, "emitDeclarationOnly": false, "noEmit": true, "rootDir": "." }, "extends": "../../../tsconfig.options.json", "include": ["**/*", "../types/**/*", "../../../types/**/*"], "references": [ { "path": ".." } ] }
7,849
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/appleStock.test.ts
import { appleStock } from '../src'; describe('mocks/appleStock', () => { test('it should be defined', () => { expect(appleStock).toBeDefined(); }); test('it should be an array', () => { expect(appleStock.length).toBeDefined(); }); test('it should return [{ date, close }]', () => { const data = appleStock; expect(data[0].date).toBeDefined(); expect(data[0].close).toBeDefined(); }); });
7,850
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/browserUsage.test.ts
import { browserUsage } from '../src'; describe('mocks/browserUsage', () => { test('it should be defined', () => { expect(browserUsage).toBeDefined(); }); test('it should be an array', () => { expect(browserUsage.length).toBeDefined(); }); test('it should return [{ date, browser names }]', () => { const data = browserUsage; expect(data[0].date).toBeDefined(); expect(data[0]['Google Chrome']).toBeDefined(); expect(data[0]['Microsoft Edge']).toBeDefined(); expect(data[0]['Internet Explorer']).toBeDefined(); expect(data[0].Safari).toBeDefined(); expect(data[0].Opera).toBeDefined(); expect(data[0].Mozilla).toBeDefined(); expect(data[0].Firefox).toBeDefined(); expect(data[0]['Other/Unknown']).toBeDefined(); }); });
7,851
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/cityTemperature.test.ts
import { cityTemperature } from '../src'; describe('mocks/cityTemperature', () => { test('it should be defined', () => { expect(cityTemperature).toBeDefined(); }); test('it should be an array', () => { expect(cityTemperature.length).toBeDefined(); }); test('it should return [{ date, city names }]', () => { const data = cityTemperature; expect(data[0].date).toBeDefined(); expect(data[0]['New York']).toBeDefined(); expect(data[0]['San Francisco']).toBeDefined(); expect(data[0].Austin).toBeDefined(); expect(typeof data[0]['New York']).toBe('string'); }); });
7,852
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genBin.test.ts
import { genBin, getSeededRandom } from '../src'; describe('generators/genBin', () => { it('should be defined', () => { expect(genBin).toBeDefined(); }); it('should have shape [{ bin, count }]', () => { const bin = genBin(1); expect(bin).toHaveLength(1); expect(bin[0].bin).toBeDefined(); expect(bin[0].count).toBeDefined(); }); it('should take optional bin function', () => { const bin = genBin(1, (i) => i); expect(bin[0].bin).toBe(0); }); it('should take an optional count function', () => { const bin = genBin(1, undefined, (i) => i); expect(bin[0].count).toBe(0); expect(bin[0].bin).toBe(0); }); it('should support seeded randomness', () => { const n = 3; const seededRandom1 = getSeededRandom(0.5); const seededRandom2 = getSeededRandom(0.5); expect( genBin( n, (i) => i, (i, number) => 25 * (number - i) * seededRandom1(), ), ).toEqual( genBin( n, (i) => i, (i, number) => 25 * (number - i) * seededRandom2(), ), ); }); });
7,853
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genBins.test.ts
import { genBins, getSeededRandom } from '../src'; describe('generators/genBins', () => { it('should be defined', () => { expect(genBins).toBeDefined(); }); it('should have the shape of [{bin, bins: [{ bin, count }]}]', () => { const bins = genBins(1, 2); expect(bins[0].bin).toBe(0); expect(bins).toHaveLength(1); expect(bins[0].bins).toHaveLength(2); expect(bins[0].bins[1].bin).toBe(150); }); it('should take an optional bin function parameter', () => { const bins = genBins(1, 1, (i) => i); expect(bins[0].bins[0].bin).toBe(0); }); it('should take an optional count function parameter', () => { const bins = genBins(1, 1, undefined, (i) => i); expect(bins[0].bins[0].count).toBe(0); }); it('should support seeded randomness', () => { const seededRandom1 = getSeededRandom(0.5); const seededRandom2 = getSeededRandom(0.5); expect( genBins( 2, 2, (i) => i, (i, number) => 25 * (number - i) * seededRandom1(), ), ).toEqual( genBins( 2, 2, (i) => i, (i, number) => 25 * (number - i) * seededRandom2(), ), ); }); });
7,854
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genDateValue.test.ts
import { genDateValue } from '../src'; describe('generators/genDateValue', () => { it('should be defined', () => { expect(genDateValue).toBeDefined(); }); it('should be function', () => { expect(typeof genDateValue).toBe('function'); }); it('should return a array of n', () => { const n = 3; const data = genDateValue(n); expect(data).toHaveLength(3); }); it('should return [{ date, value }]', () => { const n = 1; const data = genDateValue(n); expect(data[0].date.constructor).toEqual(Date); expect(typeof data[0].value).toBe('number'); }); it('should should use a start date and seed if provided', () => { const n = 3; const seed = 0.5; const startDate = new Date('2020-01-01').getUTCMilliseconds(); expect(genDateValue(n, seed, startDate)).toEqual(genDateValue(n, seed, startDate)); }); });
7,855
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genPhyllotaxis.test.ts
import { genPhyllotaxis } from '../src'; describe('generators/genPhyllotaxis', () => { test('it should be defined', () => { expect(genPhyllotaxis).toBeDefined(); }); test('it should return a function', () => { const pointFn = genPhyllotaxis({ radius: 10, width: 200, height: 200, }); expect(typeof pointFn).toBe('function'); }); test('it should return a point [x, y] when calling the returned function', () => { const pointFn = genPhyllotaxis({ radius: 10, width: 200, height: 200, }); const point = pointFn(3); const expected = { x: 110, y: 113 }; expect(Math.floor(point.x)).toEqual(expected.x); expect(Math.floor(point.y)).toEqual(expected.y); }); });
7,856
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genRandomNormalPoints.test.ts
import { genRandomNormalPoints } from '../src'; describe('generators/genRandomNormalPoints', () => { it('should be defined', () => { expect(genRandomNormalPoints).toBeDefined(); }); it('should be function', () => { expect(typeof genRandomNormalPoints).toBe('function'); }); it('should default to 3x300 points', () => { const data = genRandomNormalPoints(); expect(data).toHaveLength(900); }); it('should return 3 * n', () => { const n = 3; const data = genRandomNormalPoints(n); expect(data).toHaveLength(9); }); it('should return points with x, y, index', () => { const n = 3; const data = genRandomNormalPoints(n); expect(data[0]).toHaveLength(3); expect(data[0][0]).toBeDefined(); expect(data[0][1]).toBeDefined(); expect(data[0][2]).toBeDefined(); expect(data[0][2]).toBe(0); expect(data[3][2]).toBe(1); expect(data[6][2]).toBe(2); }); it('should support seeded randomness', () => { const n = 3; const data1 = genRandomNormalPoints(n, 0.5); const data2 = genRandomNormalPoints(n, 0.5); expect(data1).toMatchObject(data2); }); });
7,857
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/genStats.test.ts
import { genStats, getSeededRandom } from '../src'; describe('generators/genStats', () => { it('should be defined', () => { expect(genStats).toBeDefined(); }); it('should have boxPlot and binData', () => { const data = genStats(2); expect(data.length).toBeDefined(); expect(data).toHaveLength(2); expect(data[0].boxPlot).toBeDefined(); expect(data[0].binData).toBeDefined(); }); it('should support seeded randomness', () => { const data1 = genStats(1, getSeededRandom(0.5), getSeededRandom(0.75)); const data2 = genStats(1, getSeededRandom(0.5), getSeededRandom(0.75)); expect(data1).toMatchObject(data2); }); });
7,858
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/getSeededRandom.test.ts
import { getSeededRandom } from '../src'; describe('generators/getSeededRandom', () => { it('should be defined', () => { expect(getSeededRandom).toBeDefined(); }); it('should return a random number generator that returns the same value given the same seed', () => { const random1 = getSeededRandom(0.5)(); const random2 = getSeededRandom(0.5)(); const random3 = getSeededRandom(0.1)(); expect(random1).toEqual(random2); expect(random1).not.toEqual(random3); }); });
7,859
0
petrpan-code/airbnb/visx/packages/visx-mock-data
petrpan-code/airbnb/visx/packages/visx-mock-data/test/groupDateValue.test.ts
import { groupDateValue } from '../src'; describe('mocks/groupDateValue', () => { test('it should be defined', () => { expect(groupDateValue).toBeDefined(); }); test('it should be an array', () => { expect(groupDateValue.length).toBeDefined(); }); test('it should return [{ key, value, date }]', () => { const data = groupDateValue; expect(data[0].key).toBeDefined(); expect(data[0].value).toBeDefined(); expect(data[0].date).toBeDefined(); }); });