From 130383f7a90b8fefa9b8870e9c7b4a035eb8b88c Mon Sep 17 00:00:00 2001 From: Flaqueeau Date: Tue, 11 Jul 2017 19:51:06 -0700 Subject: [PATCH] [Axis] Add tests to Axis.test.js --- packages/vx-axis/test/Axis.test.js | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/packages/vx-axis/test/Axis.test.js b/packages/vx-axis/test/Axis.test.js index be90ebad0..663c031df 100644 --- a/packages/vx-axis/test/Axis.test.js +++ b/packages/vx-axis/test/Axis.test.js @@ -1,7 +1,62 @@ +import React from 'react'; import { Axis } from '../src'; +import { shallow } from 'enzyme'; +import { scaleLinear } from '../../vx-scale'; + +const fakeScale = scaleLinear({ + rangeRound: [10, 0], + domain: [0, 10], +}); describe('', () => { test('it should be defined', () => { expect(Axis).toBeDefined() }) + + test('it should render with class .vx-axis', () => { + const wrapper = shallow() + expect(wrapper.prop('className')).toEqual('vx-axis') + }) + + test('it should pass users class down to element', () => { + const fakeClass = "test-class" + const wrapper = shallow() + expect(wrapper.prop('className')).toEqual(`vx-axis ${fakeClass}`); + }) + + test('it should render the 0th element if the user so declares', () => { + // Note that we're explicitly passing in false so that we're testing + // the rendering, NOT wether or not this is a default value. + const wrapper = shallow() + expect(wrapper.find('.vx-axis-ticks').at(0).key()).toBe('vx-tick-0-0'); + }) + + test('it should not show 0th tick if the user so declares', () => { + const wrapper = shallow() + expect(wrapper.find('.vx-axis-ticks').at(0).key()).toBe('vx-tick-1-1'); + }) + + test('it should SHOW an axis line if the user so declares', () => { + // Again, we're explicitly passing in false so we're testing + // the rendering, NOT the default value. + const wrapper = shallow() + expect(wrapper.children().not(".vx-axis-ticks").find("Line").length).toBe(1); + }) + + test('it should HIDE an axis line if the user so declares', () => { + const wrapper = shallow() + expect(wrapper.children().not(".vx-axis-ticks").find("Line").length).toBe(0); + }) + + test('it should SHOW ticks if the user', () => { + // Again, we're explicitly passing in false so we're testing + // the rendering, NOT the default value. + const wrapper = shallow() + expect(wrapper.children().find(".vx-axis-ticks").find("Line").length).toBeGreaterThan(0); + }) + + test('it should HIDE ticks if the user', () => { + const wrapper = shallow() + expect(wrapper.children().find(".vx-axis-ticks").find("Line").length).toBe(0); + }) })