You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/06/19 17:28:41 UTC
[2/2] git commit: Add JS tests for Bean Validation example
Add JS tests for Bean Validation example
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/91ecda6c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/91ecda6c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/91ecda6c
Branch: refs/heads/master
Commit: 91ecda6cefccb6ba7cfe15fcd9b2350e52c37323
Parents: fdb31e9
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Jun 19 17:28:18 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Jun 19 17:28:18 2013 +0200
----------------------------------------------------------------------
.../src/main/webapp/js-test/all.html | 5 ++
.../js-test/tests/bean-validation/birthdate.js | 75 ++++++++++++++++++
.../js-test/tests/bean-validation/email.js | 73 +++++++++++++++++
.../js-test/tests/bean-validation/name.js | 82 ++++++++++++++++++++
.../js-test/tests/bean-validation/phone.js | 62 +++++++++++++++
5 files changed, 297 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/91ecda6c/wicket-examples/src/main/webapp/js-test/all.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/all.html b/wicket-examples/src/main/webapp/js-test/all.html
index 5a13582..694723f 100644
--- a/wicket-examples/src/main/webapp/js-test/all.html
+++ b/wicket-examples/src/main/webapp/js-test/all.html
@@ -24,6 +24,11 @@
<script type="text/javascript" src="tests/ajax/form.js"></script>
<script type="text/javascript" src="tests/cdi/injection.js"></script>
<script type="text/javascript" src="tests/cdi/conversation.js"></script>
+
+ <script type="text/javascript" src="tests/bean-validation/name.js"></script>
+ <script type="text/javascript" src="tests/bean-validation/email.js"></script>
+ <script type="text/javascript" src="tests/bean-validation/phone.js"></script>
+ <script type="text/javascript" src="tests/bean-validation/birthdate.js"></script>
</head>
<body>
http://git-wip-us.apache.org/repos/asf/wicket/blob/91ecda6c/wicket-examples/src/main/webapp/js-test/tests/bean-validation/birthdate.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/bean-validation/birthdate.js b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/birthdate.js
new file mode 100644
index 0000000..c442aa6
--- /dev/null
+++ b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/birthdate.js
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+$q(document).ready(function() {
+ "use strict";
+
+ var selectors = {
+
+ birthdateInput: "input[name=birthdate]",
+ birthdateInvalidDateErrorFeedback: "li.feedbackPanelERROR > span:contains(\"The value of 'Birthdate' is not a valid Date.\")",
+ birthdateNotInPastErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Birthdate' must be in the past\")"
+
+ };
+
+ var submit = function($) {
+ return gym.click($('input[value=Submit]'));
+ };
+
+ module('Bean validation');
+
+ asyncTest('birthdate', function () {
+ expect(6);
+
+ gym.load('/bean-validation')
+ .then(function($) {
+
+ // enter non-date birthdate
+ var $input = $(selectors.birthdateInput);
+ $input.val('abc');
+
+ equal($(selectors.birthdateInvalidDateErrorFeedback).length, 0, 'The feedback message for invalid birthdate is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.birthdateInvalidDateErrorFeedback).length, 1, 'The feedback message for invalid birthdate is there');
+
+ // enter birthdate in the future
+ var $input = $(selectors.birthdateInput);
+ $input.val('3/22/2345');
+
+ equal($(selectors.birthdateNotInPastErrorFeedback).length, 0, 'The feedback message for birthdate in the future is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.birthdateNotInPastErrorFeedback).length, 1, 'The feedback message for birthdate in the future is there');
+
+ // enter birthdate in the past
+ var $input = $(selectors.birthdateInput);
+ $input.val('3/22/2012');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.birthdateInvalidDateErrorFeedback).length, 0, 'The feedback message for invalid birthdate is NOT there');
+ equal($(selectors.birthdateNotInPastErrorFeedback).length, 0, 'The feedback message for birthdate in the future is NOT there');
+
+ }).always(start);
+ });
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/91ecda6c/wicket-examples/src/main/webapp/js-test/tests/bean-validation/email.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/bean-validation/email.js b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/email.js
new file mode 100644
index 0000000..5f588e5
--- /dev/null
+++ b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/email.js
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+$q(document).ready(function() {
+ "use strict";
+
+ var selectors = {
+
+ emailInput: "input[name=email]",
+ emailNullErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Email' is required\")",
+ emailInvalidErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Email' is not a well-formed email address\")"
+
+ };
+
+ var submit = function($) {
+ return gym.click($('input[value=Submit]'));
+ };
+
+ module('Bean validation');
+
+ asyncTest('email', function () {
+ expect(5);
+
+ gym.load('/bean-validation')
+ .then(function($) {
+
+ // enter email without characters (@NotNull)
+ var $input = $(selectors.emailInput);
+ $input.val('');
+
+ equal($(selectors.emailNullErrorFeedback).length, 0, 'The feedback message for null email is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.emailNullErrorFeedback).length, 1, 'The feedback message for null name is there');
+
+ // enter invalid email
+ var $input = $(selectors.emailInput);
+ $input.val('abc');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.emailInvalidErrorFeedback).length, 1, 'The feedback message for invalid email is there');
+
+ // enter valid email
+ var $input = $(selectors.emailInput);
+ $input.val('abc@example.com');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.emailNullErrorFeedback).length, 0, 'The feedback message for null email is NOT there');
+ equal($(selectors.emailInvalidErrorFeedback).length, 0, 'The feedback message for invalid email is NOT there');
+ }).always(start);
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/wicket/blob/91ecda6c/wicket-examples/src/main/webapp/js-test/tests/bean-validation/name.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/bean-validation/name.js b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/name.js
new file mode 100644
index 0000000..dd634ac
--- /dev/null
+++ b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/name.js
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+$q(document).ready(function() {
+ "use strict";
+
+ var selectors = {
+ nameInput: "input[name=name]",
+ nameNullErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Name' is required\")",
+ nameRangeErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Name' length must be between 2 and 30\")"
+
+ };
+
+ var submit = function($) {
+ return gym.click($('input[value=Submit]'));
+ };
+
+ module('Bean validation');
+
+ asyncTest('name', function () {
+ expect(6);
+
+ gym.load('/bean-validation')
+ .then(function($) {
+
+ // enter name without value (@NonNull)
+ var $input = $(selectors.nameInput);
+ $input.val('');
+
+ equal($(selectors.nameNullErrorFeedback).length, 0, 'The feedback message for null name is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.nameNullErrorFeedback).length, 1, 'The feedback message for null name is there');
+
+ // enter name with not enough characters (less than 2)
+ var $input = $(selectors.nameInput);
+ $input.val('a');
+
+ equal($(selectors.nameRangeErrorFeedback).length, 0, 'The feedback message for invalid name is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.nameRangeErrorFeedback).length, 1, 'The feedback message for invalid name is there');
+
+ // enter name with enough characters (more than 2, less than 30)
+ var $input = $(selectors.nameInput);
+ $input.val('abc');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.nameRangeErrorFeedback).length, 0, 'The feedback message for invalid name is NOT there');
+
+ // enter name with more than 30 characters
+ var $input = $(selectors.nameInput);
+ $input.val('abcdefghijklmnopqrstuvwxyzABCDE');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.nameRangeErrorFeedback).length, 1, 'The feedback message for invalid name is NOT there');
+ }).always(start);
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/wicket/blob/91ecda6c/wicket-examples/src/main/webapp/js-test/tests/bean-validation/phone.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/bean-validation/phone.js b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/phone.js
new file mode 100644
index 0000000..840c141
--- /dev/null
+++ b/wicket-examples/src/main/webapp/js-test/tests/bean-validation/phone.js
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+$q(document).ready(function() {
+ "use strict";
+
+ var selectors = {
+
+ phoneInput: "input[name=phone]",
+ phoneInvalidErrorFeedback: "li.feedbackPanelERROR > span:contains(\"'Phone' must match \"[0-9]{3}-[0-9]{4}\"\")"
+ };
+
+ var submit = function($) {
+ return gym.click($('input[value=Submit]'));
+ };
+
+ module('Bean validation');
+
+ asyncTest('phone', function () {
+ expect(3);
+
+ gym.load('/bean-validation')
+ .then(function($) {
+
+ // enter phone with invalid pattern
+ var $input = $(selectors.phoneInput);
+ $input.val('abc');
+
+ equal($(selectors.phoneInvalidErrorFeedback).length, 0, 'The feedback message for invalid phone is NOT there');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.phoneInvalidErrorFeedback).length, 1, 'The feedback message for invalid phone is there');
+
+ // enter valid phone
+ var $input = $(selectors.phoneInput);
+ $input.val('123-1234');
+
+ return submit($);
+ }).then(function($) {
+
+ equal($(selectors.phoneInvalidErrorFeedback).length, 0, 'The feedback message for invalid phone is NOT there');
+
+ }).always(start);
+ });
+
+});