From 89e53205334226b3f0654e86f93f5a5fba285840 Mon Sep 17 00:00:00 2001
From: Simon Egersand <s.egersand@gmail.com>
Date: Thu, 09 Feb 2017 21:30:01 +0100
Subject: [PATCH] Add test for updating dateFormat

---
 example/formatChangeExample.js |   10 +++++-----
 tests/datetime.spec.js         |   13 +++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/example/formatChangeExample.js b/example/formatChangeExample.js
index 2221287..b51f44d 100644
--- a/example/formatChangeExample.js
+++ b/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')
 );
diff --git a/tests/datetime.spec.js b/tests/datetime.spec.js
index 202eba7..d06e349 100644
--- a/tests/datetime.spec.js
+++ b/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 });

--
Gitblit v1.9.3