import Component from '../horizontal-bar-background';
import TestFunctions from './__test-functions__';
import d3 from 'd3';
import React from 'react';

describe('HorizontalBarBackground', () => {
  const { renderIntoDocument } = React.addons.TestUtils;

  TestFunctions.isOfExpectedType(Component, 'g', 'horizontal-bar-background');

  TestFunctions.hasExpectedDefaultProps(Component, {
    active: false,
    corners: {},
    height: 0,
    scale: Function,
    style: {},
    value: 0,
    width: 0,
    x: 0,
  });

  TestFunctions.hasExpectedInitialState(Component, {
    backgroundWidth: 0,
    fill: '',
    fillActive: '',
    style: null,
  });

  describe('has a getBackgroundWidth function that', () => {
    const component = renderIntoDocument(<Component />);
    it('uses a scale to calculate a background width', () => {
      const scale = d3.scale.linear().domain([0, 100]).range([0, 100]);
      expect(component.getBackgroundWidth(scale, 0)).toEqual(0);
      expect(component.getBackgroundWidth(scale, 50)).toEqual(50);
      expect(component.getBackgroundWidth(scale, 100)).toEqual(100);
    });
  });
});
