Skip to content

Commit

Permalink
feat(calendar): add test for CalendarD3 component
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Benitte committed May 11, 2016
1 parent 1ef5b5e commit d972002
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion specs/bubble/Bubble.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('<Bubble />', function () {
expect(circles.length).toBe(11);

done();
}, 4000);
}, 400);
})
});
});
2 changes: 1 addition & 1 deletion specs/bubble/BubbleD3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('<BubbleD3 />', function () {
expect(circles.length).toBe(11);

done();
}, 4000);
}, 400);
})
});
});
110 changes: 110 additions & 0 deletions specs/calendar/CalendarD3.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This file is part of the nivo library.
*
* (c) Raphaël Benitte
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';

import expect, { spyOn } from 'expect';
import React, { Component } from 'react';
import { render } from 'react-dom';
import { CalendarD3 } from '../../src/';


describe('<CalendarD3 />', function () {
this.timeout(10000);

let node;
beforeEach(() => {
node = document.createElement('div');
document.body.appendChild(node);
});

afterEach(() => {
document.body.removeChild(node);
});

it('should render all years days', done => {
render((
<CalendarD3
width={700} height={400}
margin={{ top: 30, right: 30, bottom: 30, left: 30 }}
from={new Date(2013, 3, 1)} to={new Date(2014, 7, 12)}
transitionDuration={0}
transitionStaggering={0}
/>
), node, () => {
setTimeout(() => {
const days = node.getElementsByClassName('nivo_calendar_day');
expect(days).toNotBe(null);
expect(days.length).toBe(365 * 2);

done();
}, 400);
})
});

it('should render all years months', done => {
render((
<CalendarD3
width={700} height={400}
margin={{ top: 30, right: 30, bottom: 30, left: 30 }}
from={new Date(2013, 3, 1)} to={new Date(2014, 7, 12)}
transitionDuration={0}
transitionStaggering={0}
/>
), node, () => {
setTimeout(() => {
const months = node.getElementsByClassName('nivo_calendar_month');
expect(months).toNotBe(null);
expect(months.length).toBe(12 * 2);

done();
}, 400);
})
});

it('should render a label for each year', done => {
render((
<CalendarD3
width={700} height={400}
margin={{ top: 30, right: 30, bottom: 30, left: 30 }}
from={new Date(2013, 3, 1)} to={new Date(2014, 7, 12)}
transitionDuration={0}
transitionStaggering={0}
/>
), node, () => {
setTimeout(() => {
const legends = node.getElementsByClassName('nivo_calendar_year_legend');
expect(legends).toNotBe(null);
expect(legends.length).toBe(2);

done();
}, 400);
})
});

it('should support vertical layout', done => {
render((
<CalendarD3
width={400} height={700}
margin={{ top: 30, right: 30, bottom: 30, left: 30 }}
from={new Date(2013, 3, 1)} to={new Date(2014, 7, 12)}
direction="vertical"
transitionDuration={0}
transitionStaggering={0}
/>
), node, () => {
setTimeout(() => {
const days = node.getElementsByClassName('nivo_calendar_day');
expect(days).toNotBe(null);
expect(days.length).toBe(365 * 2);

done();
}, 400);
})
});
});

0 comments on commit d972002

Please sign in to comment.