import { withRootEdge } from '../../shared/line/with-root-edge';
import { absoluteFromTwoPoints, buildDataPoints } from '@pie-lib/graphing-utils';
import { utils } from '@pie-lib/plot';

import { graphProps as getGraphProps } from '../../../__tests__/utils';

const { xy } = utils;

jest.mock('@pie-lib/graphing-utils', () => ({
  buildDataPoints: jest.fn().mockReturnValue([]),
  absoluteFromTwoPoints: jest.fn(() => jest.fn()),
  getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
}));

jest.mock('../../shared/line/with-root-edge', () => ({
  withRootEdge: jest.fn(),
  rootEdgeComponent: jest.fn(),
}));

describe('Absolute', () => {
  let fnBody;
  let graphProps;
  let root;
  let edge;
  let result;

  beforeEach(() => {
    require('../component');
    fnBody = withRootEdge.mock.calls[0][0];
    graphProps = getGraphProps();
    root = xy(0, 0);
    edge = xy(1, 1);

    result = fnBody({ graphProps, root, edge });
  });

  it('fnBody is not null', () => {
    expect(fnBody).toBeDefined();
  });

  it('calls buildDataPoints', () => {
    const { domain, range } = graphProps;
    expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
  });

  it('calls absoluteFromTwoPoints', () => {
    expect(absoluteFromTwoPoints).toHaveBeenCalledWith(root, edge);
  });

  it('returns dataPoints', () => {
    expect(result).toEqual({ enableCurve: false, root, edge, dataPoints: [] });
  });
});
