-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(calendar): add test for Calendar component
- Loading branch information
Raphael Benitte
committed
May 11, 2016
1 parent
e11737d
commit 31eb720
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}); | ||
}); |