bootstrap_form_extensions 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/bootstrap_form_extensions/arrayed_field.js +70 -0
  5. data/app/assets/javascripts/bootstrap_form_extensions/bootstrap-timepicker.min.js +5 -0
  6. data/app/assets/javascripts/bootstrap_form_extensions/index.js +2 -0
  7. data/app/assets/javascripts/bootstrap_form_extensions/jquery.html5data.min.js +7 -0
  8. data/app/assets/javascripts/bootstrap_form_extensions/scheduler.js +226 -0
  9. data/app/assets/javascripts/bootstrap_form_extensions/select_or_new.js +76 -0
  10. data/app/assets/javascripts/bootstrap_form_extensions/time_picker.js +61 -0
  11. data/app/assets/javascripts/bootstrap_form_extensions/timespan.js +60 -0
  12. data/app/assets/stylesheets/bootstrap_form_extensions/bootstrap-timepicker.min.css +10 -0
  13. data/app/assets/stylesheets/bootstrap_form_extensions/common.css +11 -0
  14. data/app/assets/stylesheets/bootstrap_form_extensions/index.css +4 -0
  15. data/app/assets/stylesheets/bootstrap_form_extensions/scheduler.css +31 -0
  16. data/app/assets/stylesheets/bootstrap_form_extensions/submit_bar.css +4 -0
  17. data/app/views/bootstrap_form_extensions/_submit_bar.html.erb +36 -0
  18. data/lib/bootstrap_form_extensions.rb +22 -0
  19. data/lib/bootstrap_form_extensions/arrayed_field.rb +107 -0
  20. data/lib/bootstrap_form_extensions/date_time_pickers.rb +71 -0
  21. data/lib/bootstrap_form_extensions/helpers.rb +18 -0
  22. data/lib/bootstrap_form_extensions/scheduler.rb +72 -0
  23. data/lib/bootstrap_form_extensions/select_or_new.rb +36 -0
  24. data/lib/bootstrap_form_extensions/submit_bar.rb +65 -0
  25. data/lib/bootstrap_form_extensions/timespan.rb +55 -0
  26. data/lib/bootstrap_form_extensions/version.rb +3 -0
  27. data/lib/tasks/rails_bootstrap_form_extensions_tasks.rake +4 -0
  28. data/test/arrayed_field_test.rb +63 -0
  29. data/test/bootstrap_form_extensions_test.rb +7 -0
  30. data/test/date_time_pickers_test.rb +50 -0
  31. data/test/dummy/README.rdoc +28 -0
  32. data/test/dummy/Rakefile +6 -0
  33. data/test/dummy/app/assets/javascripts/application.js +13 -0
  34. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  35. data/test/dummy/app/controllers/application_controller.rb +5 -0
  36. data/test/dummy/app/helpers/application_helper.rb +2 -0
  37. data/test/dummy/app/models/category.rb +7 -0
  38. data/test/dummy/app/models/thing.rb +46 -0
  39. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  40. data/test/dummy/bin/bundle +3 -0
  41. data/test/dummy/bin/rails +4 -0
  42. data/test/dummy/bin/rake +4 -0
  43. data/test/dummy/bin/setup +29 -0
  44. data/test/dummy/config.ru +4 -0
  45. data/test/dummy/config/application.rb +26 -0
  46. data/test/dummy/config/boot.rb +5 -0
  47. data/test/dummy/config/database.yml +25 -0
  48. data/test/dummy/config/environment.rb +5 -0
  49. data/test/dummy/config/environments/development.rb +41 -0
  50. data/test/dummy/config/environments/production.rb +79 -0
  51. data/test/dummy/config/environments/test.rb +42 -0
  52. data/test/dummy/config/initializers/assets.rb +11 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  55. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  56. data/test/dummy/config/initializers/inflections.rb +16 -0
  57. data/test/dummy/config/initializers/mime_types.rb +4 -0
  58. data/test/dummy/config/initializers/session_store.rb +3 -0
  59. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/test/dummy/config/locales/en.yml +23 -0
  61. data/test/dummy/config/routes.rb +3 -0
  62. data/test/dummy/config/secrets.yml +22 -0
  63. data/test/dummy/db/migrate/20150918185031_create_things.rb +9 -0
  64. data/test/dummy/db/migrate/20150924203053_add_timespan.rb +7 -0
  65. data/test/dummy/db/migrate/20150929213249_add_arrayed_field.rb +7 -0
  66. data/test/dummy/db/migrate/20151006171627_add_another_arrayed_field.rb +7 -0
  67. data/test/dummy/db/migrate/20151006181943_add_json_field.rb +7 -0
  68. data/test/dummy/db/migrate/20151007213131_add_scheduler_field.rb +7 -0
  69. data/test/dummy/db/migrate/20151030194330_add_date_time.rb +7 -0
  70. data/test/dummy/db/migrate/20151106165522_add_category.rb +10 -0
  71. data/test/dummy/db/schema.rb +31 -0
  72. data/test/dummy/db/test.sqlite3 +0 -0
  73. data/test/dummy/log/development.log +0 -0
  74. data/test/dummy/log/test.log +1997 -0
  75. data/test/dummy/public/404.html +67 -0
  76. data/test/dummy/public/422.html +67 -0
  77. data/test/dummy/public/500.html +66 -0
  78. data/test/dummy/public/favicon.ico +0 -0
  79. data/test/dummy/test/fixtures/things.yml +8 -0
  80. data/test/javascripts/arrayed_field_spec.js +101 -0
  81. data/test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js +32 -0
  82. data/test/javascripts/helpers/jasmine-jquery.js +838 -0
  83. data/test/javascripts/scheduler_spec.js +354 -0
  84. data/test/javascripts/select_or_new_spec.js +113 -0
  85. data/test/javascripts/support/jasmine.yml +127 -0
  86. data/test/javascripts/support/jasmine_helper.rb +19 -0
  87. data/test/javascripts/time_picker_spec.js +42 -0
  88. data/test/javascripts/timespan_spec.js +81 -0
  89. data/test/javascripts/vendor/bootstrap.min.js +7 -0
  90. data/test/javascripts/vendor/jquery-2.1.4.min.js +4 -0
  91. data/test/scheduler_serializer_test.rb +200 -0
  92. data/test/scheduler_test.rb +15 -0
  93. data/test/select_or_new_test.rb +37 -0
  94. data/test/submit_bar_test.rb +112 -0
  95. data/test/test_helper.rb +37 -0
  96. data/test/timespan_test.rb +47 -0
  97. metadata +291 -0
@@ -0,0 +1,354 @@
1
+ describe("Scheduler", function() {
2
+
3
+ describe("Plugin", function() {
4
+
5
+ it("should be defined on jQuery object", function() {
6
+ expect($(document.body).scheduler).not.toThrow()
7
+ })
8
+
9
+ })
10
+
11
+ describe("Run tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode", function() {
12
+
13
+ beforeEach(function() {
14
+ $.fn.bootstrapScheduler = $.fn.scheduler.noConflict()
15
+ })
16
+
17
+ afterEach(function() {
18
+ $.fn.scheduler = $.fn.bootstrapScheduler
19
+ delete $.fn.bootstrapScheduler
20
+ })
21
+
22
+ describe("initialization", function() {
23
+
24
+ it("should provide no conflict - scheduler was set back to undefined (orig value)", function() {
25
+ expect($.fn.scheduler).toBeUndefined()
26
+ })
27
+
28
+ it("should return jquery collection containing the element", function() {
29
+ var $el = $('<div/>')
30
+ var $scheduler = $el.bootstrapScheduler()
31
+ expect($scheduler).toEqual(jasmine.any($))
32
+ expect($scheduler[0]).toBe($el[0])
33
+ })
34
+
35
+ })
36
+
37
+ describe("behaviour", function() {
38
+
39
+ var $element
40
+ var fixture = function() {
41
+ return '<div class="form-group" data-scheduler="true">'
42
+ +' <label class="control-label col-sm-2" for="thing_schedule">Schedule</label>'
43
+ +' <div class="col-sm-10">'
44
+ +' <input class="scheduler-hidden-field" id="thing_schedule" name="thing[schedule]" type="hidden" value="[[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]]">'
45
+ +' <table class="scheduler-badge">'
46
+ +' <tbody>'
47
+ +' <tr>'
48
+ +' <td class="off" data-day="0" data-hour="0">&nbsp;</td>'
49
+ +' <td class="on" data-day="0" data-hour="1">&nbsp;</td>'
50
+ +' <td class="on" data-day="0" data-hour="2">&nbsp;</td>'
51
+ +' <td class="on" data-day="0" data-hour="3">&nbsp;</td>'
52
+ +' <td class="on" data-day="0" data-hour="4">&nbsp;</td>'
53
+ +' <td class="on" data-day="0" data-hour="5">&nbsp;</td>'
54
+ +' <td class="on" data-day="0" data-hour="6">&nbsp;</td>'
55
+ +' <td class="on" data-day="0" data-hour="7">&nbsp;</td>'
56
+ +' <td class="on" data-day="0" data-hour="8">&nbsp;</td>'
57
+ +' <td class="on" data-day="0" data-hour="9">&nbsp;</td>'
58
+ +' <td class="on" data-day="0" data-hour="10">&nbsp;</td>'
59
+ +' <td class="on" data-day="0" data-hour="11">&nbsp;</td>'
60
+ +' <td class="on" data-day="0" data-hour="12">&nbsp;</td>'
61
+ +' <td class="on" data-day="0" data-hour="13">&nbsp;</td>'
62
+ +' <td class="on" data-day="0" data-hour="14">&nbsp;</td>'
63
+ +' <td class="on" data-day="0" data-hour="15">&nbsp;</td>'
64
+ +' <td class="on" data-day="0" data-hour="16">&nbsp;</td>'
65
+ +' <td class="on" data-day="0" data-hour="17">&nbsp;</td>'
66
+ +' <td class="on" data-day="0" data-hour="18">&nbsp;</td>'
67
+ +' <td class="on" data-day="0" data-hour="19">&nbsp;</td>'
68
+ +' <td class="on" data-day="0" data-hour="20">&nbsp;</td>'
69
+ +' <td class="on" data-day="0" data-hour="21">&nbsp;</td>'
70
+ +' <td class="on" data-day="0" data-hour="22">&nbsp;</td>'
71
+ +' <td class="on" data-day="0" data-hour="23">&nbsp;</td>'
72
+ +' </tr>'
73
+ +' <tr>'
74
+ +' <td class="off" data-day="1" data-hour="0">&nbsp;</td>'
75
+ +' <td class="on" data-day="1" data-hour="1">&nbsp;</td>'
76
+ +' <td class="on" data-day="1" data-hour="2">&nbsp;</td>'
77
+ +' <td class="on" data-day="1" data-hour="3">&nbsp;</td>'
78
+ +' <td class="on" data-day="1" data-hour="4">&nbsp;</td>'
79
+ +' <td class="on" data-day="1" data-hour="5">&nbsp;</td>'
80
+ +' <td class="on" data-day="1" data-hour="6">&nbsp;</td>'
81
+ +' <td class="on" data-day="1" data-hour="7">&nbsp;</td>'
82
+ +' <td class="on" data-day="1" data-hour="8">&nbsp;</td>'
83
+ +' <td class="on" data-day="1" data-hour="9">&nbsp;</td>'
84
+ +' <td class="on" data-day="1" data-hour="10">&nbsp;</td>'
85
+ +' <td class="on" data-day="1" data-hour="11">&nbsp;</td>'
86
+ +' <td class="on" data-day="1" data-hour="12">&nbsp;</td>'
87
+ +' <td class="on" data-day="1" data-hour="13">&nbsp;</td>'
88
+ +' <td class="on" data-day="1" data-hour="14">&nbsp;</td>'
89
+ +' <td class="on" data-day="1" data-hour="15">&nbsp;</td>'
90
+ +' <td class="on" data-day="1" data-hour="16">&nbsp;</td>'
91
+ +' <td class="on" data-day="1" data-hour="17">&nbsp;</td>'
92
+ +' <td class="on" data-day="1" data-hour="18">&nbsp;</td>'
93
+ +' <td class="on" data-day="1" data-hour="19">&nbsp;</td>'
94
+ +' <td class="on" data-day="1" data-hour="20">&nbsp;</td>'
95
+ +' <td class="on" data-day="1" data-hour="21">&nbsp;</td>'
96
+ +' <td class="on" data-day="1" data-hour="22">&nbsp;</td>'
97
+ +' <td class="on" data-day="1" data-hour="23">&nbsp;</td>'
98
+ +' </tr>'
99
+ +' <tr>'
100
+ +' <td class="off" data-day="2" data-hour="0">&nbsp;</td>'
101
+ +' <td class="on" data-day="2" data-hour="1">&nbsp;</td>'
102
+ +' <td class="on" data-day="2" data-hour="2">&nbsp;</td>'
103
+ +' <td class="on" data-day="2" data-hour="3">&nbsp;</td>'
104
+ +' <td class="on" data-day="2" data-hour="4">&nbsp;</td>'
105
+ +' <td class="on" data-day="2" data-hour="5">&nbsp;</td>'
106
+ +' <td class="on" data-day="2" data-hour="6">&nbsp;</td>'
107
+ +' <td class="on" data-day="2" data-hour="7">&nbsp;</td>'
108
+ +' <td class="on" data-day="2" data-hour="8">&nbsp;</td>'
109
+ +' <td class="on" data-day="2" data-hour="9">&nbsp;</td>'
110
+ +' <td class="on" data-day="2" data-hour="10">&nbsp;</td>'
111
+ +' <td class="on" data-day="2" data-hour="11">&nbsp;</td>'
112
+ +' <td class="on" data-day="2" data-hour="12">&nbsp;</td>'
113
+ +' <td class="on" data-day="2" data-hour="13">&nbsp;</td>'
114
+ +' <td class="on" data-day="2" data-hour="14">&nbsp;</td>'
115
+ +' <td class="on" data-day="2" data-hour="15">&nbsp;</td>'
116
+ +' <td class="on" data-day="2" data-hour="16">&nbsp;</td>'
117
+ +' <td class="on" data-day="2" data-hour="17">&nbsp;</td>'
118
+ +' <td class="on" data-day="2" data-hour="18">&nbsp;</td>'
119
+ +' <td class="on" data-day="2" data-hour="19">&nbsp;</td>'
120
+ +' <td class="on" data-day="2" data-hour="20">&nbsp;</td>'
121
+ +' <td class="on" data-day="2" data-hour="21">&nbsp;</td>'
122
+ +' <td class="on" data-day="2" data-hour="22">&nbsp;</td>'
123
+ +' <td class="on" data-day="2" data-hour="23">&nbsp;</td>'
124
+ +' </tr>'
125
+ +' <tr>'
126
+ +' <td class="off" data-day="3" data-hour="0">&nbsp;</td>'
127
+ +' <td class="on" data-day="3" data-hour="1">&nbsp;</td>'
128
+ +' <td class="on" data-day="3" data-hour="2">&nbsp;</td>'
129
+ +' <td class="on" data-day="3" data-hour="3">&nbsp;</td>'
130
+ +' <td class="on" data-day="3" data-hour="4">&nbsp;</td>'
131
+ +' <td class="on" data-day="3" data-hour="5">&nbsp;</td>'
132
+ +' <td class="on" data-day="3" data-hour="6">&nbsp;</td>'
133
+ +' <td class="on" data-day="3" data-hour="7">&nbsp;</td>'
134
+ +' <td class="on" data-day="3" data-hour="8">&nbsp;</td>'
135
+ +' <td class="on" data-day="3" data-hour="9">&nbsp;</td>'
136
+ +' <td class="on" data-day="3" data-hour="10">&nbsp;</td>'
137
+ +' <td class="on" data-day="3" data-hour="11">&nbsp;</td>'
138
+ +' <td class="on" data-day="3" data-hour="12">&nbsp;</td>'
139
+ +' <td class="on" data-day="3" data-hour="13">&nbsp;</td>'
140
+ +' <td class="on" data-day="3" data-hour="14">&nbsp;</td>'
141
+ +' <td class="on" data-day="3" data-hour="15">&nbsp;</td>'
142
+ +' <td class="on" data-day="3" data-hour="16">&nbsp;</td>'
143
+ +' <td class="on" data-day="3" data-hour="17">&nbsp;</td>'
144
+ +' <td class="on" data-day="3" data-hour="18">&nbsp;</td>'
145
+ +' <td class="on" data-day="3" data-hour="19">&nbsp;</td>'
146
+ +' <td class="on" data-day="3" data-hour="20">&nbsp;</td>'
147
+ +' <td class="on" data-day="3" data-hour="21">&nbsp;</td>'
148
+ +' <td class="on" data-day="3" data-hour="22">&nbsp;</td>'
149
+ +' <td class="on" data-day="3" data-hour="23">&nbsp;</td>'
150
+ +' </tr>'
151
+ +' <tr>'
152
+ +' <td class="off" data-day="4" data-hour="0">&nbsp;</td>'
153
+ +' <td class="on" data-day="4" data-hour="1">&nbsp;</td>'
154
+ +' <td class="on" data-day="4" data-hour="2">&nbsp;</td>'
155
+ +' <td class="on" data-day="4" data-hour="3">&nbsp;</td>'
156
+ +' <td class="on" data-day="4" data-hour="4">&nbsp;</td>'
157
+ +' <td class="on" data-day="4" data-hour="5">&nbsp;</td>'
158
+ +' <td class="on" data-day="4" data-hour="6">&nbsp;</td>'
159
+ +' <td class="on" data-day="4" data-hour="7">&nbsp;</td>'
160
+ +' <td class="on" data-day="4" data-hour="8">&nbsp;</td>'
161
+ +' <td class="on" data-day="4" data-hour="9">&nbsp;</td>'
162
+ +' <td class="on" data-day="4" data-hour="10">&nbsp;</td>'
163
+ +' <td class="on" data-day="4" data-hour="11">&nbsp;</td>'
164
+ +' <td class="on" data-day="4" data-hour="12">&nbsp;</td>'
165
+ +' <td class="on" data-day="4" data-hour="13">&nbsp;</td>'
166
+ +' <td class="on" data-day="4" data-hour="14">&nbsp;</td>'
167
+ +' <td class="on" data-day="4" data-hour="15">&nbsp;</td>'
168
+ +' <td class="on" data-day="4" data-hour="16">&nbsp;</td>'
169
+ +' <td class="on" data-day="4" data-hour="17">&nbsp;</td>'
170
+ +' <td class="on" data-day="4" data-hour="18">&nbsp;</td>'
171
+ +' <td class="on" data-day="4" data-hour="19">&nbsp;</td>'
172
+ +' <td class="on" data-day="4" data-hour="20">&nbsp;</td>'
173
+ +' <td class="on" data-day="4" data-hour="21">&nbsp;</td>'
174
+ +' <td class="on" data-day="4" data-hour="22">&nbsp;</td>'
175
+ +' <td class="on" data-day="4" data-hour="23">&nbsp;</td>'
176
+ +' </tr>'
177
+ +' <tr>'
178
+ +' <td class="off" data-day="5" data-hour="0">&nbsp;</td>'
179
+ +' <td class="on" data-day="5" data-hour="1">&nbsp;</td>'
180
+ +' <td class="on" data-day="5" data-hour="2">&nbsp;</td>'
181
+ +' <td class="on" data-day="5" data-hour="3">&nbsp;</td>'
182
+ +' <td class="on" data-day="5" data-hour="4">&nbsp;</td>'
183
+ +' <td class="on" data-day="5" data-hour="5">&nbsp;</td>'
184
+ +' <td class="on" data-day="5" data-hour="6">&nbsp;</td>'
185
+ +' <td class="on" data-day="5" data-hour="7">&nbsp;</td>'
186
+ +' <td class="on" data-day="5" data-hour="8">&nbsp;</td>'
187
+ +' <td class="on" data-day="5" data-hour="9">&nbsp;</td>'
188
+ +' <td class="on" data-day="5" data-hour="10">&nbsp;</td>'
189
+ +' <td class="on" data-day="5" data-hour="11">&nbsp;</td>'
190
+ +' <td class="on" data-day="5" data-hour="12">&nbsp;</td>'
191
+ +' <td class="on" data-day="5" data-hour="13">&nbsp;</td>'
192
+ +' <td class="on" data-day="5" data-hour="14">&nbsp;</td>'
193
+ +' <td class="on" data-day="5" data-hour="15">&nbsp;</td>'
194
+ +' <td class="on" data-day="5" data-hour="16">&nbsp;</td>'
195
+ +' <td class="on" data-day="5" data-hour="17">&nbsp;</td>'
196
+ +' <td class="on" data-day="5" data-hour="18">&nbsp;</td>'
197
+ +' <td class="on" data-day="5" data-hour="19">&nbsp;</td>'
198
+ +' <td class="on" data-day="5" data-hour="20">&nbsp;</td>'
199
+ +' <td class="on" data-day="5" data-hour="21">&nbsp;</td>'
200
+ +' <td class="on" data-day="5" data-hour="22">&nbsp;</td>'
201
+ +' <td class="on" data-day="5" data-hour="23">&nbsp;</td>'
202
+ +' </tr>'
203
+ +' <tr>'
204
+ +' <td class="off" data-day="6" data-hour="0">&nbsp;</td>'
205
+ +' <td class="on" data-day="6" data-hour="1">&nbsp;</td>'
206
+ +' <td class="on" data-day="6" data-hour="2">&nbsp;</td>'
207
+ +' <td class="on" data-day="6" data-hour="3">&nbsp;</td>'
208
+ +' <td class="on" data-day="6" data-hour="4">&nbsp;</td>'
209
+ +' <td class="on" data-day="6" data-hour="5">&nbsp;</td>'
210
+ +' <td class="on" data-day="6" data-hour="6">&nbsp;</td>'
211
+ +' <td class="on" data-day="6" data-hour="7">&nbsp;</td>'
212
+ +' <td class="on" data-day="6" data-hour="8">&nbsp;</td>'
213
+ +' <td class="on" data-day="6" data-hour="9">&nbsp;</td>'
214
+ +' <td class="on" data-day="6" data-hour="10">&nbsp;</td>'
215
+ +' <td class="on" data-day="6" data-hour="11">&nbsp;</td>'
216
+ +' <td class="on" data-day="6" data-hour="12">&nbsp;</td>'
217
+ +' <td class="on" data-day="6" data-hour="13">&nbsp;</td>'
218
+ +' <td class="on" data-day="6" data-hour="14">&nbsp;</td>'
219
+ +' <td class="on" data-day="6" data-hour="15">&nbsp;</td>'
220
+ +' <td class="on" data-day="6" data-hour="16">&nbsp;</td>'
221
+ +' <td class="on" data-day="6" data-hour="17">&nbsp;</td>'
222
+ +' <td class="on" data-day="6" data-hour="18">&nbsp;</td>'
223
+ +' <td class="on" data-day="6" data-hour="19">&nbsp;</td>'
224
+ +' <td class="on" data-day="6" data-hour="20">&nbsp;</td>'
225
+ +' <td class="on" data-day="6" data-hour="21">&nbsp;</td>'
226
+ +' <td class="on" data-day="6" data-hour="22">&nbsp;</td>'
227
+ +' <td class="on" data-day="6" data-hour="23">&nbsp;</td>'
228
+ +' </tr>'
229
+ +' </tbody>'
230
+ +' </table>'
231
+ +' </div>'
232
+ +'</div>'
233
+ }
234
+
235
+ beforeEach(function() {
236
+ $element = $(fixture())
237
+ $element.bootstrapScheduler()
238
+ $element.find('table.scheduler-badge').click()
239
+ })
240
+
241
+ describe("return values in the hidden field", function() {
242
+
243
+ it("apply no changes", function() {
244
+ var values
245
+ $('#scheduler-container button.apply').click()
246
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
247
+ expect(values).toEqual([[false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]])
248
+ })
249
+
250
+ it("cancel changes", function() {
251
+ var values
252
+ $('#scheduler-container a.none').click()
253
+ $('#scheduler-container button.cancel').click()
254
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
255
+ expect(values).toEqual([[false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]])
256
+ })
257
+
258
+ it("select all", function() {
259
+ var values
260
+ $('#scheduler-container a.all').click()
261
+ $('#scheduler-container button.apply').click()
262
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
263
+ expect(values).toEqual([[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]])
264
+ })
265
+
266
+ it("select none", function() {
267
+ var values
268
+ $('#scheduler-container a.none').click()
269
+ $('#scheduler-container button.apply').click()
270
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
271
+ expect(values).toEqual([[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]])
272
+ })
273
+
274
+ it("unselect a full day", function() {
275
+ var values
276
+ $('#scheduler-container a.day-header:first').click()
277
+ $('#scheduler-container button.apply').click()
278
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
279
+ expect(values).toEqual([[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]])
280
+ })
281
+
282
+ it("unselect a full hour", function() {
283
+ var values
284
+ $('#scheduler-container a.hour-header:last').click()
285
+ $('#scheduler-container button.apply').click()
286
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
287
+ expect(values).toEqual([[false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false]])
288
+ })
289
+
290
+ it("unselect one hour", function() {
291
+ var values
292
+ $('#scheduler-container td[data-day="0"][data-hour="0"]').click()
293
+ $('#scheduler-container button.apply').click()
294
+ values = JSON.parse($element.find('.scheduler-hidden-field').val())
295
+ expect(values).toEqual([[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]])
296
+ })
297
+
298
+ })
299
+
300
+ describe("update badge", function() {
301
+
302
+ it("apply no changes", function() {
303
+ var html
304
+ html = $element.find('table.scheduler-badge').html()
305
+ $('#scheduler-container button.apply').click()
306
+ expect($element.find('table.scheduler-badge').html()).toEqual(html)
307
+ })
308
+
309
+ it("cancel changes", function() {
310
+ var html
311
+ html = $element.find('table.scheduler-badge').html()
312
+ $('#scheduler-container a.none').click()
313
+ $('#scheduler-container button.cancel').click()
314
+ expect($element.find('table.scheduler-badge').html()).toEqual(html)
315
+ })
316
+
317
+ it("select all", function() {
318
+ $('#scheduler-container a.all').click()
319
+ $('#scheduler-container button.apply').click()
320
+ expect($element.find('table.scheduler-badge').html()).not.toContain('off')
321
+ })
322
+
323
+ it("select none", function() {
324
+ $('#scheduler-container a.none').click()
325
+ $('#scheduler-container button.apply').click()
326
+ expect($element.find('table.scheduler-badge').html()).not.toContain('on')
327
+ })
328
+
329
+ it("unselect a full day", function() {
330
+ var values
331
+ $('#scheduler-container a.day-header:first').click()
332
+ $('#scheduler-container button.apply').click()
333
+ expect($element.find('table.scheduler-badge tr:first').html()).not.toContain('on')
334
+ })
335
+
336
+ it("unselect a full hour", function() {
337
+ $('#scheduler-container a.hour-header:last').click()
338
+ $('#scheduler-container button.apply').click()
339
+ expect($element.find('table.scheduler-badge tr td:last-child.on')).not.toExist()
340
+ })
341
+
342
+ it("unselect one hour", function() {
343
+ $('#scheduler-container td[data-day="0"][data-hour="0"]').click()
344
+ $('#scheduler-container button.apply').click()
345
+ expect($element.find('table.scheduler-badge td[data-day="0"][data-hour="0"]')).toHaveClass('on')
346
+ })
347
+
348
+ })
349
+
350
+ })
351
+
352
+ })
353
+
354
+ })
@@ -0,0 +1,113 @@
1
+ describe("SelectOrNew", function() {
2
+
3
+ describe("Plugin", function() {
4
+
5
+ it("should be defined on jQuery object", function() {
6
+ expect($(document.body).selectOrNew).not.toThrow()
7
+ })
8
+
9
+ })
10
+
11
+ describe("Run tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode", function() {
12
+
13
+ beforeEach(function() {
14
+ $.fn.bootstrapSelectOrNew = $.fn.selectOrNew.noConflict()
15
+ })
16
+
17
+ afterEach(function() {
18
+ $.fn.selectOrNew = $.fn.bootstrapSelectOrNew
19
+ delete $.fn.bootstrapSelectOrNew
20
+ })
21
+
22
+ describe("initialization", function() {
23
+
24
+ it("should provide no conflict - selectOrNew was set back to undefined (orig value)", function() {
25
+ expect($.fn.selectOrNew).toBeUndefined()
26
+ })
27
+
28
+ it("should return jquery collection containing the element", function() {
29
+ var $el = $('<div/>')
30
+ var $selectOrNew = $el.bootstrapSelectOrNew()
31
+ expect($selectOrNew).toEqual(jasmine.any($))
32
+ expect($selectOrNew[0]).toBe($el[0])
33
+ })
34
+
35
+ })
36
+
37
+ describe("behaviour", function() {
38
+
39
+ var $element, $select, $input, $inputGroup
40
+ var fixture = function() {
41
+ return '<div class="form-group" data-select-or-new="true">'
42
+ +' <label class="control-label col-sm-2" for="thing_category">Category</label>'
43
+ +' <div class="col-sm-10">'
44
+ +' <select class="form-control" id="thing_category" name="thing[category]">'
45
+ +' <option value="">Please select</option>'
46
+ +' <option value="1">One</option>'
47
+ +' <option value="2">Two</option>'
48
+ +' <option value="0">New...</option>'
49
+ +' </select>'
50
+ +' <div class="input-group" style="display: none;">'
51
+ +' <input class="form-control" id="thing_new_category" name="thing[new_category]" placeholder="New..." type="text">'
52
+ +' <div class="input-group-addon select-or-new-cancel">'
53
+ +' <i class="text-danger glyphicon glyphicon-remove"></i>'
54
+ +' </div>'
55
+ +' </div>'
56
+ +' </div>'
57
+ +'</div>'
58
+ }
59
+
60
+ beforeEach(function() {
61
+ $element = $(fixture())
62
+ $element.appendTo('body')
63
+
64
+ $select = $element.find('select')
65
+ $input = $element.find('input')
66
+ $inputGroup = $element.find('div.input-group')
67
+ $cancelNew = $element.find('div.select-or-new-cancel')
68
+
69
+ $element.bootstrapSelectOrNew()
70
+ })
71
+
72
+ afterEach(function() {
73
+ $element.remove()
74
+ })
75
+
76
+ it("should show the input tag when 'New...' is selected", function() {
77
+ expect($select).toBeVisible()
78
+ expect($inputGroup).not.toBeVisible()
79
+ $select.val('0').trigger('change')
80
+ expect($select).not.toBeVisible()
81
+ expect($inputGroup).toBeVisible()
82
+ })
83
+
84
+ it("should focus on the input tag when 'New...' is selected", function() {
85
+ $select.val('0').trigger('change')
86
+ expect($input).toBeFocused()
87
+ })
88
+
89
+ it("should show the select tag when new is cancelled", function() {
90
+ $select.val('0').trigger('change')
91
+ $cancelNew.click()
92
+ expect($select).toBeVisible()
93
+ expect($inputGroup).not.toBeVisible()
94
+ })
95
+
96
+ it("should focus on the select tag when new is cancelled", function() {
97
+ $select.val('0').trigger('change')
98
+ $cancelNew.click()
99
+ expect($select).toBeFocused()
100
+ })
101
+
102
+ it("should empty the input value when new is cancelled", function() {
103
+ $select.val('0').trigger('change')
104
+ $input.val('New Category')
105
+ $cancelNew.click()
106
+ expect($input).toHaveValue('')
107
+ })
108
+
109
+ })
110
+
111
+ })
112
+
113
+ })