source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/tests/unit/dialog/dialog_core.js@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/*
2 * dialog_core.js
3 */
4
5var el,
6 offsetBefore, offsetAfter,
7 heightBefore, heightAfter,
8 widthBefore, widthAfter,
9 dragged;
10
11function dlg() {
12 return el.data("dialog").element.parents(".ui-dialog:first");
13}
14
15function isOpen(why) {
16 ok(dlg().is(":visible"), why);
17}
18
19function isNotOpen(why) {
20 ok(!dlg().is(":visible"), why);
21}
22
23function drag(handle, dx, dy) {
24 var d = dlg();
25 offsetBefore = d.offset();
26 heightBefore = d.height();
27 widthBefore = d.width();
28 //this mouseover is to work around a limitation in resizable
29 //TODO: fix resizable so handle doesn't require mouseover in order to be used
30 $(handle, d).simulate("mouseover");
31 $(handle, d).simulate("drag", {
32 dx: dx || 0,
33 dy: dy || 0
34 });
35 dragged = { dx: dx, dy: dy };
36 offsetAfter = d.offset();
37 heightAfter = d.height();
38 widthAfter = d.width();
39}
40
41function moved(dx, dy, msg) {
42 msg = msg ? msg + "." : "";
43 var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) };
44 var expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) };
45 same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
46}
47
48function shouldmove(why) {
49 var handle = $(".ui-dialog-titlebar", dlg());
50 drag(handle, 50, -50);
51 moved(50, -50, why);
52}
53
54function shouldnotmove(why) {
55 var handle = $(".ui-dialog-titlebar", dlg());
56 drag(handle, 50, -50);
57 moved(0, 0, why);
58}
59
60function resized(dw, dh, msg) {
61 msg = msg ? msg + "." : "";
62 var actual = { width: widthAfter, height: heightAfter };
63 var expected = { width: widthBefore + dw, height: heightBefore + dh };
64 same(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
65}
66
67function shouldresize(why) {
68 var handle = $(".ui-resizable-se", dlg());
69 drag(handle, 50, 50);
70 resized(50, 50, why);
71}
72
73function shouldnotresize(why) {
74 var handle = $(".ui-resizable-se", dlg());
75 drag(handle, 50, 50);
76 resized(0, 0, why);
77}
78
79function broder(el, side){
80 return parseInt(el.css('border-' + side + '-width'), 10);
81}
82
83function margin(el, side) {
84 return parseInt(el.css('margin-' + side), 10);
85}
86
87(function($) {
88
89module("dialog: core");
90
91test("element types", function() {
92 var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
93 + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
94 + ',acronym,code,samp,kbd,var,img,object,hr'
95 + ',input,button,label,select,iframe').split(',');
96
97 $.each(typeNames, function(i) {
98 var typeName = typeNames[i];
99 el = $(document.createElement(typeName)).appendTo('body');
100 (typeName == 'table' && el.append("<tr><td>content</td></tr>"));
101 el.dialog();
102 ok(true, '$("&lt;' + typeName + '/&gt").dialog()');
103 el.dialog("destroy");
104 el.remove();
105 });
106});
107
108test("title id", function() {
109 expect(3);
110
111 var titleId;
112
113 // reset the uuid so we know what values to expect
114 $.ui.dialog.uuid = 0;
115
116 el = $('<div></div>').dialog();
117 titleId = dlg().find('.ui-dialog-title').attr('id');
118 equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id');
119 el.remove();
120
121 el = $('<div></div>').dialog();
122 titleId = dlg().find('.ui-dialog-title').attr('id');
123 equals(titleId, 'ui-dialog-title-2', 'auto-numbered title id');
124 el.remove();
125
126 el = $('<div id="foo"/>').dialog();
127 titleId = dlg().find('.ui-dialog-title').attr('id');
128 equals(titleId, 'ui-dialog-title-foo', 'carried over title id');
129 el.remove();
130});
131
132test("ARIA", function() {
133 expect(4);
134
135 el = $('<div></div>').dialog();
136
137 equals(dlg().attr('role'), 'dialog', 'dialog role');
138
139 var labelledBy = dlg().attr('aria-labelledby');
140 ok(labelledBy.length > 0, 'has aria-labelledby attribute');
141 equals(dlg().find('.ui-dialog-title').attr('id'), labelledBy,
142 'proper aria-labelledby attribute');
143
144 equals(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button',
145 'close link role');
146
147 el.remove();
148});
149
150test("widget method", function() {
151 var dialog = $("<div/>").appendTo("#main").dialog();
152 same(dialog.parent()[0], dialog.dialog("widget")[0]);
153});
154
155})(jQuery);
Note: See TracBrowser for help on using the repository browser.