Skip to content

Commit

Permalink
Run prettier (tests included)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkp committed Oct 25, 2017
1 parent 210a2e7 commit 839b973
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 131 deletions.
131 changes: 64 additions & 67 deletions test/Calendar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,79 +11,76 @@ import chai from 'chai';

const expect = chai.expect;


describe('Calendar', () => {

const onSelect = function(date) {
return true
//console.info('onSelect', date);
const onSelect = function(date) {
return true;
//console.info('onSelect', date);
};

it('displays the correct year', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).assertYear('2015');
});

it('displays the correct month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).assertMonth('April');
});

it('should be able to go to previous month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar)
.previousMonth()
.assertMonth('March');
});

it('should be able to go to next month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar)
.nextMonth()
.assertMonth('May');
});

it('should trigger the callback with selected date when clicking a day', function(
done
) {
const callback = function(selectedDate) {
expect(moment(selectedDate).format('DD/MM/YYYY')).to.equal('08/04/2015');
done();
};

const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={callback} />
);

it('displays the correct year', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).assertYear('2015');
});


it('displays the correct month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).assertMonth('April');
});


it('should be able to go to previous month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).previousMonth().assertMonth('March');
});


it('should be able to go to next month', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar).nextMonth().assertMonth('May');
});


it('should trigger the callback with selected date when clicking a day', function(done) {
const callback = function(selectedDate) {
expect(moment(selectedDate).format('DD/MM/YYYY')).to.equal('08/04/2015');
done();
};

const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={callback} />
);

asserter(calendar).clickDay(8);
});


it('should set selected date to selected', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);
asserter(calendar).clickDay(8);
});

asserter(calendar).clickDay(8).assertSelectedDay(8);
});
it('should set selected date to selected', () => {
const calendar = (
<Calendar date={moment('03/04/2015', 'DD/MM/YYYY')} onSelect={onSelect} />
);

asserter(calendar)
.clickDay(8)
.assertSelectedDay(8);
});

it('should add class to today', () => {
const calendar = (
<Calendar date={moment()} onSelect={onSelect} />
);
it('should add class to today', () => {
const calendar = <Calendar date={moment()} onSelect={onSelect} />;

asserter(calendar).assertToday();
});
asserter(calendar).assertToday();
});
});
138 changes: 74 additions & 64 deletions test/assertions/Asserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,77 @@ import chai from 'chai';

const expect = chai.expect;


export default (jsx) => {


const calendar = ReactTestUtils.renderIntoDocument(jsx);


return {

assertYear(expectedYear) {
const year = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'year');
expect(ReactDOM.findDOMNode(year).textContent).to.equal(expectedYear);
return this;
},


assertMonth(expectedMonth) {
const month = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'month');
expect(ReactDOM.findDOMNode(month).textContent).to.equal(expectedMonth);
return this;
},


previousMonth() {
const previous = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'previous');
ReactTestUtils.Simulate.click(previous.firstChild);
return this;
},


nextMonth() {
const next = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'next');
ReactTestUtils.Simulate.click(next.firstChild);
return this;
},


assertSelectedDay(expectedDay) {
const selected = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'selected');
const value = ReactDOM.findDOMNode(selected).textContent;
expect(+value).to.equal(expectedDay);
return this;
},


assertToday() {
const today = ReactTestUtils.findRenderedDOMComponentWithClass(calendar, 'today');
const value = ReactDOM.findDOMNode(today).textContent;
expect(value).to.equal(moment().format('D'));
return this;
},


clickDay(date) {
const days = ReactTestUtils.scryRenderedDOMComponentsWithClass(calendar, 'Day');
const found = days.filter((day) => {
var value = ReactDOM.findDOMNode(day).dataset.day;
return +value === date;
});
ReactTestUtils.Simulate.click(found[0].firstChild);
return this;
}
}
}
export default jsx => {
const calendar = ReactTestUtils.renderIntoDocument(jsx);

return {
assertYear(expectedYear) {
const year = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'year'
);
expect(ReactDOM.findDOMNode(year).textContent).to.equal(expectedYear);
return this;
},

assertMonth(expectedMonth) {
const month = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'month'
);
expect(ReactDOM.findDOMNode(month).textContent).to.equal(expectedMonth);
return this;
},

previousMonth() {
const previous = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'previous'
);
ReactTestUtils.Simulate.click(previous.firstChild);
return this;
},

nextMonth() {
const next = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'next'
);
ReactTestUtils.Simulate.click(next.firstChild);
return this;
},

assertSelectedDay(expectedDay) {
const selected = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'selected'
);
const value = ReactDOM.findDOMNode(selected).textContent;
expect(+value).to.equal(expectedDay);
return this;
},

assertToday() {
const today = ReactTestUtils.findRenderedDOMComponentWithClass(
calendar,
'today'
);
const value = ReactDOM.findDOMNode(today).textContent;
expect(value).to.equal(moment().format('D'));
return this;
},

clickDay(date) {
const days = ReactTestUtils.scryRenderedDOMComponentsWithClass(
calendar,
'Day'
);
const found = days.filter(day => {
var value = ReactDOM.findDOMNode(day).dataset.day;
return +value === date;
});
ReactTestUtils.Simulate.click(found[0].firstChild);
return this;
},
};
};

0 comments on commit 839b973

Please sign in to comment.