summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/tests/ValidationTests.html
blob: 67c9aecb7e1d3cef7216da44589be8df5e89d2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title>Prado Client-Side Validation Tests</title>
    <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
    <script language="JavaScript" type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
<!-- unit tests -->
<!-- base files -->
<script language="JavaScript" Type="text/javascript" src="../../base.js"></script>
<script language="JavaScript" Type="text/javascript" src="../../dom.js"></script>
<!-- library file -->
<script language="JavaScript" Type="text/javascript" src="../library/validation/validator.js"></script>
<script language="JavaScript" type="text/javascript">

	function testConvertInteger()
	{
		var convert = Prado.Validation.Util;

		//test integers
		assertEquals("Integer 10", 10, convert.toInteger("10"));
		assertNull("Not an integer", convert.toInteger("10.0"));
		assertEquals("+ integer", 10, convert.toInteger(" +10 "));
	}

	function testConvertDouble()
	{
		var convert = Prado.Validation.Util;

		//test doubles
		assertEquals("Double 10.0", 10.0, convert.toDouble("10.0","."));
		assertNull("Not a double", convert.toDouble("10.0s"));
		assertEquals("+ double", 10.2, convert.toDouble(" +10.2 "));
	}

	function testConvertAsCurrency()
	{
		var convert = Prado.Validation.Util;

		//test currency convert
		assertEquals("10 Dollars", 10, convert.toCurrency("10.00"));
		assertEquals("10,000 Dollars", 10000.10, convert.toCurrency("10,000.10"));

		//using space as grouping
		assertEquals("10 000 Dollars", 10000.10, convert.toCurrency("10 000.10", " "));
		
		assertEquals("1 0000 Yen", 10000, convert.toCurrency("1 0000", " ",0));

		assertNull("Not 10 Dollars", convert.toCurrency("$10.0"));
	}

	function testConvertToDate() 
	{
		var convert = Prado.Validation.Util;

		//test dates !! Months are zero based for javascript Date objects !!
		var testDate = (new Date(2005, 05, 20)).valueOf();
		assertEquals("Matching date 2005 May 20", testDate, convert.toDate("2005-06-20", "%Y-%m-%d"));
	}

	function testValidatorConversion()
	{
		var validator = new Prado.Validation(null, {id : "", controltovalidate : "", groupchar: " ", digits : 0});
		assertEquals("Integer 10", 10, validator.convert("Integer", "10"));
		assertEquals("10 000 Yen", 10000, validator.convert("Currency", "10 000"));
	}
</script>
  </head>

  <body>
    <h1>Prado Client-Side Validation Tests</h1>

    <p>This page contains tests for the utility functions
    that JsUnit uses. To see them, take a look at the source.</p>
  </body>
</html>