Skip to content

Commit

Permalink
feat(calendar): add test for Calendar component
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Benitte committed May 11, 2016
1 parent e11737d commit 31eb720
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions specs/calendar/Calendar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 { Calendar } from '../../src/';


describe('<Calendar />', 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((
<Calendar
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)}
/>
), 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((
<Calendar
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)}
/>
), node, () => {
setTimeout(() => {
const months = node.getElementsByClassName('nivo_calendar_month');
expect(months).toNotBe(null);
expect(months.length).toBe(12 * 2);

const monthLegends = node.getElementsByClassName('nivo_calendar_month_legend');
expect(monthLegends).toNotBe(null);
expect(monthLegends.length).toBe(12 * 2);

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

it('should render a label for each year', done => {
render((
<Calendar
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)}
/>
), 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((
<Calendar
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"
/>
), 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 31eb720

Please sign in to comment.