aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/datepicker/datepicker_methods.js
blob: b969c00f49351599e7c54e920c3571baa14fa6e0 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(function( $ ) {

module( "datepicker: methods" );

test( "destroy", function() {
	expect( 3 );

	var input = $( "#datepicker" );
	domEqual( input, function() {
		input.datepicker();
		ok( input.attr( "aria-owns" ), "aria-owns attribute added" );
		ok( input.attr( "aria-haspopup" ), "aria-haspopup attribute added" );
		input.datepicker( "destroy" );
	});
});

test( "enable / disable", function() {
	expect( 10 );

	var input = TestHelpers.datepicker.init( "#datepicker" ),
		calendar = input.datepicker( "widget" );

	input.datepicker( "disable" );
	ok( input.datepicker( "option", "disabled" ), "disabled option is set" );
	ok( calendar.hasClass( "ui-datepicker-disabled" ), "has disabled widget class name" );
	ok( input.hasClass( "ui-state-disabled" ), "has disabled state class name" );
	equal( input.attr( "aria-disabled" ), "true", "has ARIA disabled" );
	equal( input.attr( "disabled" ), "disabled", "input disabled" );

	input.datepicker( "enable" );
	ok( !input.datepicker( "option", "disabled" ), "enabled after enable() call" );
	ok( !calendar.hasClass( "ui-datepicker-disabled" ), "no longer has disabled widget class name" );
	ok( !input.hasClass( "ui-state-disabled" ), "no longer has disabled state class name" );
	equal( input.attr( "aria-disabled" ), "false", "no longer has ARIA disabled" );
	equal( input.attr( "disabled" ), undefined, "input no longer disabled" );
});

test( "widget", function() {
	expect( 1 );

	var actual = $( "#datepicker" ).datepicker().datepicker( "widget" );
	deepEqual( $( "body > .ui-front" )[ 0 ],  actual[ 0 ] );
	actual.remove();
});

test( "open / close", function() {
	expect( 7 );

	var input = TestHelpers.datepicker.initNewInput({ show: false, hide: false }),
		calendar = input.datepicker( "widget" );

	ok( calendar.is( ":hidden" ), "calendar hidden on init" );

	input.datepicker( "open" );
	ok( calendar.is( ":visible" ), "open: calendar visible" );
	equal( calendar.attr( "aria-hidden" ), "false", "open: calendar aria-hidden" );
	equal( calendar.attr( "aria-expanded" ), "true", "close: calendar aria-expanded" );

	input.datepicker( "close" );
	ok( !calendar.is( ":visible" ), "close: calendar hidden" );
	equal( calendar.attr( "aria-hidden" ), "true", "close: calendar aria-hidden" );
	equal( calendar.attr( "aria-expanded" ), "false", "close: calendar aria-expanded" );
});

test( "value", function() {
	expect( 4 );

	var input = $( "#datepicker" ).datepicker(),
		picker = input.datepicker( "widget" );

	input.datepicker( "value", "1/1/14" );
	equal( input.val(), "1/1/14", "input's value set" );

	input.datepicker( "open" );
	ok(
		picker.find( "button[data-timestamp]" ).eq( 0 ).hasClass( "ui-state-active" ),
		"first day marked as selected"
	);
	equal( input.datepicker( "value" ), "1/1/14", "getter" );

	input.val( "abc" );
	strictEqual( input.datepicker( "value" ), null, "Invalid values should return null." );
});

test( "valueAsDate", function() {
	expect( 6 );

	var input = TestHelpers.datepicker.init( "#datepicker" ),
		picker = input.datepicker( "widget" ),
		date1 = new Date( 2008, 6 - 1, 4 );

	input.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) );
	equal( input.val(), "1/1/14", "Input's value set" );
	ok(
		picker.find( "button[data-timestamp]" ).eq( 0 ).hasClass( "ui-state-active" ),
		"First day marked as selected"
	);
	TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );

	input.val( "a/b/c" );
	equal( input.datepicker( "valueAsDate" ), null, "Invalid dates return null" );

	input.val( "" ).datepicker( "destroy" );
	input = TestHelpers.datepicker.init( "#datepicker" );

	strictEqual( input.datepicker( "valueAsDate" ), null, "Set date - default" );
	input.datepicker( "valueAsDate", date1 );
	TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date - 2008-06-04" );
});

test( "isValid", function() {
	expect( 2 );
	var input = $( "#datepicker" ).datepicker();

	input.val( "1/1/14" );
	ok( input.datepicker( "isValid" ) );

	input.val( "1/1/abc" );
	ok( !input.datepicker( "isValid" ) );

	input.datepicker( "destroy" );
});

})( jQuery );