diff options
author | Youmin Ha <youmin.ha@samsung.com> | 2012-08-23 16:13:20 +0900 |
---|---|---|
committer | Youmin Ha <youmin.ha@samsung.com> | 2012-08-23 16:13:20 +0900 |
commit | f476ccb6d18ed0c7392ad5508a4c7108c1297f2a (patch) | |
tree | bbdda31334a8da5bef6e1869a375075e1b8447a8 /tests/unit-tests/datetimepicker | |
parent | 1ebd5ca39c5801e5c53b0d339223713e898d0b10 (diff) | |
download | web-ui-fw-f476ccb6d18ed0c7392ad5508a4c7108c1297f2a.tar.gz web-ui-fw-f476ccb6d18ed0c7392ad5508a4c7108c1297f2a.tar.bz2 web-ui-fw-f476ccb6d18ed0c7392ad5508a4c7108c1297f2a.zip |
2.0_beta sync to rsa
Diffstat (limited to 'tests/unit-tests/datetimepicker')
-rw-r--r-- | tests/unit-tests/datetimepicker/datetimepicker-tests.js | 147 | ||||
-rw-r--r-- | tests/unit-tests/datetimepicker/index.html | 74 |
2 files changed, 221 insertions, 0 deletions
diff --git a/tests/unit-tests/datetimepicker/datetimepicker-tests.js b/tests/unit-tests/datetimepicker/datetimepicker-tests.js new file mode 100644 index 00000000..c35e064e --- /dev/null +++ b/tests/unit-tests/datetimepicker/datetimepicker-tests.js @@ -0,0 +1,147 @@ +$(document).ready( function () { + + module( "Date Time Picker"); + + var datetime = $("#datetime")[0]; + var date = $("#date")[0]; + var time = $("#time")[0]; + var custom = $("#custom")[0]; + + // trigger pagecreate + $( "#page-1" ).page(); + + var objDatetime = $(datetime).data( "datetimepicker" ); + var objDate = $(date).data( "datetimepicker" ); + var objTime = $(time).data( "datetimepicker" ); + var objCustom = $(custom).data( "datetimepicker" ); + + asyncTest( "Auto-initialization", function () { + ok( objDatetime, "should Date/Time instace created" ); + ok( objDate, "should Date instance created" ); + ok( objTime, "should Time instance created" ); + ok( objCustom, "should Custom format instance created" ); + + start(); + }); + + asyncTest( "Options", function () { + equal( objDatetime.options.type, "datetime", "should 'datetime' type created." ); + equal( objDate.options.type, "date", "should 'date' type created." ); + equal( objTime.options.type, "time", "should 'time' type created." ); + equal( objCustom.options.type, "datetime", "should custom format created as 'datetime' type." ); + equal( objCustom.options.format, "MMM dd yyyy hh:mm tt", "should accept custom format string." ); + equal( objCustom.options.date.toString(), new Date("Jun 30 00:00:00 UTC+0000 2012").toString(), "should accept preset date." ); + + start(); + }); + + asyncTest( "Private Methods", function () { + ok( ( function () { + var year = 0, + expect = false, + actual = false; + + try { + for ( year = 1; year < 2100; year++ ) { + expect = new Date( year, 1, 29 ).getDate() == 29; + actual = objDatetime._isLeapYear( year ); + if ( expect != actual ) { + throw "" + year + " is wrong"; + } + }; + } catch ( exception ) { + console.log( exception ); + return false; + } + return true; + }()), "should be able to check leap year" ); + + var updateFieldTest = function ( format, value, expect ) { + var target = $('<div data-pat=' + format + '></div>'); + objTime._updateField( target, value ); + return target.text(); + }; + + deepEqual( [ + updateFieldTest( "h", 0 ), + updateFieldTest( "hh", 1 ), + updateFieldTest( "H", 13 ), + updateFieldTest( "HH", 9 ), + updateFieldTest( "m", 9 ), + updateFieldTest( "mm", 9 ), + updateFieldTest( "MMM", 3 ), + updateFieldTest( "MMMM", 3 ), + updateFieldTest( "yy", 1995 ), + updateFieldTest( "yyyy", 1995 ) + ], + [ + "12", "01", "13", "09", "9", "09", Globalize.culture().calendar.months.namesAbbr[2], Globalize.culture().calendar.months.names[2], "95", "1995" + ], "should update field to given value with format" ); + + ok( ( function () { + var beforeNoon = objTime.options.date.getHours() < 12; + objTime._switchAmPm(); + return beforeNoon != objTime.options.date.getHours() < 12; + }()), "should change AM/PM by AMPM button" ); + + deepEqual( [ "MMMM", " ", "dd", " ", "yyyy", " ", "hh", ":", "mm", " ", "dummy space" ], + objTime._parsePattern( "MMMM dd yyyy hh:mm 'dummy space'" ), "should parse DTF string as array" ); + + objDatetime.options.date = new Date( "May 2 18:30:00 2012" ); + + var months = Globalize.culture().calendar.months.namesAbbr.slice(); + if ( months.length > 12 ) { + months.length = 12; + } + + deepEqual( [ + { // hour h 6 + values : [ "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" ], + data : [ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12 ], + numItems : 12, + current : 5 + }, + { // hour H 6 + values : range( 0, 23 ), + data : range( 0, 23 ), + numItems : 24, + current : 18 + }, + { + values : months, + data : range( 1, 12 ), + numItems : 12, + current : 4 + } + ], + [ + objDatetime._populateDataSelector( "hour", "hh", objDatetime ), + objDatetime._populateDataSelector( "hour", "H", objDatetime ), + objDatetime._populateDataSelector( "month", "MMM", objDatetime ) + ], "should populate data selector by given field and pattern" ); + + start(); + }); + + asyncTest( "Public Methods", function () { + objDatetime.value.call( objDatetime, "Jan 1 09:00:00 2012" ); + equal( "2012-01-01T09:00:00", objDatetime.value(), "should set and get value by API" ); + var format = "yyyy MM dd hh mm"; + objDatetime._setFormat( format ); + equal( objDatetime.option("format"), format, "should set type and format" ); + start(); + }); + + asyncTest( "Events", function () { + var str = "May 2 18:00:00 2012"; + + $(datetime).bind("date-changed", function(e, date) { + equal( date, "2012-05-02T18:00:00", "Should invoke event when date changed" ); + start(); + }); + + objDatetime.value( str ); + }); + + +}); diff --git a/tests/unit-tests/datetimepicker/index.html b/tests/unit-tests/datetimepicker/index.html new file mode 100644 index 00000000..41f75ffc --- /dev/null +++ b/tests/unit-tests/datetimepicker/index.html @@ -0,0 +1,74 @@ +<!DOCTYPE html> +<html> +<head> + <script src="../../../build/tizen-web-ui-fw/latest/js/jquery.js"></script> + <script src="../../../build/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script> + <script src="../../../build/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js" + data-framework-theme="tizen-white" + data-framework-viewport-scale=false> + </script> + + <link rel="stylesheet" href="../../../libs/js/jquery-mobile-1.1.0/external/qunit.css" /> + + <script src="../../../libs/js/jquery-mobile-1.1.0/tests/jquery.testHelper.js"></script> + <script src="../../../libs/js/jquery-mobile-1.1.0/external/qunit.js"></script> + <script src="datetimepicker-tests.js"></script> + + <title>Date Time Picker</title> +</head> + +<body> + +<h1 id="qunit-header">Date Time Picker</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> + +<div id="qunit-fixture"> + <div data-role="page" id="dummy-page"> + <div data-role="header" data-position="fixed"> + <h1>Dummy</h1> + </div> + <div data-role="contents"> + </div> + </div> + <div data-role="page" id="page-1"> + <div data-role="header" data-position="fixed"> + <h1>Date Time Picker</h1> + </div> + <div data-role="content"> + <ul data-role="listview"> + <li class="ui-li-2line-sub-main"> + <span class="ui-li-text-main"> + <input type="datetime" id="datetime" /> + </span> + <span class="ui-li-text-sub">DateTimePicker</span> + </li> + <li class="ui-li-2line-sub-main"> + <span class="ui-li-text-main"> + <input type="date" id="date"/> + </span> + <span class="ui-li-text-sub">DatePicker</span> + </li> + <li class="ui-li-2line-sub-main"> + <span class="ui-li-text-main"> + <input type="time" id="time"/> + </span> + <span class="ui-li-text-sub">TimePicker</span> + </li> + <li class="ui-li-2line-sub-main"> + <span class="ui-li-text-main"> + <input type="datetime" id="custom" data-format="MMM dd yyyy hh:mm tt" value="2012-06-30T00:00:00+00:00" /> + </span> + <span class="ui-li-text-sub">DateTimePicker</span> + </li> + </ul> + </div> + </div> + +</div> + +</body> +</html> + |