kiteditor 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/LICENSE +25 -0
  2. data/app/controllers/mercury/images_controller.rb +5 -0
  3. data/app/controllers/mercury_controller.rb +34 -0
  4. data/app/models/mercury/image.rb +17 -0
  5. data/app/views/layouts/mercury.html.erb +33 -0
  6. data/app/views/layouts/popup.html.haml +9 -0
  7. data/app/views/mercury/images/_list.html.haml +22 -0
  8. data/app/views/mercury/images/index.html.haml +4 -0
  9. data/app/views/mercury/images/index.js.erb +2 -0
  10. data/app/views/mercury/lightviews/about.html +11 -0
  11. data/app/views/mercury/modals/character.html +255 -0
  12. data/app/views/mercury/modals/htmleditor.html +13 -0
  13. data/app/views/mercury/modals/link.html +94 -0
  14. data/app/views/mercury/modals/media.html +1 -0
  15. data/app/views/mercury/modals/table.html +84 -0
  16. data/app/views/mercury/palettes/backcolor.html +73 -0
  17. data/app/views/mercury/palettes/forecolor.html +73 -0
  18. data/app/views/mercury/panels/history.html +3 -0
  19. data/app/views/mercury/panels/notes.html +3 -0
  20. data/app/views/mercury/panels/snippets.html +12 -0
  21. data/app/views/mercury/selects/formatblock.html +11 -0
  22. data/app/views/mercury/selects/style.html +5 -0
  23. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  24. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  25. data/config/engine.rb +44 -0
  26. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  27. data/features/loading/loading.feature +22 -0
  28. data/features/loading/navigating.feature +77 -0
  29. data/features/loading/user_interface.feature +67 -0
  30. data/features/regions/editable/advanced_editing.feature +0 -0
  31. data/features/regions/editable/basic_editing.feature +195 -0
  32. data/features/regions/editable/inserting_links.feature +98 -0
  33. data/features/regions/editable/inserting_media.feature +110 -0
  34. data/features/regions/editable/inserting_snippets.feature +102 -0
  35. data/features/regions/editable/inserting_special_characters.feature +24 -0
  36. data/features/regions/editable/inserting_tables.feature +109 -0
  37. data/features/regions/editable/pasting.feature +0 -0
  38. data/features/regions/editable/uploading_images.feature +0 -0
  39. data/features/regions/markupable/advanced_editing.feature +0 -0
  40. data/features/regions/markupable/basic_editing.feature +0 -0
  41. data/features/regions/markupable/inserting_links.feature +0 -0
  42. data/features/regions/markupable/inserting_media.feature +0 -0
  43. data/features/regions/markupable/inserting_snippets.feature +0 -0
  44. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  45. data/features/regions/markupable/inserting_tables.feature +0 -0
  46. data/features/regions/markupable/uploading_images.feature +0 -0
  47. data/features/regions/snippetable/advanced_editing.feature +0 -0
  48. data/features/regions/snippetable/basic_editing.feature +0 -0
  49. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  50. data/features/saving/saving.feature +33 -0
  51. data/features/step_definitions/debug_steps.rb +14 -0
  52. data/features/step_definitions/mercury_steps.rb +438 -0
  53. data/features/step_definitions/web_steps.rb +211 -0
  54. data/features/support/env.rb +46 -0
  55. data/features/support/mercury_contents.rb +25 -0
  56. data/features/support/mercury_selectors.rb +148 -0
  57. data/features/support/paths.rb +38 -0
  58. data/features/support/selectors.rb +44 -0
  59. data/lib/generators/mercury/install/install_generator.rb +49 -0
  60. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/lib/mercury-rails.rb +3 -0
  63. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  64. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  66. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  67. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  68. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  69. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  70. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  71. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  72. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  73. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  74. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  75. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  76. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  77. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  78. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  79. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  80. data/spec/javascripts/mercury/page_editor_spec.js.coffee +750 -0
  81. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  82. data/spec/javascripts/mercury/panel_spec.js.coffee +185 -0
  83. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  84. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  87. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  88. data/spec/javascripts/mercury/snippet_spec.js.coffee +245 -0
  89. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  90. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  91. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  92. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  93. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  94. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  95. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  96. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  97. data/spec/javascripts/mercury/uploader_spec.js.coffee +514 -0
  98. data/spec/javascripts/spec_helper.js +513 -0
  99. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  100. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  101. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  103. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  104. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  105. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  106. data/spec/javascripts/templates/mercury/modal.html +13 -0
  107. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  108. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  110. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  111. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  112. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  113. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  114. data/spec/javascripts/templates/mercury/palette.html +16 -0
  115. data/spec/javascripts/templates/mercury/panel.html +16 -0
  116. data/spec/javascripts/templates/mercury/region.html +2 -0
  117. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  118. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  119. data/spec/javascripts/templates/mercury/select.html +16 -0
  120. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  121. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  122. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  123. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  124. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  125. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  126. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  127. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  128. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  129. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  130. data/vendor/assets/images/mercury/button.png +0 -0
  131. data/vendor/assets/images/mercury/close.png +0 -0
  132. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  133. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  134. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  135. data/vendor/assets/images/mercury/missing-image.png +0 -0
  136. data/vendor/assets/images/mercury/search-icon.png +0 -0
  137. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  138. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  139. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  140. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  154. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  155. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  156. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.18.custom.min.js +356 -0
  157. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui.1.8.13.custom.min.js +356 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  162. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  163. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  164. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  169. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  170. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  171. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -0
  172. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  173. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  174. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  176. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  177. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  178. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  179. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  180. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  181. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  182. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  183. data/vendor/assets/javascripts/mercury/modal.js.coffee +204 -0
  184. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  185. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  186. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +95 -0
  187. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +107 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  189. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  190. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  191. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +241 -0
  192. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  193. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  194. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  195. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  196. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  197. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  198. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  199. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +339 -0
  200. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  201. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  202. data/vendor/assets/javascripts/mercury/snippet.js.coffee +104 -0
  203. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  204. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  205. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  206. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  207. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  208. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  209. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  210. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  211. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  212. data/vendor/assets/javascripts/mercury/uploader.js.coffee +227 -0
  213. data/vendor/assets/javascripts/mercury.js +479 -0
  214. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  215. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  216. data/vendor/assets/javascripts/popup.js +8 -0
  217. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  218. data/vendor/assets/stylesheets/mercury/dialog.css +208 -0
  219. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  220. data/vendor/assets/stylesheets/mercury/mercury.css +151 -0
  221. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  222. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  223. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  224. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  225. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  226. data/vendor/assets/stylesheets/mercury.css +28 -0
  227. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  228. data/vendor/assets/stylesheets/popup.css.erb +37 -0
  229. metadata +634 -0
@@ -0,0 +1,220 @@
1
+ describe "Mercury.modalHandlers.insertLink", ->
2
+
3
+ template 'mercury/modals/insertlink.html'
4
+
5
+ beforeEach ->
6
+ Mercury.region = null
7
+ @modal =
8
+ element: $('#test')
9
+ hide: ->
10
+ resize: ->
11
+ window.mercuryInstance = {document: $(document)}
12
+
13
+ describe "initializing", ->
14
+
15
+ beforeEach ->
16
+ Mercury.modalHandlers.insertLink.call(@modal)
17
+
18
+ it "loads all links with a name into the existing bookmarks pulldown", ->
19
+ options = $('#link_existing_bookmark').html()
20
+ expect(options).toContain('link1')
21
+ expect(options).toContain('link2')
22
+ expect(options).toContain('Link Two')
23
+
24
+
25
+ describe "clicking on a radio button (in a label)", ->
26
+
27
+ beforeEach ->
28
+ Mercury.modalHandlers.insertLink.call(@modal)
29
+
30
+ it "focuses the next input with a selectable class", ->
31
+ spy = spyOn($.fn, 'focus').andCallFake(=>)
32
+ jasmine.simulate.click($('#checkbox1').get(0))
33
+ expect(spy.callCount).toEqual(1)
34
+
35
+
36
+ describe "focusing an input", ->
37
+
38
+ beforeEach ->
39
+ Mercury.modalHandlers.insertLink.call(@modal)
40
+
41
+ it "checks the corresponding checkbox", ->
42
+ $('#link_existing_bookmark').focus()
43
+ expect($('#checkbox2').get(0).checked).toEqual(true)
44
+
45
+
46
+ describe "changing the link target", ->
47
+
48
+ it "shows options for whatever was selected", ->
49
+ it "calls resize", ->
50
+
51
+
52
+ describe "when editing", ->
53
+
54
+ describe "a standard link", ->
55
+
56
+ beforeEach ->
57
+ Mercury.region = selection: => {
58
+ commonAncestor: -> $('<a>', {href: 'http://cnn.com', target: '_top'}).html('foo'),
59
+ textContent: -> 'content'
60
+ }
61
+ Mercury.modalHandlers.insertLink.call(@modal)
62
+
63
+ it "hides the link text input", ->
64
+ expect($('#link_text_container').css('display')).toEqual('none')
65
+
66
+ it "pre-fills the link url input", ->
67
+ expect($('#link_external_url').val()).toEqual('http://cnn.com')
68
+
69
+ it "selects the target if one's available", ->
70
+ expect($('#link_target').val()).toEqual('_top')
71
+
72
+ it "fills the content", ->
73
+ expect($('#link_text').val()).toEqual('content')
74
+
75
+ describe "a javascript popup link", ->
76
+
77
+ beforeEach ->
78
+ Mercury.region = selection: => {commonAncestor: -> $('<a>', {href: "javascript:void(window.open('http://cnn.com', 'popup_window', 'width=100,height=42,menubar=no,toolbar=no'))"}).html('foo')}
79
+ Mercury.modalHandlers.insertLink.call(@modal)
80
+
81
+ it "hides the link text input", ->
82
+ expect($('#link_text_container').css('display')).toEqual('none')
83
+
84
+ it "pre-fills the link url input", ->
85
+ expect($('#link_external_url').val()).toEqual('http://cnn.com')
86
+
87
+ it "selects the target", ->
88
+ expect($('#link_target').val()).toEqual('popup')
89
+
90
+ it "sets the width and height by parsing them out of the href", ->
91
+ expect($('#link_popup_width').val()).toEqual('100')
92
+ expect($('#link_popup_height').val()).toEqual('42')
93
+
94
+ describe "a bookmark link", ->
95
+
96
+ beforeEach ->
97
+ Mercury.region = selection: => {commonAncestor: -> $('<a>', {href: '#link2'}).html('foo')}
98
+ Mercury.modalHandlers.insertLink.call(@modal)
99
+
100
+ it "hides the link text input", ->
101
+ expect($('#link_text_container').css('display')).toEqual('none')
102
+
103
+ it "checks the existing bookmark radio", ->
104
+ expect($('input[value=existing_bookmark]').get(0).checked).toEqual(true)
105
+
106
+ it "selects the correct option from the list", ->
107
+ expect($('#link_existing_bookmark').val()).toEqual('link2')
108
+
109
+ describe "a bookmark target", ->
110
+
111
+ beforeEach ->
112
+ Mercury.region = selection: => {commonAncestor: -> $('<a>', {name: 'link3'}).html('foo')}
113
+ Mercury.modalHandlers.insertLink.call(@modal)
114
+
115
+ it "hides the link text input", ->
116
+ expect($('#link_text_container').css('display')).toEqual('none')
117
+
118
+ it "checks the new bookmark radio", ->
119
+ expect($('input[value=new_bookmark]').get(0).checked).toEqual(true)
120
+
121
+ it "sets the link name input", ->
122
+ expect($('#link_new_bookmark').val()).toEqual('link3')
123
+
124
+
125
+ describe "submitting", ->
126
+
127
+ describe "a new link", ->
128
+
129
+ beforeEach ->
130
+ Mercury.modalHandlers.insertLink.call(@modal)
131
+ @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
132
+ $('#link_text').val('foo')
133
+
134
+ it "hides the modal", ->
135
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
136
+ jasmine.simulate.click($('#submit').get(0))
137
+ expect(spy.callCount).toEqual(1)
138
+
139
+ describe "as a standard link", ->
140
+
141
+ beforeEach ->
142
+ $('#link_external_url').val('http://cnn.com')
143
+ $('#link_target').val('_top')
144
+
145
+ it "triggers an action with the proper values", ->
146
+ jasmine.simulate.click($('#submit').get(0))
147
+ expect(@triggerSpy.callCount).toEqual(1)
148
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
149
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
150
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({tagName: 'a', attrs: {href: 'http://cnn.com', target: '_top'}, content: 'foo'})
151
+
152
+ describe "as a javascript popup", ->
153
+
154
+ beforeEach ->
155
+ $('#link_external_url').val('http://cnn.com')
156
+ $('#link_target').val('popup')
157
+ $('#link_popup_width').val(100)
158
+ $('#link_popup_height').val('42')
159
+
160
+ it "triggers an action with the proper values", ->
161
+ jasmine.simulate.click($('#submit').get(0))
162
+ expect(@triggerSpy.callCount).toEqual(1)
163
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
164
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
165
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({tagName: 'a', attrs: {href: "javascript:void(window.open('http://cnn.com', 'popup_window', 'width=100,height=42,menubar=no,toolbar=no'))"}, content: 'foo'})
166
+
167
+ describe "as an existing bookmark", ->
168
+
169
+ beforeEach ->
170
+ $('#link_existing_bookmark').val('link2')
171
+ $('input[value=existing_bookmark]').prop('checked', true)
172
+
173
+ it "triggers an action with the proper values", ->
174
+ jasmine.simulate.click($('#submit').get(0))
175
+ expect(@triggerSpy.callCount).toEqual(1)
176
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
177
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
178
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({tagName: 'a', attrs: {href: '#link2'}, content: 'foo'})
179
+
180
+ describe "as a new bookmark", ->
181
+
182
+ beforeEach ->
183
+ $('#link_new_bookmark').val('link3')
184
+ $('input[value=new_bookmark]').prop('checked', true)
185
+
186
+ it "triggers an action with the proper values", ->
187
+ jasmine.simulate.click($('#submit').get(0))
188
+ expect(@triggerSpy.callCount).toEqual(1)
189
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
190
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
191
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({tagName: 'a', attrs: {name: 'link3'}, content: 'foo'})
192
+
193
+ describe "editing an existing link", ->
194
+
195
+ beforeEach ->
196
+ @existingLink = $('<a>', {name: 'link3'}).html('foo')
197
+ Mercury.region = selection: => {commonAncestor: => @existingLink}
198
+ Mercury.modalHandlers.insertLink.call(@modal)
199
+ @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
200
+ $('#link_text').val('foo')
201
+
202
+ it "hides the modal", ->
203
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
204
+ jasmine.simulate.click($('#submit').get(0))
205
+ expect(spy.callCount).toEqual(1)
206
+
207
+ describe "as a standard link", ->
208
+
209
+ beforeEach ->
210
+ $('#link_external_url').val('http://cnn.com')
211
+ $('#link_target').val('_top')
212
+ $('input[value=external_url]').prop('checked', true)
213
+
214
+ it "triggers an action with the proper values", ->
215
+ jasmine.simulate.click($('#submit').get(0))
216
+ expect(@triggerSpy.callCount).toEqual(1)
217
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
218
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('replaceLink')
219
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({tagName: 'a', attrs: {href: 'http://cnn.com', target: '_top'}, content: 'foo'})
220
+ expect(@triggerSpy.argsForCall[0][1]['node']).toEqual(@existingLink.get(0))
@@ -0,0 +1,167 @@
1
+ describe "Mercury.modalHandlers.insertMedia", ->
2
+
3
+ template 'mercury/modals/insertmedia.html'
4
+
5
+ beforeEach ->
6
+ Mercury.region = null
7
+ spyOn(window, 'setTimeout').andCallFake((timeout, callback) => callback())
8
+ @modal =
9
+ element: $('#test')
10
+ hide: ->
11
+ resize: ->
12
+
13
+ describe "clicking on a radio button (in a label)", ->
14
+
15
+ beforeEach ->
16
+ Mercury.modalHandlers.insertMedia.call(@modal)
17
+
18
+ it "focuses the next input with a selectable class", ->
19
+ spy = spyOn($.fn, 'focus').andCallFake(=>)
20
+ jasmine.simulate.click($('#checkbox1').get(0))
21
+ expect(spy.callCount).toEqual(1)
22
+
23
+
24
+ describe "focusing an input", ->
25
+
26
+ beforeEach ->
27
+ Mercury.modalHandlers.insertMedia.call(@modal)
28
+
29
+ it "checks the corresponding checkbox", ->
30
+ $('#media_youtube_url').focus()
31
+ expect($('#checkbox2').get(0).checked).toEqual(true)
32
+
33
+ it "hides all the option divs", ->
34
+ $('#media_youtube_url').focus()
35
+ expect($('#image_url').css('display')).toEqual('none')
36
+ expect($('#vimeo_url').css('display')).toEqual('none')
37
+
38
+ it "shows the options for the item that was focused", ->
39
+ $('#media_youtube_url').focus()
40
+ expect($('#youtube_url').css('display')).toNotEqual('none')
41
+
42
+ it "calls resize", ->
43
+ spy = spyOn(@modal, 'resize').andCallFake(=>)
44
+ $('#media_youtube_url').focus()
45
+ expect(spy.callCount).toEqual(1)
46
+
47
+
48
+ describe "when editing", ->
49
+
50
+ describe "an existing image", ->
51
+
52
+ beforeEach ->
53
+ @focusSpy = spyOn($.fn, 'focus').andCallThrough()
54
+ @selection = {is: -> $('<img>', {src: '/foo.gif', align: 'right'})}
55
+ Mercury.region = selection: => @selection
56
+ Mercury.modalHandlers.insertMedia.call(@modal)
57
+
58
+ it "pre-fills the image url", ->
59
+ expect($('#media_image_url').val()).toEqual('/foo.gif')
60
+
61
+ it "focuses the url input", ->
62
+ expect(@focusSpy.callCount).toEqual(1)
63
+ expect($('input[value=image_url]').get(0).checked).toEqual(true)
64
+
65
+ it "sets the image alignment option", ->
66
+ expect($('#media_image_alignment').val()).toEqual('right')
67
+
68
+ describe "an existing youtube video", ->
69
+
70
+ beforeEach ->
71
+ @focusSpy = spyOn($.fn, 'focus').andCallThrough()
72
+ @selection = {is: -> $('<iframe>', {src: 'http://www.youtube.com/embed/foo?wmode=transparent', style: 'width:100px;height:42px'})}
73
+ Mercury.region = selection: => @selection
74
+ Mercury.modalHandlers.insertMedia.call(@modal)
75
+
76
+ it "pre-fills the url", ->
77
+ expect($('#media_youtube_url').val()).toEqual('http://youtu.be/foo')
78
+
79
+ it "focuses the url input", ->
80
+ expect($('input[value=youtube_url]').get(0).checked).toEqual(true)
81
+
82
+ it "sets the width option", ->
83
+ expect($('#media_youtube_width').val()).toEqual('100')
84
+
85
+ it "sets the height option", ->
86
+ expect($('#media_youtube_height').val()).toEqual('42')
87
+
88
+ describe "an existing vimeo video", ->
89
+
90
+ beforeEach ->
91
+ @focusSpy = spyOn($.fn, 'focus').andCallThrough()
92
+ @selection = {is: -> $('<iframe>', {src: 'http://player.vimeo.com/video/foo?title=1&byline=1&portrait=0&color=ffffff', style: 'width:100px;height:42px'})}
93
+ Mercury.region = selection: => @selection
94
+ Mercury.modalHandlers.insertMedia.call(@modal)
95
+
96
+ it "pre-fills the url", ->
97
+ expect($('#media_vimeo_url').val()).toEqual('http://vimeo.com/foo')
98
+
99
+ it "focuses the url input", ->
100
+ expect($('input[value=vimeo_url]').get(0).checked).toEqual(true)
101
+
102
+ it "sets the width option", ->
103
+ expect($('#media_vimeo_width').val()).toEqual('100')
104
+
105
+ it "sets the height option", ->
106
+ expect($('#media_vimeo_height').val()).toEqual('42')
107
+
108
+
109
+ describe "submitting", ->
110
+
111
+ beforeEach ->
112
+ Mercury.modalHandlers.insertMedia.call(@modal)
113
+ @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
114
+
115
+ it "hides the modal", ->
116
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
117
+ jasmine.simulate.click($('#submit').get(0))
118
+ expect(spy.callCount).toEqual(1)
119
+
120
+ describe "an image", ->
121
+
122
+ beforeEach ->
123
+ $('#media_image_url').val('http://domain/foo.gif')
124
+ $('#media_image_alignment').val('right')
125
+
126
+ it "triggers an action with the proper values", ->
127
+ jasmine.simulate.click($('#submit').get(0))
128
+ expect(@triggerSpy.callCount).toEqual(1)
129
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
130
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertImage')
131
+ expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({src: 'http://domain/foo.gif', align: 'right'})
132
+
133
+ describe "a youtube video", ->
134
+
135
+ beforeEach ->
136
+ $('#media_youtube_url').val('http://youtu.be/foo')
137
+ $('#media_youtube_width').val(100)
138
+ $('#media_youtube_height').val('42')
139
+ $('input[value=youtube_url]').prop('checked', true)
140
+
141
+ it "triggers an action with the proper values", ->
142
+ jasmine.simulate.click($('#submit').get(0))
143
+ expect(@triggerSpy.callCount).toEqual(1)
144
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
145
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')
146
+ value = $('<div>').html(@triggerSpy.argsForCall[0][1]['value']).html()
147
+ expect(value).toContain('100px')
148
+ expect(value).toContain('42px')
149
+ expect(value).toContain('src="http://www.youtube.com/embed/foo?wmode=transparent"')
150
+
151
+ describe "a vimeo video", ->
152
+
153
+ beforeEach ->
154
+ $('#media_vimeo_url').val('http://vimeo.com/foo')
155
+ $('#media_vimeo_width').val(100)
156
+ $('#media_vimeo_height').val('42')
157
+ $('input[value=vimeo_url]').prop('checked', true)
158
+
159
+ it "triggers an action with the proper values", ->
160
+ jasmine.simulate.click($('#submit').get(0))
161
+ expect(@triggerSpy.callCount).toEqual(1)
162
+ expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
163
+ expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')
164
+ value = $('<div>').html(@triggerSpy.argsForCall[0][1]['value']).html()
165
+ expect(value).toContain('100px')
166
+ expect(value).toContain('42px')
167
+ expect(value).toContain('http://player.vimeo.com/video/foo?title=1&amp;byline=1&amp;portrait=0&amp;color=ffffff')
@@ -0,0 +1,52 @@
1
+ describe "Mercury.modalHandlers.insertSnippet", ->
2
+
3
+ template 'mercury/modals/insertsnippet.html'
4
+
5
+ beforeEach ->
6
+ Mercury.Snippet.all = []
7
+ Mercury.Snippet.load({
8
+ 'snippet_0': {name: 'foo', options: {'first_name': "Jeremy", 'last_name': "Jackson"}},
9
+ })
10
+ @modal =
11
+ element: $('#test')
12
+ hide: ->
13
+ options: {snippetName: 'test'}
14
+ Mercury.modalHandlers.insertSnippet.call(@modal)
15
+
16
+ describe "submitting", ->
17
+
18
+ it "hides the modal", ->
19
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
20
+ jasmine.simulate.click($('#submit').get(0))
21
+ expect(spy.callCount).toEqual(1)
22
+
23
+ describe "if there's an active snippet", ->
24
+
25
+ beforeEach ->
26
+ Mercury.snippet = Mercury.Snippet.all[0]
27
+
28
+ it "updates the snippet", ->
29
+ spy = spyOn(Mercury.Snippet.prototype, 'setOptions').andCallThrough()
30
+ jasmine.simulate.click($('#submit').get(0))
31
+ expect(spy.callCount).toEqual(1)
32
+ expect(Mercury.Snippet.all[0]['options']).toEqual({first_name: 'Wilma', last_name: 'Flintstone'})
33
+
34
+ it "triggers an action", ->
35
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
36
+ jasmine.simulate.click($('#submit').get(0))
37
+ expect(spy.callCount).toEqual(1)
38
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'insertSnippet', value: Mercury.Snippet.all[0]}])
39
+
40
+ describe "if there's no active snippet", ->
41
+
42
+ it "creates a snippet", ->
43
+ spy = spyOn(Mercury.Snippet, 'create').andCallThrough()
44
+ jasmine.simulate.click($('#submit').get(0))
45
+ expect(spy.callCount).toEqual(1)
46
+ expect(Mercury.Snippet.all[1]['options']).toEqual({first_name: 'Wilma', last_name: 'Flintstone'})
47
+
48
+ it "triggers an action", ->
49
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
50
+ jasmine.simulate.click($('#submit').get(0))
51
+ expect(spy.callCount).toEqual(1)
52
+ expect(spy.argsForCall[0]).toEqual(['action', {action: 'insertSnippet', value: Mercury.Snippet.all[1]}])
@@ -0,0 +1,160 @@
1
+ describe "Mercury.modalHandlers.insertTable", ->
2
+
3
+ template 'mercury/modals/inserttable.html'
4
+
5
+ beforeEach ->
6
+ @modal =
7
+ element: $('#test')
8
+ hide: ->
9
+
10
+ describe "initializing", ->
11
+
12
+ beforeEach ->
13
+ @tableEditorSpy = spyOn(Mercury, 'tableEditor').andCallFake(=>)
14
+ Mercury.modalHandlers.insertTable.call(@modal)
15
+
16
+ it "selects the first cell", ->
17
+ expect($('#cell1').hasClass('selected')).toEqual(true)
18
+
19
+ it "sets the table editor up", ->
20
+ expect(@tableEditorSpy.callCount).toEqual(1)
21
+ expect(@tableEditorSpy.argsForCall[0][0].get(0)).toEqual($('#table').get(0))
22
+ expect(@tableEditorSpy.argsForCall[0][1].get(0)).toEqual($('#cell1').get(0))
23
+
24
+ describe "clicking on the cells", ->
25
+
26
+ beforeEach ->
27
+ @tableEditorSpy = spyOn(Mercury, 'tableEditor').andCallFake(=>)
28
+ Mercury.modalHandlers.insertTable.call(@modal)
29
+
30
+ it "should unselect any selected cells", ->
31
+ jasmine.simulate.click($('#cell2').get(0))
32
+ expect($('#cell1').hasClass('selected')).toEqual(false)
33
+
34
+ it "selects the cell clicked on", ->
35
+ jasmine.simulate.click($('#cell2').get(0))
36
+ expect($('#cell2').hasClass('selected')).toEqual(true)
37
+
38
+ it "sets the table editor to use the selected cell", ->
39
+ jasmine.simulate.click($('#cell2').get(0))
40
+ expect(@tableEditorSpy.callCount).toEqual(2)
41
+ expect(@tableEditorSpy.argsForCall[1][1].get(0)).toEqual($('#cell2').get(0))
42
+
43
+
44
+ describe "clicking on the action buttons", ->
45
+
46
+ beforeEach ->
47
+ @addRowSpy = spyOn(Mercury.tableEditor, 'addRow').andCallFake(=>)
48
+ @removeRowSpy = spyOn(Mercury.tableEditor, 'removeRow').andCallFake(=>)
49
+ @addColumnSpy = spyOn(Mercury.tableEditor, 'addColumn').andCallFake(=>)
50
+ @removeColumnSpy = spyOn(Mercury.tableEditor, 'removeColumn').andCallFake(=>)
51
+ @increaseColspanSpy = spyOn(Mercury.tableEditor, 'increaseColspan').andCallFake(=>)
52
+ @decreaseColspanSpy = spyOn(Mercury.tableEditor, 'decreaseColspan').andCallFake(=>)
53
+ @increaseRowspanSpy = spyOn(Mercury.tableEditor, 'increaseRowspan').andCallFake(=>)
54
+ @decreaseRowspanSpy = spyOn(Mercury.tableEditor, 'decreaseRowspan').andCallFake(=>)
55
+ Mercury.modalHandlers.insertTable.call(@modal)
56
+
57
+ it "adds a row before the selected cell", ->
58
+ jasmine.simulate.click($('input[name=insertRowBefore]').get(0))
59
+ expect(@addRowSpy.callCount).toEqual(1)
60
+ expect(@addRowSpy.argsForCall[0]).toEqual(['before'])
61
+
62
+ it "adds a row after the selected cell", ->
63
+ jasmine.simulate.click($('input[name=insertRowAfter]').get(0))
64
+ expect(@addRowSpy.callCount).toEqual(1)
65
+ expect(@addRowSpy.argsForCall[0]).toEqual(['after'])
66
+
67
+ it "deletes the row of the selected cell", ->
68
+ jasmine.simulate.click($('input[name=deleteRow]').get(0))
69
+ expect(@removeRowSpy.callCount).toEqual(1)
70
+
71
+ it "adds a column before the selected cell", ->
72
+ jasmine.simulate.click($('input[name=insertColumnBefore]').get(0))
73
+ expect(@addColumnSpy.callCount).toEqual(1)
74
+ expect(@addColumnSpy.argsForCall[0]).toEqual(['before'])
75
+
76
+ it "adds a column after the selected cell", ->
77
+ jasmine.simulate.click($('input[name=insertColumnAfter]').get(0))
78
+ expect(@addColumnSpy.callCount).toEqual(1)
79
+ expect(@addColumnSpy.argsForCall[0]).toEqual(['after'])
80
+
81
+ it "deletes the column of the selected cell", ->
82
+ jasmine.simulate.click($('input[name=deleteColumn]').get(0))
83
+ expect(@removeColumnSpy.callCount).toEqual(1)
84
+
85
+ it "increases the colspan of the selected cell", ->
86
+ jasmine.simulate.click($('input[name=increaseColspan]').get(0))
87
+ expect(@increaseColspanSpy.callCount).toEqual(1)
88
+
89
+ it "decreases the colspan of the selected cell", ->
90
+ jasmine.simulate.click($('input[name=decreaseColspan]').get(0))
91
+ expect(@decreaseColspanSpy.callCount).toEqual(1)
92
+
93
+ it "increases the rowspan of the selected cell", ->
94
+ jasmine.simulate.click($('input[name=increaseRowspan]').get(0))
95
+ expect(@increaseRowspanSpy.callCount).toEqual(1)
96
+
97
+ it "decreases the rowspan of the selected cell", ->
98
+ jasmine.simulate.click($('input[name=decreaseRowspan]').get(0))
99
+ expect(@decreaseRowspanSpy.callCount).toEqual(1)
100
+
101
+
102
+ describe "changing the alignment", ->
103
+
104
+ it "changes the alignment of the table", ->
105
+
106
+
107
+ describe "changing the border", ->
108
+
109
+ beforeEach ->
110
+ Mercury.modalHandlers.insertTable.call(@modal)
111
+
112
+ it "changes the border of the table", ->
113
+ $('#table_border').val('19')
114
+ jasmine.simulate.keyup($('#table_border').get(0))
115
+ expect($('#table').attr('border')).toEqual('19')
116
+
117
+ it "handles non-numeric values", ->
118
+ $('#table_border').val('2x')
119
+ jasmine.simulate.keyup($('#table_border').get(0))
120
+ expect($('#table').attr('border')).toEqual('2')
121
+
122
+
123
+ describe "changing the cellspacing", ->
124
+
125
+ beforeEach ->
126
+ Mercury.modalHandlers.insertTable.call(@modal)
127
+
128
+ it "changes the cellspacing of the table", ->
129
+ $('#table_spacing').val('5')
130
+ jasmine.simulate.keyup($('#table_spacing').get(0))
131
+ expect($('#table').attr('cellspacing')).toEqual('5')
132
+
133
+ it "handles non-numeric values", ->
134
+ $('#table_spacing').val('12x')
135
+ jasmine.simulate.keyup($('#table_spacing').get(0))
136
+ expect($('#table').attr('cellspacing')).toEqual('12')
137
+
138
+
139
+ describe "submitting", ->
140
+
141
+ beforeEach ->
142
+ Mercury.modalHandlers.insertTable.call(@modal)
143
+
144
+ it "triggers an action", ->
145
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
146
+ jasmine.simulate.click($('#submit').get(0))
147
+ expect(spy.callCount).toEqual(1)
148
+ expect(spy.argsForCall[0][0]).toEqual('action')
149
+ expect(spy.argsForCall[0][1]['action']).toEqual('insertTable')
150
+ value = spy.argsForCall[0][1]['value']
151
+ expect(value).toContain('border="1"')
152
+ expect(value).toContain('cellspacing="0"')
153
+ expect(value).toContain('<td id="cell2"><br></td>')
154
+
155
+ it "hides the modal", ->
156
+ spy = spyOn(@modal, 'hide').andCallFake(=>)
157
+ jasmine.simulate.click($('#submit').get(0))
158
+ expect(spy.callCount).toEqual(1)
159
+
160
+
@@ -0,0 +1,60 @@
1
+ describe "String", ->
2
+
3
+ describe "#titleize", ->
4
+
5
+ it "should capitalize the first letter in a string", ->
6
+ expect('wow!'.titleize()).toEqual('Wow!')
7
+
8
+
9
+ describe "#toHex", ->
10
+
11
+ it "converts a rgb(0, 0, 0) type string to hex", ->
12
+ expect('rgb(0, 0, 0)'.toHex()).toEqual('#000000')
13
+ expect('rgb(255, 255, 0)'.toHex()).toEqual('#FFFF00')
14
+
15
+
16
+ describe "#regExpEscape", ->
17
+
18
+ it "escapes characters used in regular expressions", ->
19
+ expect('/.*+?|()[]{}\\'.regExpEscape()).toEqual('\\/\\.\\*\\+\\?\\|\\(\\)\\[\\]\\{\\}\\\\')
20
+
21
+
22
+ describe "#printf", ->
23
+
24
+ it "works something like a basic implementation of the standard sprintf", ->
25
+ expect('int %d'.printf(2.1)).toEqual('int 2')
26
+ expect('int%d'.printf(2.1)).toEqual('int2')
27
+ expect('%d-int'.printf(2.1)).toEqual('2-int')
28
+ expect('%f float'.printf(2.1)).toEqual('2.1 float')
29
+ expect('%s string'.printf(2.1)).toEqual('2.1 string')
30
+ expect('%% a'.printf(2.1)).toEqual('% a')
31
+ expect('a %% b'.printf()).toEqual('a % b')
32
+ expect('a %% %d'.printf(2.1)).toEqual('a % 2')
33
+ expect('%d\n%s'.printf(2.1, 'string')).toEqual('2\nstring')
34
+
35
+
36
+ describe "Number", ->
37
+
38
+ describe "#toHex", ->
39
+
40
+ it "converts a number to it's hex value", ->
41
+ expect(100.toHex()).toEqual('64')
42
+ expect(255.toHex()).toEqual('FF')
43
+
44
+ it "pads 0-F with a 0", ->
45
+ expect(0.toHex()).toEqual('00')
46
+ expect(15.toHex()).toEqual('0F')
47
+
48
+ describe "#toBytes", ->
49
+
50
+ it "converts a number to a readable byte representation (eg. 1.2 kb, 3.4 Mb)", ->
51
+ kb = 1024
52
+ expect(kb.toBytes()).toEqual('1.00 kb')
53
+ expect((kb + 100).toBytes()).toEqual('1.10 kb')
54
+ expect((kb * 1000).toBytes()).toEqual('1000.00 kb')
55
+ expect((kb * 1024).toBytes()).toEqual('1.00 Mb')
56
+ expect((kb * 1024 * 1024).toBytes()).toEqual('1.00 Gb')
57
+ expect((kb * 1024 * 1024 * 1024).toBytes()).toEqual('1.00 Tb')
58
+ expect((kb * 1024 * 1024 * 1024 * 1024).toBytes()).toEqual('1.00 Pb')
59
+ expect((kb * 1024 * 1024 * 1024 * 1024 * 1024).toBytes()).toEqual('1.00 Eb')
60
+