sproutcore 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. data/History.txt +233 -0
  2. data/Manifest.txt +67 -34
  3. data/bin/sc-build +12 -1
  4. data/bin/sc-gen +1 -1
  5. data/bin/sproutcore +14 -0
  6. data/clients/sc_docs/controllers/docs.js +38 -8
  7. data/clients/sc_docs/english.lproj/body.css +80 -127
  8. data/clients/sc_docs/english.lproj/body.rhtml +43 -23
  9. data/clients/sc_docs/english.lproj/no_docs.rhtml +2 -1
  10. data/clients/sc_docs/english.lproj/tabs.rhtml +16 -0
  11. data/clients/sc_docs/main.js +14 -9
  12. data/clients/sc_docs/models/doc.js +1 -1
  13. data/clients/sc_docs/tests/controllers/docs.rhtml +1 -2
  14. data/clients/sc_docs/tests/models/doc.rhtml +1 -2
  15. data/clients/sc_docs/tests/views/doc_frame.rhtml +1 -2
  16. data/clients/sc_docs/tests/views/doc_label_view.rhtml +1 -2
  17. data/clients/sc_docs/views/doc_frame.js +1 -1
  18. data/clients/sc_test_runner/controllers/runner.js +31 -8
  19. data/clients/sc_test_runner/english.lproj/body.css +62 -122
  20. data/clients/sc_test_runner/english.lproj/body.rhtml +62 -26
  21. data/clients/sc_test_runner/main.js +1 -6
  22. data/clients/sc_test_runner/models/test.js +14 -1
  23. data/clients/sc_test_runner/views/runner_frame.js +4 -2
  24. data/clients/view_builder/builders/builder.js +339 -0
  25. data/clients/view_builder/builders/button.js +81 -0
  26. data/clients/view_builder/controllers/document.js +21 -0
  27. data/clients/view_builder/core.js +19 -0
  28. data/clients/view_builder/english.lproj/body.css +77 -0
  29. data/clients/view_builder/english.lproj/body.rhtml +41 -0
  30. data/clients/{sc_docs → view_builder}/english.lproj/controls.css +0 -0
  31. data/clients/view_builder/english.lproj/strings.js +14 -0
  32. data/clients/view_builder/main.js +38 -0
  33. data/clients/view_builder/tests/controllers/document.rhtml +20 -0
  34. data/clients/view_builder/tests/views/builder.rhtml +20 -0
  35. data/clients/view_builder/views/builder.js +23 -0
  36. data/frameworks/prototype/prototype.js +1 -1
  37. data/frameworks/sproutcore/Core.js +32 -7
  38. data/frameworks/sproutcore/README +1 -1
  39. data/frameworks/sproutcore/animation/animation.js +411 -0
  40. data/frameworks/sproutcore/controllers/array.js +17 -9
  41. data/frameworks/sproutcore/controllers/collection.js +9 -110
  42. data/frameworks/sproutcore/controllers/controller.js +1 -1
  43. data/frameworks/sproutcore/controllers/object.js +2 -1
  44. data/frameworks/sproutcore/drag/drag.js +267 -56
  45. data/frameworks/sproutcore/drag/drag_data_source.js +24 -16
  46. data/frameworks/sproutcore/drag/drag_source.js +53 -42
  47. data/frameworks/sproutcore/drag/drop_target.js +2 -2
  48. data/frameworks/sproutcore/english.lproj/buttons.css +337 -236
  49. data/frameworks/sproutcore/english.lproj/core.css +115 -0
  50. data/frameworks/sproutcore/english.lproj/icons.css +227 -0
  51. data/{clients/sc_docs → frameworks/sproutcore}/english.lproj/images/indicator.gif +0 -0
  52. data/frameworks/sproutcore/english.lproj/images/sc-theme-sprite.png +0 -0
  53. data/frameworks/sproutcore/english.lproj/images/sc-theme-ysprite.png +0 -0
  54. data/frameworks/sproutcore/english.lproj/images/shared-icons.png +0 -0
  55. data/frameworks/sproutcore/english.lproj/menu.css +1 -1
  56. data/frameworks/sproutcore/english.lproj/strings.js +1 -1
  57. data/frameworks/sproutcore/english.lproj/theme.css +405 -31
  58. data/frameworks/sproutcore/foundation/application.js +15 -11
  59. data/frameworks/sproutcore/foundation/benchmark.js +1 -1
  60. data/frameworks/sproutcore/foundation/binding.js +2 -2
  61. data/frameworks/sproutcore/foundation/date.js +1 -1
  62. data/frameworks/sproutcore/foundation/error.js +1 -1
  63. data/frameworks/sproutcore/foundation/input_manager.js +32 -21
  64. data/frameworks/sproutcore/foundation/mock.js +1 -1
  65. data/frameworks/sproutcore/foundation/node_descriptor.js +9 -6
  66. data/frameworks/sproutcore/foundation/object.js +249 -177
  67. data/frameworks/sproutcore/foundation/page.js +5 -2
  68. data/frameworks/sproutcore/foundation/path_module.js +11 -10
  69. data/frameworks/sproutcore/foundation/responder.js +5 -2
  70. data/frameworks/sproutcore/foundation/routes.js +17 -13
  71. data/frameworks/sproutcore/foundation/run_loop.js +249 -11
  72. data/frameworks/sproutcore/foundation/server.js +1 -1
  73. data/frameworks/sproutcore/foundation/set.js +3 -3
  74. data/frameworks/sproutcore/foundation/string.js +5 -3
  75. data/frameworks/sproutcore/foundation/timer.js +371 -0
  76. data/frameworks/sproutcore/foundation/undo_manager.js +1 -1
  77. data/frameworks/sproutcore/foundation/unittest.js +3 -3
  78. data/frameworks/sproutcore/foundation/utils.js +161 -2
  79. data/frameworks/sproutcore/globals/panels.js +1 -1
  80. data/frameworks/sproutcore/globals/popups.js +4 -3
  81. data/frameworks/sproutcore/globals/window.js +44 -4
  82. data/frameworks/sproutcore/lib/button_views.rb +328 -0
  83. data/frameworks/sproutcore/lib/collection_view.rb +80 -0
  84. data/frameworks/sproutcore/lib/core_views.rb +281 -0
  85. data/frameworks/sproutcore/lib/form_views.rb +253 -0
  86. data/frameworks/sproutcore/lib/index.rhtml +2 -0
  87. data/frameworks/sproutcore/lib/menu_views.rb +88 -0
  88. data/frameworks/sproutcore/{foundation → mixins}/array.js +60 -29
  89. data/frameworks/sproutcore/mixins/control.js +265 -0
  90. data/frameworks/sproutcore/mixins/delegate_support.js +66 -0
  91. data/frameworks/sproutcore/{foundation → mixins}/observable.js +176 -6
  92. data/frameworks/sproutcore/mixins/scrollable.js +245 -0
  93. data/frameworks/sproutcore/mixins/selection_support.js +148 -0
  94. data/frameworks/sproutcore/mixins/validatable.js +152 -0
  95. data/frameworks/sproutcore/models/collection.js +5 -5
  96. data/frameworks/sproutcore/models/record.js +1 -1
  97. data/frameworks/sproutcore/models/store.js +1 -1
  98. data/frameworks/sproutcore/panes/dialog.js +1 -1
  99. data/frameworks/sproutcore/panes/manager.js +1 -1
  100. data/frameworks/sproutcore/panes/menu.js +1 -1
  101. data/frameworks/sproutcore/panes/overlay.js +2 -2
  102. data/frameworks/sproutcore/panes/panel.js +1 -1
  103. data/frameworks/sproutcore/panes/picker.js +1 -1
  104. data/frameworks/sproutcore/tests/controllers/array.rhtml +44 -4
  105. data/frameworks/sproutcore/tests/foundation/timer/invalidate.rhtml +33 -0
  106. data/frameworks/sproutcore/tests/foundation/timer/invokeLater.rhtml +145 -0
  107. data/frameworks/sproutcore/tests/foundation/timer/isPaused.rhtml +70 -0
  108. data/frameworks/sproutcore/tests/foundation/timer/schedule.rhtml +145 -0
  109. data/frameworks/sproutcore/tests/views/{scroll.rhtml → checkbox.rhtml} +3 -3
  110. data/frameworks/sproutcore/tests/views/{collection.rhtml → collection/base.rhtml} +33 -32
  111. data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +260 -0
  112. data/frameworks/sproutcore/tests/views/image_cell.rhtml +19 -0
  113. data/frameworks/sproutcore/tests/views/label_item.rhtml +2 -4
  114. data/frameworks/sproutcore/tests/views/list.rhtml +2 -3
  115. data/frameworks/sproutcore/tests/views/list_item.rhtml +20 -0
  116. data/frameworks/sproutcore/tests/views/slider.rhtml +20 -0
  117. data/frameworks/sproutcore/tests/views/text_cell.rhtml +19 -0
  118. data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +395 -0
  119. data/frameworks/sproutcore/tests/views/view/frame.rhtml +353 -0
  120. data/frameworks/sproutcore/tests/views/view/innerFrame.rhtml +347 -0
  121. data/frameworks/sproutcore/tests/views/view/isVisibleInWindow.rhtml +148 -0
  122. data/frameworks/sproutcore/tests/views/view/scrollFrame.rhtml +468 -0
  123. data/frameworks/sproutcore/validators/credit_card.js +33 -13
  124. data/frameworks/sproutcore/validators/date.js +26 -6
  125. data/frameworks/sproutcore/validators/email.js +21 -3
  126. data/frameworks/sproutcore/validators/not_empty.js +11 -1
  127. data/frameworks/sproutcore/validators/number.js +18 -4
  128. data/frameworks/sproutcore/validators/password.js +12 -1
  129. data/frameworks/sproutcore/validators/validator.js +204 -194
  130. data/frameworks/sproutcore/views/{button.js → button/button.js} +96 -94
  131. data/frameworks/sproutcore/views/button/checkbox.js +29 -0
  132. data/frameworks/sproutcore/views/button/disclosure.js +42 -0
  133. data/frameworks/sproutcore/views/button/radio.js +29 -0
  134. data/frameworks/sproutcore/views/{collection.js → collection/collection.js} +1373 -1024
  135. data/frameworks/sproutcore/views/collection/grid.js +124 -46
  136. data/frameworks/sproutcore/views/collection/image_cell.js +17 -46
  137. data/frameworks/sproutcore/views/collection/list.js +45 -35
  138. data/frameworks/sproutcore/views/collection/source_list.js +386 -0
  139. data/frameworks/sproutcore/views/collection/table.js +118 -0
  140. data/frameworks/sproutcore/views/container.js +7 -2
  141. data/frameworks/sproutcore/views/error_explanation.js +23 -10
  142. data/frameworks/sproutcore/views/{checkbox_field.js → field/checkbox_field.js} +16 -6
  143. data/frameworks/sproutcore/views/field/field.js +219 -0
  144. data/frameworks/sproutcore/views/{radio_field.js → field/radio_field.js} +27 -12
  145. data/frameworks/sproutcore/views/{select_field.js → field/select_field.js} +116 -90
  146. data/frameworks/sproutcore/views/{text_field.js → field/text_field.js} +57 -8
  147. data/frameworks/sproutcore/views/{textarea_field.js → field/textarea_field.js} +13 -3
  148. data/frameworks/sproutcore/views/filter_button.js +2 -2
  149. data/frameworks/sproutcore/views/form.js +3 -3
  150. data/frameworks/sproutcore/views/image.js +128 -21
  151. data/frameworks/sproutcore/views/inline_text_editor.js +1 -1
  152. data/frameworks/sproutcore/views/label.js +149 -92
  153. data/frameworks/sproutcore/views/list_item.js +225 -0
  154. data/frameworks/sproutcore/views/menu_item.js +10 -4
  155. data/frameworks/sproutcore/views/pagination.js +11 -4
  156. data/frameworks/sproutcore/views/popup_button.js +25 -21
  157. data/frameworks/sproutcore/views/popup_menu.js +10 -4
  158. data/frameworks/sproutcore/views/progress.js +29 -16
  159. data/frameworks/sproutcore/views/radio_group.js +1 -1
  160. data/frameworks/sproutcore/views/scroll.js +60 -20
  161. data/frameworks/sproutcore/views/segmented.js +1 -1
  162. data/frameworks/sproutcore/views/slider.js +132 -0
  163. data/frameworks/sproutcore/views/source_list_group.js +130 -0
  164. data/frameworks/sproutcore/views/spinner.js +1 -1
  165. data/frameworks/sproutcore/views/split.js +292 -0
  166. data/frameworks/sproutcore/views/split_divider.js +109 -0
  167. data/frameworks/sproutcore/views/tab.js +1 -1
  168. data/frameworks/sproutcore/views/toolbar.js +1 -1
  169. data/frameworks/sproutcore/views/view.js +1272 -591
  170. data/generators/client/templates/english.lproj/body.css +1 -1
  171. data/generators/controller/controller_generator.rb +1 -1
  172. data/generators/controller/templates/test.rhtml +2 -1
  173. data/generators/model/templates/test.rhtml +1 -1
  174. data/generators/test/templates/test.rhtml +1 -1
  175. data/generators/view/templates/test.rhtml +1 -1
  176. data/jsdoc/templates/sproutcore/class.tmpl +241 -338
  177. data/jsdoc/templates/sproutcore/default.css +105 -155
  178. data/jsdoc/templates/sproutcore/index.tmpl +43 -8
  179. data/jsdoc/templates/sproutcore/publish.js +9 -4
  180. data/lib/sproutcore/build_tools/html_builder.rb +29 -13
  181. data/lib/sproutcore/build_tools/resource_builder.rb +1 -1
  182. data/lib/sproutcore/bundle.rb +86 -25
  183. data/lib/sproutcore/jsdoc.rb +2 -0
  184. data/lib/sproutcore/version.rb +1 -1
  185. data/lib/sproutcore/view_helpers.rb +36 -3
  186. data/tasks/deployment.rake +1 -1
  187. metadata +69 -36
  188. data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
  189. data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
  190. data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
  191. data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
  192. data/clients/sc_docs/english.lproj/warning.rhtml +0 -6
  193. data/clients/sc_test_runner/english.lproj/warning.rhtml +0 -6
  194. data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
  195. data/frameworks/sproutcore/english.lproj/collections.css +0 -82
  196. data/frameworks/sproutcore/english.lproj/images/buttons-sprite.png +0 -0
  197. data/frameworks/sproutcore/views/collection/collection_item.js +0 -36
  198. data/frameworks/sproutcore/views/collection/text_cell.js +0 -128
  199. data/frameworks/sproutcore/views/field.js +0 -214
  200. data/frameworks/sproutcore/views/workspace.js +0 -170
  201. data/generators/client/templates/english.lproj/controls.css +0 -0
  202. data/generators/framework/templates/english.lproj/body.css +0 -0
  203. data/generators/framework/templates/english.lproj/body.rhtml +0 -3
  204. data/generators/framework/templates/english.lproj/controls.css +0 -0
  205. data/lib/sproutcore/view_helpers/button_views.rb +0 -302
  206. data/lib/sproutcore/view_helpers/core_views.rb +0 -292
  207. data/lib/sproutcore/view_helpers/form_views.rb +0 -258
  208. data/lib/sproutcore/view_helpers/menu_views.rb +0 -94
@@ -0,0 +1,33 @@
1
+ <% content_for('final') do %>
2
+
3
+ <script>
4
+
5
+ Test.context("Timer.invalidate", {
6
+
7
+ "invalidate immediately should never execute": function() {
8
+
9
+ var fired = NO ;
10
+
11
+ SC.runLoop.beginRunLoop() ;
12
+ var start = SC.runLoop.get('startTime') ;
13
+ var t = SC.Timer.schedule({
14
+ target: this,
15
+ action: function() { fired = YES ; },
16
+ interval: 100
17
+ });
18
+ t.invalidate() ;
19
+ SC.runLoop.endRunLoop() ;
20
+
21
+ var checks = 10 ;
22
+ wait(1500, function() {
23
+ assertEqual(NO, fired) ;
24
+ }) ;
25
+ }
26
+
27
+ // using invalidate on a repeating timer is tested in schedule().
28
+
29
+ });
30
+
31
+ </script>
32
+
33
+ <% end %>
@@ -0,0 +1,145 @@
1
+ <% content_for('final') do %>
2
+
3
+ <script>
4
+
5
+ Test.context("SC.Object.invokeLater", {
6
+
7
+ "should invoke method string after specified time": function() {
8
+ var fired = NO ;
9
+ var o = SC.Object.create({
10
+ func: function() { fired = YES; }
11
+ }) ;
12
+ o.invokeLater('func', 200) ;
13
+
14
+ var tries = 20;
15
+ var f= function() {
16
+ if (!fired && --tries >= 0) wait(100, f) ;
17
+ assertEqual(YES, fired, 'did not fire') ;
18
+ } ;
19
+ wait(300, f) ;
20
+ },
21
+
22
+ "should invoke method instance after specified time": function() {
23
+ var fired = NO ;
24
+ var o = SC.Object.create({
25
+ func: function() { fired = YES; }
26
+ }) ;
27
+ o.invokeLater(o.func, 200) ;
28
+
29
+ var tries = 20;
30
+ var f= function() {
31
+ if (!fired && --tries >= 0) wait(100, f) ;
32
+ assertEqual(YES, fired, 'did not fire') ;
33
+ } ;
34
+ wait(300, f) ;
35
+ },
36
+
37
+ "should invoke method string immediately if no time passed": function() {
38
+ var fired = NO ;
39
+ var o = SC.Object.create({
40
+ func: function() { fired = YES; }
41
+ }) ;
42
+ o.invokeLater('func') ;
43
+
44
+ var tries = 20;
45
+ var f= function() {
46
+ if (!fired && --tries >= 0) wait(100, f) ;
47
+ assertEqual(YES, fired, 'did not fire') ;
48
+ } ;
49
+ wait(300, f) ;
50
+ },
51
+
52
+ "should automatically bind with arguments if passed": function() {
53
+ var fired = NO ;
54
+ var g1 = null, g2 = null ;
55
+
56
+ var o = SC.Object.create({
57
+ func: function(arg1, arg2) {
58
+ g1 = arg1; g2 = arg2; fired = YES;
59
+ }
60
+ }) ;
61
+ o.invokeLater('func', 200, 'ARG1', 'ARG2') ;
62
+
63
+ var tries = 20;
64
+ var f= function() {
65
+ if (!fired && --tries >= 0) wait(100, f) ;
66
+ assertEqual(YES, fired, 'did not fire') ;
67
+ assertEqual('ARG1', g1, 'arg1');
68
+ assertEqual('ARG2', g2, 'arg2');
69
+ } ;
70
+ wait(300, f) ;
71
+ }
72
+
73
+ });
74
+
75
+ Test.context("Prototype.invokeLater", {
76
+
77
+ "should invoke function with target after specified time": function() {
78
+ var fired = NO ;
79
+ var target = null;
80
+ var o = SC.Object.create() ;
81
+ var func = function() { fired = YES; target = this; } ;
82
+ func.invokeLater(o, 200) ;
83
+
84
+ var tries = 20;
85
+ var f= function() {
86
+ if (!fired && --tries >= 0) wait(100, f) ;
87
+ assertEqual(YES, fired, 'did not fire') ;
88
+ assertEqual(o, target, 'target') ;
89
+ } ;
90
+ wait(300, f) ;
91
+ },
92
+
93
+ "should invoke object with no target after specified time": function() {
94
+ var fired = NO ;
95
+ var func = function() { fired = YES; } ;
96
+ func.invokeLater(null, 200) ;
97
+
98
+ var tries = 20;
99
+ var f= function() {
100
+ if (!fired && --tries >= 0) wait(100, f) ;
101
+ assertEqual(YES, fired, 'did not fire') ;
102
+ } ;
103
+ wait(300, f) ;
104
+ },
105
+
106
+ "should invoke function immediately if no time passed": function() {
107
+ var fired = NO ;
108
+ var o = SC.Object.create() ;
109
+ var func = function() { fired = YES; } ;
110
+ func.invokeLater(o) ;
111
+
112
+ var tries = 20;
113
+ var f= function() {
114
+ if (!fired && --tries >= 0) wait(100, f) ;
115
+ assertEqual(YES, fired, 'did not fire') ;
116
+ } ;
117
+ wait(300, f) ;
118
+ },
119
+
120
+ "should automatically bind with arguments if passed": function() {
121
+ var fired = NO ;
122
+ var g1 = null, g2 = null ;
123
+
124
+ var o = SC.Object.create() ;
125
+ var func = function(arg1, arg2) {
126
+ g1 = arg1; g2 = arg2; fired = YES;
127
+ } ;
128
+ func.invokeLater(o, 200, 'ARG1', 'ARG2') ;
129
+
130
+ var tries = 20;
131
+ var f= function() {
132
+ if (!fired && --tries >= 0) wait(100, f) ;
133
+ assertEqual(YES, fired, 'did not fire') ;
134
+ assertEqual('ARG1', g1, 'arg1');
135
+ assertEqual('ARG2', g2, 'arg2');
136
+ } ;
137
+ wait(300, f) ;
138
+ }
139
+
140
+
141
+ });
142
+
143
+ </script>
144
+
145
+ <% end %>
@@ -0,0 +1,70 @@
1
+ <% content_for('final') do %>
2
+
3
+ <script>
4
+
5
+ Test.context("Timer.isPaused", {
6
+
7
+ "setting isPaused should stop firing": function() {
8
+
9
+ var firedCount = 0 ;
10
+
11
+ SC.runLoop.beginRunLoop() ;
12
+ var start = SC.runLoop.get('startTime') ;
13
+ var t = SC.Timer.schedule({
14
+ target: this,
15
+ action: function() { firedCount++ ; },
16
+ interval: 100,
17
+ repeats: YES
18
+ });
19
+ SC.runLoop.endRunLoop() ;
20
+
21
+ // wait for timer to fire twice, then pause it.
22
+ var tries1 = 10 ;
23
+ var f1 = function() {
24
+ if(firedCount<2) {
25
+ if (--tries1 >= 0) {
26
+ wait(100, f1) ;
27
+ } else assertEqual(NO, YES, 'Timer never fired 2 times - f1') ;
28
+ } else {
29
+ assertEqual(NO, t.get('isPaused'), 'should start with isPaused = NO');
30
+ t.set('isPaused', YES) ;
31
+ firedCount = 0 ; // Reset count here.
32
+ wait(300, f2) ;
33
+ }
34
+ };
35
+
36
+ // once timer paused, make sure it did not fire again.
37
+ var f2 = function() {
38
+ assertEqual(0, firedCount, 'timer kept firing!') ;
39
+ assertEqual(YES, t.get('isPaused'), 'timer is not paused') ;
40
+ t.set('isPaused', NO) ;
41
+
42
+ wait(300, f3) ;
43
+ } ;
44
+
45
+ // once timer has verified paused, unpause and make sure it fires again.
46
+ var tries2 = 10 ;
47
+ var f3 = function() {
48
+ if (firedCount <= 2) {
49
+ if (--tries1 >= 0) {
50
+ wait(100, f3) ;
51
+ } else assertEqual(NO, YES, "Timer did not resume") ;
52
+
53
+ // timer fired, clean up.
54
+ } else {
55
+ t.invalidate() ;
56
+ assertEqual(NO, t.get('isPaused'), 'timer did not unpause') ;
57
+ }
58
+ };
59
+
60
+ wait(300, f1) ;
61
+
62
+ }
63
+
64
+ // using invalidate on a repeating timer is tested in schedule().
65
+
66
+ });
67
+
68
+ </script>
69
+
70
+ <% end %>
@@ -0,0 +1,145 @@
1
+ <% content_for('final') do %>
2
+
3
+ <script>
4
+
5
+ Test.context("Timer.schedule single timer", {
6
+
7
+ "single timer should execute once and invalidate": function() {
8
+ var fired = [] ;
9
+
10
+ SC.runLoop.beginRunLoop() ;
11
+ var start = SC.runLoop.get('startTime') ;
12
+ var t = SC.Timer.schedule({
13
+ target: this,
14
+ action: function() { fired.push(Date.now()); },
15
+ interval: 100,
16
+ repeats: NO
17
+ });
18
+ SC.runLoop.endRunLoop() ;
19
+
20
+ var checks = 10 ;
21
+ var f = function() {
22
+
23
+ if (fired.length == 0 && --checks > 0) {
24
+ wait(100, f); return ;
25
+ }
26
+
27
+ // should only fire once
28
+ assertEqual(1, fired.length, 'fired count') ;
29
+
30
+ // timer should no longer be valid
31
+ assertEqual(NO, t.get('isValid'), 'isValid');
32
+
33
+ } ;
34
+
35
+ wait(300, f);
36
+ },
37
+
38
+ "repeating timer with no limit should repeat until terminated": function() {
39
+ var fired = [] ;
40
+
41
+ // schedule repeating timer
42
+ SC.runLoop.beginRunLoop() ;
43
+ var start = SC.runLoop.get('startTime') ;
44
+ var runs = 4 ;
45
+
46
+ var t = SC.Timer.schedule({
47
+ target: this,
48
+ action: function() {
49
+ fired.push(Date.now());
50
+ if (--runs <= 0) t.invalidate();
51
+ },
52
+ interval: 100,
53
+ repeats: YES
54
+ });
55
+ SC.runLoop.endRunLoop() ;
56
+
57
+ // We can't gaurantee when timeouts will execute in the browser so we
58
+ // have to be a little flexible about testing repeated loops like this.
59
+ var checks = 10 ;
60
+ var f = function() {
61
+
62
+ if (--checks < 0) assertEqual(YES, NO, 'Check Count Exceeded') ;
63
+ if (runs > 0) {
64
+ wait(100, f) ; // wait until timer fires 4 times.
65
+ } else {
66
+ var diffs = fired.map(function(x) { return x - start; });
67
+ assertEqual(4, fired.length, 'fired count: %@'.fmt(diffs.join(', '))) ;
68
+ assertEqual(NO, t.get('isValid'), 'isValid') ;
69
+ }
70
+ };
71
+ wait(600, f);
72
+
73
+ },
74
+
75
+ "repeating timer should terminate after expiration": function() {
76
+ var fired = [] ;
77
+
78
+ // schedule repeating timer
79
+ SC.runLoop.beginRunLoop() ;
80
+ var start = SC.runLoop.get('startTime') ;
81
+ var runs = 4 ;
82
+
83
+ var t = SC.Timer.schedule({
84
+ target: this,
85
+ action: function() {
86
+ fired.push(Date.now());
87
+ },
88
+ interval: 100,
89
+ repeats: YES,
90
+ until: start + 500
91
+ });
92
+ SC.runLoop.endRunLoop() ;
93
+
94
+ // We can't gaurantee when timeouts will execute in the browser so we
95
+ // have to be a little flexible about testing repeated loops like this.
96
+ var checks = 10 ;
97
+ var f = function() {
98
+ if (--checks < 0) assertEqual(YES, NO, 'Timer never invalidated :') ;
99
+ if ((checks > 0) && t.get('isValid')) {
100
+ wait(100, f);
101
+ } else {
102
+ var diffs = fired.map(function(x) { return x - start; });
103
+ assertEqual(NO, t.get('isValid'), 'Timer did not terminate: %@'.fmt(diffs.join(', '))) ;
104
+ }
105
+ };
106
+ wait(600, f);
107
+ },
108
+
109
+ "scheduling multiple timers at the same time should cause them to fire at same time": function() {
110
+
111
+ var f1 = 0; var f2 = 0;
112
+ SC.runLoop.beginRunLoop() ;
113
+ var start = SC.runLoop.get('startTime') ;
114
+
115
+ var t1 = SC.Timer.schedule({
116
+ target: this,
117
+ action: function() { f1 = SC.runLoop.get('startTime'); },
118
+ interval: 100
119
+ });
120
+
121
+ var t2 = SC.Timer.schedule({
122
+ target: this,
123
+ action: function() { f2 = SC.runLoop.get('startTime'); },
124
+ interval: 100
125
+ });
126
+
127
+ // be lenient on execution time since we can't control the browser.
128
+ var tries = 10 ;
129
+ var f = function() {
130
+ if ((f1 == 0 || f2 == 0) && --tries >= 0) {
131
+ wait(100, f) ; return ;
132
+ }
133
+
134
+ assertEqual(f1, f2, 'execution time f1 == f2');
135
+ assertEqual(NO, t1.get('isValid'), 't1.isValid') ;
136
+ assertEqual(NO, t2.get('isValid'), 't2.isValid') ;
137
+ } ;
138
+ wait(200, f) ;
139
+ }
140
+
141
+ });
142
+
143
+ </script>
144
+
145
+ <% end %>
@@ -1,12 +1,12 @@
1
1
  <% # ========================================================================
2
- # Sproutcore.ScrollView Unit Test
2
+ # SC.CheckboxView Unit Test
3
3
  # ========================================================================
4
4
  %>
5
5
  <% content_for('final') do %>
6
6
 
7
7
  <script>
8
8
 
9
- Test.context("Sproutcore.ScrollView",{
9
+ Test.context("SC.CheckboxView",{
10
10
 
11
11
  "TODO: Add your own tests here": function() {
12
12
  true.shouldEqual(true) ;
@@ -14,7 +14,7 @@ Test.context("Sproutcore.ScrollView",{
14
14
 
15
15
  }) ;
16
16
 
17
- appMain = main; main = null ; // Cancel main() so app does not start
17
+ if (window.main && (appMain = main)) main = null ;
18
18
 
19
19
  </script>
20
20
 
@@ -3,38 +3,53 @@
3
3
 
4
4
  Test.context("A SC.CollectionView with it's content set to a SC.CollectionController", {
5
5
 
6
- "Should contain the same number of item views as it's controller has records": function()
6
+ "Should contain the same number of visible item views": function()
7
7
  {
8
- testCollectionView.get('itemViews').length.shouldEqual(6);
8
+ testCollectionView.get('itemViews').length.shouldEqual(2);
9
9
  },
10
+
10
11
  "Should update it's item views as it's controller is updated": function()
11
12
  {
12
- testCollectionView.get('itemViews').length.shouldEqual(6);
13
- SC.Store.addRecord( SC.Record.create({ guid: '1007', name: 'item seven' }) );
14
- testCollectionView.get('itemViews').length.shouldEqual(7);
13
+ var valueOfFirstItemView = function() {
14
+ var itemView = testCollectionView.get('itemViews').first() ;
15
+ return (itemView) ? itemView.get('content').get('guid') : null ;
16
+ } ;
17
+
18
+ valueOfFirstItemView().shouldEqual('1001') ;
19
+
20
+ SC.Store.addRecord( SC.Record.create({ guid: '0999', name: 'item zero' }) );
21
+
22
+ valueOfFirstItemView().shouldEqual('0999') ;
15
23
  },
24
+
16
25
  "Should scroll to the selected item": function()
17
26
  {
18
- testCollection.get('records').length.shouldEqual(6);
19
27
  testCollectionView.get('rootElement').scrollTop.shouldEqual(0);
20
- testCollectionView.scrollToItemRecord( testCollection.get('records').last() );
21
- testCollectionView.get('rootElement').scrollTop.shouldEqual(30);
28
+ testCollectionView.scrollToContent( testCollection.get('records').last() );
29
+ scrollView.get('rootElement').scrollTop.shouldEqual(30);
22
30
  },
31
+
23
32
  "Should not scroll to the selected item if it's already fully visible": function()
24
33
  {
25
- testCollection.get('records').length.shouldEqual(6);
26
- testCollectionView.get('rootElement').scrollTop.shouldEqual(0);
27
- testCollectionView.scrollToItemRecord( testCollection.get('records')[1] );
28
- testCollectionView.get('rootElement').scrollTop.shouldEqual(0);
34
+ scrollView.get('rootElement').scrollTop.shouldEqual(0);
35
+ testCollectionView.scrollToContent( testCollection.get('records')[1] );
36
+ scrollView.get('rootElement').scrollTop.shouldEqual(0);
29
37
  },
38
+
30
39
  setup: function()
31
40
  {
41
+ // add a scroll view wrapper.
42
+ scrollView = SC.ScrollView.create() ;
43
+ scrollView.set('frame', { x: 10, y: 10, width: 100, height: 30 });
44
+ SC.window.appendChild(scrollView);
45
+
32
46
  // create the view...
33
- testCollectionView = SC.CollectionView.extend({
47
+ testCollectionView = SC.ListView.extend({
48
+ contentValueKey: 'name',
34
49
  contentBinding: 'testController.arrangedObjects',
35
50
  selectionBinding: 'testController.selection'
36
51
  }).create();
37
- SC.window.appendChild(testCollectionView);
52
+ scrollView.set('content', testCollectionView) ;
38
53
 
39
54
  // create some item data...
40
55
  [
@@ -54,36 +69,25 @@ Test.context("A SC.CollectionView with it's content set to a SC.CollectionContro
54
69
  testController = SC.CollectionController.create();
55
70
  testController.set('content', testCollection);
56
71
 
57
-
58
- // make the view scrollable.
59
- var element = Element.extend(testCollectionView.get('rootElement'));
60
- element.setStyle({ overflow: 'auto', width: '100px', height: '30px' });
61
- // set the item heights to force the collection to scroll
62
- element.childElements().each(function(child)
63
- {
64
- child.setStyle({ height: '10px' });
65
- });
66
72
  },
67
73
  teardown: function()
68
74
  {
69
75
  // tell SC.Store to dump all the records...
70
76
  // otherwise, since SC.Store is shared across all tests (yuk!) we'll get shared fixtues
71
77
  testCollection.get('records').each(function(r){ SC.Store.removeRecord(r); });
72
-
78
+
73
79
  // remove the view from SC.window... again, no shared fixtures...
74
80
  testCollectionView.removeFromParent();
75
-
81
+ scrollView.removeFromParent() ;
82
+
76
83
  delete testCollectionView;
77
84
  delete testCollection;
78
85
  delete testController;
86
+ delete scrollView ;
79
87
  }
80
88
 
81
89
  });
82
90
 
83
-
84
-
85
-
86
-
87
91
  Test.context("A SC.CollectionView with it's content set to a SC.ArrayController",
88
92
  {
89
93
  "Should contain the same number of item views as it's controller has records": function()
@@ -130,8 +134,5 @@ Test.context("A SC.CollectionView with it's content set to a SC.ArrayController"
130
134
  }
131
135
  });
132
136
 
133
-
134
-
135
-
136
137
  </script>
137
138
  <% end %>