Simon Egersand
2017-02-09 89e53205334226b3f0654e86f93f5a5fba285840
Add test for updating dateFormat
2 files modified
23 ■■■■ changed files
example/formatChangeExample.js 10 ●●●● patch | view | raw | blame | history
tests/datetime.spec.js 13 ●●●●● patch | view | raw | blame | history
example/formatChangeExample.js
@@ -6,14 +6,14 @@
var Wrapper = React.createClass({
    getInitialState: function() {
        return {
            dateFormat: 'YYYY-mm-DD'
            dateFormat: 'YYYY-MM-DD'
        };
    },
    updateFormat: function(format) {
        console.log('changing state');
        this.setState({
            dateFormat: 'DD.mm.YYYY'
            dateFormat: 'DD.MM.YYYY'
        });
    },
@@ -23,11 +23,11 @@
    render: function() {
        return React.createElement(DateTime,
            { dateFormat: this.state.dateFormat, timeFormat: false, defaultValue: moment()     });
            { dateFormat: this.state.dateFormat, timeFormat: false, defaultValue: moment() });
    }
});
ReactDOM.render(
  React.createElement(Wrapper),
  document.getElementById('datetime')
    React.createElement(Wrapper),
    document.getElementById('datetime')
);
tests/datetime.spec.js
@@ -156,6 +156,19 @@
        expect(utils.isOpen(component)).toBeTruthy();
    });
    it('dateFormat -> prop changes and value updates accordingly', () => {
        const date = new Date(2000, 0, 15, 2, 2, 2, 2),
            component = utils.createDatetime({
                dateFormat: 'YYYY-MM-DD', timeFormat: false, defaultValue: date
            });
        const valueBefore = utils.getInputValue(component);
        component.setProps({ dateFormat: 'DD.MM.YYYY'});
        const valueAfter = utils.getInputValue(component);
        expect(valueBefore).not.toEqual(valueAfter);
    });
    describe('with custom props', () => {
        it('input=false', () => {
            const component = utils.createDatetime({ input: false });