1 | /*
|
---|
2 | * datepicker_methods.js
|
---|
3 | */
|
---|
4 | (function($) {
|
---|
5 |
|
---|
6 | module("datepicker: methods", {
|
---|
7 | teardown: function() {
|
---|
8 | stop();
|
---|
9 | setTimeout(start, 13);
|
---|
10 | }
|
---|
11 | });
|
---|
12 |
|
---|
13 | test('destroy', function() {
|
---|
14 | var inp = init('#inp');
|
---|
15 | ok(inp.is('.hasDatepicker'), 'Default - marker class set');
|
---|
16 | ok($.data(inp[0], PROP_NAME), 'Default - instance present');
|
---|
17 | ok(inp.next().is('#alt'), 'Default - button absent');
|
---|
18 | inp.datepicker('destroy');
|
---|
19 | inp = $('#inp');
|
---|
20 | ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared');
|
---|
21 | ok(!$.data(inp[0], PROP_NAME), 'Default - instance absent');
|
---|
22 | ok(inp.next().is('#alt'), 'Default - button absent');
|
---|
23 | // With button
|
---|
24 | inp= init('#inp', {showOn: 'both'});
|
---|
25 | ok(inp.is('.hasDatepicker'), 'Button - marker class set');
|
---|
26 | ok($.data(inp[0], PROP_NAME), 'Button - instance present');
|
---|
27 | ok(inp.next().text() == '...', 'Button - button added');
|
---|
28 | inp.datepicker('destroy');
|
---|
29 | inp = $('#inp');
|
---|
30 | ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared');
|
---|
31 | ok(!$.data(inp[0], PROP_NAME), 'Button - instance absent');
|
---|
32 | ok(inp.next().is('#alt'), 'Button - button removed');
|
---|
33 | // With append text
|
---|
34 | inp = init('#inp', {appendText: 'Testing'});
|
---|
35 | ok(inp.is('.hasDatepicker'), 'Append - marker class set');
|
---|
36 | ok($.data(inp[0], PROP_NAME), 'Append - instance present');
|
---|
37 | ok(inp.next().text() == 'Testing', 'Append - append text added');
|
---|
38 | inp.datepicker('destroy');
|
---|
39 | inp = $('#inp');
|
---|
40 | ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared');
|
---|
41 | ok(!$.data(inp[0], PROP_NAME), 'Append - instance absent');
|
---|
42 | ok(inp.next().is('#alt'), 'Append - append text removed');
|
---|
43 | // With both
|
---|
44 | inp= init('#inp', {showOn: 'both', buttonImageOnly: true,
|
---|
45 | buttonImage: 'img/calendar.gif', appendText: 'Testing'});
|
---|
46 | ok(inp.is('.hasDatepicker'), 'Both - marker class set');
|
---|
47 | ok($.data(inp[0], PROP_NAME), 'Both - instance present');
|
---|
48 | ok(inp.next()[0].nodeName.toLowerCase() == 'img', 'Both - button added');
|
---|
49 | ok(inp.next().next().text() == 'Testing', 'Both - append text added');
|
---|
50 | inp.datepicker('destroy');
|
---|
51 | inp = $('#inp');
|
---|
52 | ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared');
|
---|
53 | ok(!$.data(inp[0], PROP_NAME), 'Both - instance absent');
|
---|
54 | ok(inp.next().is('#alt'), 'Both - button and append text absent');
|
---|
55 | // Inline
|
---|
56 | var inl = init('#inl');
|
---|
57 | ok(inl.is('.hasDatepicker'), 'Inline - marker class set');
|
---|
58 | ok(inl.html() != '', 'Inline - datepicker present');
|
---|
59 | ok($.data(inl[0], PROP_NAME), 'Inline - instance present');
|
---|
60 | ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent');
|
---|
61 | inl.datepicker('destroy');
|
---|
62 | inl = $('#inl');
|
---|
63 | ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared');
|
---|
64 | ok(inl.html() == '', 'Inline - datepicker absent');
|
---|
65 | ok(!$.data(inl[0], PROP_NAME), 'Inline - instance absent');
|
---|
66 | ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent');
|
---|
67 | });
|
---|
68 |
|
---|
69 | test('enableDisable', function() {
|
---|
70 | var inp = init('#inp');
|
---|
71 | ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled');
|
---|
72 | ok(!inp[0].disabled, 'Enable/disable - field initially enabled');
|
---|
73 | inp.datepicker('disable');
|
---|
74 | ok(inp.datepicker('isDisabled'), 'Enable/disable - now marked as disabled');
|
---|
75 | ok(inp[0].disabled, 'Enable/disable - field now disabled');
|
---|
76 | inp.datepicker('enable');
|
---|
77 | ok(!inp.datepicker('isDisabled'), 'Enable/disable - now marked as enabled');
|
---|
78 | ok(!inp[0].disabled, 'Enable/disable - field now enabled');
|
---|
79 | inp.datepicker('destroy');
|
---|
80 | // With a button
|
---|
81 | inp = init('#inp', {showOn: 'button'});
|
---|
82 | ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled');
|
---|
83 | ok(!inp[0].disabled, 'Enable/disable button - field initially enabled');
|
---|
84 | ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled');
|
---|
85 | inp.datepicker('disable');
|
---|
86 | ok(inp.datepicker('isDisabled'), 'Enable/disable button - now marked as disabled');
|
---|
87 | ok(inp[0].disabled, 'Enable/disable button - field now disabled');
|
---|
88 | ok(inp.next('button')[0].disabled, 'Enable/disable button - button now disabled');
|
---|
89 | inp.datepicker('enable');
|
---|
90 | ok(!inp.datepicker('isDisabled'), 'Enable/disable button - now marked as enabled');
|
---|
91 | ok(!inp[0].disabled, 'Enable/disable button - field now enabled');
|
---|
92 | ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled');
|
---|
93 | inp.datepicker('destroy');
|
---|
94 | // With an image button
|
---|
95 | inp = init('#inp', {showOn: 'button', buttonImageOnly: true,
|
---|
96 | buttonImage: 'img/calendar.gif'});
|
---|
97 | ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled');
|
---|
98 | ok(!inp[0].disabled, 'Enable/disable image - field initially enabled');
|
---|
99 | ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image initially enabled');
|
---|
100 | inp.datepicker('disable');
|
---|
101 | ok(inp.datepicker('isDisabled'), 'Enable/disable image - now marked as disabled');
|
---|
102 | ok(inp[0].disabled, 'Enable/disable image - field now disabled');
|
---|
103 | ok(inp.next('img').css('opacity') != 1, 'Enable/disable image - image now disabled');
|
---|
104 | inp.datepicker('enable');
|
---|
105 | ok(!inp.datepicker('isDisabled'), 'Enable/disable image - now marked as enabled');
|
---|
106 | ok(!inp[0].disabled, 'Enable/disable image - field now enabled');
|
---|
107 | ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image now enabled');
|
---|
108 | inp.datepicker('destroy');
|
---|
109 | // Inline
|
---|
110 | var inl = init('#inl');
|
---|
111 | var dp = $('.ui-datepicker-inline', inl);
|
---|
112 | ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled');
|
---|
113 | ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially');
|
---|
114 | inl.datepicker('disable');
|
---|
115 | ok(inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as disabled');
|
---|
116 | ok(dp.children().is('.ui-state-disabled'), 'Enable/disable inline - visually disabled');
|
---|
117 | inl.datepicker('enable');
|
---|
118 | ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as enabled');
|
---|
119 | ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visiually disabled');
|
---|
120 | inl.datepicker('destroy');
|
---|
121 | });
|
---|
122 |
|
---|
123 | })(jQuery);
|
---|