bootstrap_form_extensions 1.0.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/bootstrap_form_extensions/arrayed_field.js +70 -0
- data/app/assets/javascripts/bootstrap_form_extensions/bootstrap-timepicker.min.js +5 -0
- data/app/assets/javascripts/bootstrap_form_extensions/index.js +2 -0
- data/app/assets/javascripts/bootstrap_form_extensions/jquery.html5data.min.js +7 -0
- data/app/assets/javascripts/bootstrap_form_extensions/scheduler.js +226 -0
- data/app/assets/javascripts/bootstrap_form_extensions/select_or_new.js +76 -0
- data/app/assets/javascripts/bootstrap_form_extensions/time_picker.js +61 -0
- data/app/assets/javascripts/bootstrap_form_extensions/timespan.js +60 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/bootstrap-timepicker.min.css +10 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/common.css +11 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/index.css +4 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/scheduler.css +31 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/submit_bar.css +4 -0
- data/app/views/bootstrap_form_extensions/_submit_bar.html.erb +36 -0
- data/lib/bootstrap_form_extensions.rb +22 -0
- data/lib/bootstrap_form_extensions/arrayed_field.rb +107 -0
- data/lib/bootstrap_form_extensions/date_time_pickers.rb +71 -0
- data/lib/bootstrap_form_extensions/helpers.rb +18 -0
- data/lib/bootstrap_form_extensions/scheduler.rb +72 -0
- data/lib/bootstrap_form_extensions/select_or_new.rb +36 -0
- data/lib/bootstrap_form_extensions/submit_bar.rb +65 -0
- data/lib/bootstrap_form_extensions/timespan.rb +55 -0
- data/lib/bootstrap_form_extensions/version.rb +3 -0
- data/lib/tasks/rails_bootstrap_form_extensions_tasks.rake +4 -0
- data/test/arrayed_field_test.rb +63 -0
- data/test/bootstrap_form_extensions_test.rb +7 -0
- data/test/date_time_pickers_test.rb +50 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/category.rb +7 -0
- data/test/dummy/app/models/thing.rb +46 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20150918185031_create_things.rb +9 -0
- data/test/dummy/db/migrate/20150924203053_add_timespan.rb +7 -0
- data/test/dummy/db/migrate/20150929213249_add_arrayed_field.rb +7 -0
- data/test/dummy/db/migrate/20151006171627_add_another_arrayed_field.rb +7 -0
- data/test/dummy/db/migrate/20151006181943_add_json_field.rb +7 -0
- data/test/dummy/db/migrate/20151007213131_add_scheduler_field.rb +7 -0
- data/test/dummy/db/migrate/20151030194330_add_date_time.rb +7 -0
- data/test/dummy/db/migrate/20151106165522_add_category.rb +10 -0
- data/test/dummy/db/schema.rb +31 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +1997 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/things.yml +8 -0
- data/test/javascripts/arrayed_field_spec.js +101 -0
- data/test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js +32 -0
- data/test/javascripts/helpers/jasmine-jquery.js +838 -0
- data/test/javascripts/scheduler_spec.js +354 -0
- data/test/javascripts/select_or_new_spec.js +113 -0
- data/test/javascripts/support/jasmine.yml +127 -0
- data/test/javascripts/support/jasmine_helper.rb +19 -0
- data/test/javascripts/time_picker_spec.js +42 -0
- data/test/javascripts/timespan_spec.js +81 -0
- data/test/javascripts/vendor/bootstrap.min.js +7 -0
- data/test/javascripts/vendor/jquery-2.1.4.min.js +4 -0
- data/test/scheduler_serializer_test.rb +200 -0
- data/test/scheduler_test.rb +15 -0
- data/test/select_or_new_test.rb +37 -0
- data/test/submit_bar_test.rb +112 -0
- data/test/test_helper.rb +37 -0
- data/test/timespan_test.rb +47 -0
- metadata +291 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
background-color: #EFEFEF;
|
|
9
|
+
color: #2E2F30;
|
|
10
|
+
text-align: center;
|
|
11
|
+
font-family: arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
div.dialog {
|
|
16
|
+
width: 95%;
|
|
17
|
+
max-width: 33em;
|
|
18
|
+
margin: 4em auto 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
div.dialog > div {
|
|
22
|
+
border: 1px solid #CCC;
|
|
23
|
+
border-right-color: #999;
|
|
24
|
+
border-left-color: #999;
|
|
25
|
+
border-bottom-color: #BBB;
|
|
26
|
+
border-top: #B00100 solid 4px;
|
|
27
|
+
border-top-left-radius: 9px;
|
|
28
|
+
border-top-right-radius: 9px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 7px 12% 0;
|
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
h1 {
|
|
35
|
+
font-size: 100%;
|
|
36
|
+
color: #730E15;
|
|
37
|
+
line-height: 1.5em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
div.dialog > p {
|
|
41
|
+
margin: 0 0 1em;
|
|
42
|
+
padding: 1em;
|
|
43
|
+
background-color: #F7F7F7;
|
|
44
|
+
border: 1px solid #CCC;
|
|
45
|
+
border-right-color: #999;
|
|
46
|
+
border-left-color: #999;
|
|
47
|
+
border-bottom-color: #999;
|
|
48
|
+
border-bottom-left-radius: 4px;
|
|
49
|
+
border-bottom-right-radius: 4px;
|
|
50
|
+
border-top-color: #DADADA;
|
|
51
|
+
color: #666;
|
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
|
|
57
|
+
<body>
|
|
58
|
+
<!-- This file lives in public/404.html -->
|
|
59
|
+
<div class="dialog">
|
|
60
|
+
<div>
|
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
|
63
|
+
</div>
|
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
65
|
+
</div>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
background-color: #EFEFEF;
|
|
9
|
+
color: #2E2F30;
|
|
10
|
+
text-align: center;
|
|
11
|
+
font-family: arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
div.dialog {
|
|
16
|
+
width: 95%;
|
|
17
|
+
max-width: 33em;
|
|
18
|
+
margin: 4em auto 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
div.dialog > div {
|
|
22
|
+
border: 1px solid #CCC;
|
|
23
|
+
border-right-color: #999;
|
|
24
|
+
border-left-color: #999;
|
|
25
|
+
border-bottom-color: #BBB;
|
|
26
|
+
border-top: #B00100 solid 4px;
|
|
27
|
+
border-top-left-radius: 9px;
|
|
28
|
+
border-top-right-radius: 9px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 7px 12% 0;
|
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
h1 {
|
|
35
|
+
font-size: 100%;
|
|
36
|
+
color: #730E15;
|
|
37
|
+
line-height: 1.5em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
div.dialog > p {
|
|
41
|
+
margin: 0 0 1em;
|
|
42
|
+
padding: 1em;
|
|
43
|
+
background-color: #F7F7F7;
|
|
44
|
+
border: 1px solid #CCC;
|
|
45
|
+
border-right-color: #999;
|
|
46
|
+
border-left-color: #999;
|
|
47
|
+
border-bottom-color: #999;
|
|
48
|
+
border-bottom-left-radius: 4px;
|
|
49
|
+
border-bottom-right-radius: 4px;
|
|
50
|
+
border-top-color: #DADADA;
|
|
51
|
+
color: #666;
|
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
|
|
57
|
+
<body>
|
|
58
|
+
<!-- This file lives in public/422.html -->
|
|
59
|
+
<div class="dialog">
|
|
60
|
+
<div>
|
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
63
|
+
</div>
|
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
65
|
+
</div>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
background-color: #EFEFEF;
|
|
9
|
+
color: #2E2F30;
|
|
10
|
+
text-align: center;
|
|
11
|
+
font-family: arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
div.dialog {
|
|
16
|
+
width: 95%;
|
|
17
|
+
max-width: 33em;
|
|
18
|
+
margin: 4em auto 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
div.dialog > div {
|
|
22
|
+
border: 1px solid #CCC;
|
|
23
|
+
border-right-color: #999;
|
|
24
|
+
border-left-color: #999;
|
|
25
|
+
border-bottom-color: #BBB;
|
|
26
|
+
border-top: #B00100 solid 4px;
|
|
27
|
+
border-top-left-radius: 9px;
|
|
28
|
+
border-top-right-radius: 9px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 7px 12% 0;
|
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
h1 {
|
|
35
|
+
font-size: 100%;
|
|
36
|
+
color: #730E15;
|
|
37
|
+
line-height: 1.5em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
div.dialog > p {
|
|
41
|
+
margin: 0 0 1em;
|
|
42
|
+
padding: 1em;
|
|
43
|
+
background-color: #F7F7F7;
|
|
44
|
+
border: 1px solid #CCC;
|
|
45
|
+
border-right-color: #999;
|
|
46
|
+
border-left-color: #999;
|
|
47
|
+
border-bottom-color: #999;
|
|
48
|
+
border-bottom-left-radius: 4px;
|
|
49
|
+
border-bottom-right-radius: 4px;
|
|
50
|
+
border-top-color: #DADADA;
|
|
51
|
+
color: #666;
|
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
|
|
57
|
+
<body>
|
|
58
|
+
<!-- This file lives in public/500.html -->
|
|
59
|
+
<div class="dialog">
|
|
60
|
+
<div>
|
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
62
|
+
</div>
|
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
64
|
+
</div>
|
|
65
|
+
</body>
|
|
66
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
describe("ArrayedField", function() {
|
|
2
|
+
|
|
3
|
+
describe("Plugin", function() {
|
|
4
|
+
|
|
5
|
+
it("should be defined on jQuery object", function() {
|
|
6
|
+
expect($(document.body).arrayedfield).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.bootstrapArrayedField = $.fn.arrayedfield.noConflict()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
afterEach(function() {
|
|
18
|
+
$.fn.arrayedfield = $.fn.bootstrapArrayedField
|
|
19
|
+
delete $.fn.bootstrapArrayedField
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe("initialization", function() {
|
|
23
|
+
|
|
24
|
+
it("should provide no conflict - arrayedfield was set back to undefined (orig value)", function() {
|
|
25
|
+
expect($.fn.arrayedfield).toBeUndefined()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("should return jquery collection containing the element", function() {
|
|
29
|
+
var $el = $('<div/>')
|
|
30
|
+
var $arrayedfield = $el.bootstrapArrayedField()
|
|
31
|
+
expect($arrayedfield).toEqual(jasmine.any($))
|
|
32
|
+
expect($arrayedfield[0]).toBe($el[0])
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe("behaviour", function() {
|
|
38
|
+
|
|
39
|
+
var $element
|
|
40
|
+
var fixture = function() {
|
|
41
|
+
return '<div data-arrayed-field="true">'
|
|
42
|
+
+' <div class="blueprint-for-arrayed-field" style="display:none;">'
|
|
43
|
+
+' <div class="row voffset1">'
|
|
44
|
+
+' <div class="col-sm-11">'
|
|
45
|
+
+' <input type="url" id="" class="form-control" data-name="thing[urls][]" />'
|
|
46
|
+
+' </div>'
|
|
47
|
+
+' <div class="col-sm-1">'
|
|
48
|
+
+' <a class="btn btn-default remove-arrayed-field-row" href="javascript:void(0);"><i class="glyphicon glyphicon-trash"></i></a>'
|
|
49
|
+
+' </div>'
|
|
50
|
+
+' </div>'
|
|
51
|
+
+' </div>'
|
|
52
|
+
+' <div class="arrayed-field-rows">'
|
|
53
|
+
+' <div class="row voffset1">'
|
|
54
|
+
+' <div class="col-sm-11">'
|
|
55
|
+
+' <input type="url" id="" class="form-control" name="thing[urls][]" />'
|
|
56
|
+
+' </div>'
|
|
57
|
+
+' <div class="col-sm-1">'
|
|
58
|
+
+' <a class="btn btn-default remove-arrayed-field-row" href="javascript:void(0);"><i class="glyphicon glyphicon-trash"></i></a>'
|
|
59
|
+
+' </div>'
|
|
60
|
+
+' </div>'
|
|
61
|
+
+' <div class="row voffset1">'
|
|
62
|
+
+' <div class="col-sm-11">'
|
|
63
|
+
+' <input type="url" id="" class="form-control" name="thing[urls][]" />'
|
|
64
|
+
+' </div>'
|
|
65
|
+
+' <div class="col-sm-1">'
|
|
66
|
+
+' <a class="btn btn-default remove-arrayed-field-row" href="javascript:void(0);"><i class="glyphicon glyphicon-trash"></i></a>'
|
|
67
|
+
+' </div>'
|
|
68
|
+
+' </div>'
|
|
69
|
+
+' </div>'
|
|
70
|
+
+' <div class="row voffset1">'
|
|
71
|
+
+' <div class="col-sm-12">'
|
|
72
|
+
+' <a class="btn btn-default add-arrayed-field-row" href="javascript:void(0);"><i class="glyphicon glyphicon-plus"></i></a>'
|
|
73
|
+
+' </div>'
|
|
74
|
+
+' </div>'
|
|
75
|
+
+'</div>'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
beforeEach(function() {
|
|
79
|
+
$element = $(fixture())
|
|
80
|
+
$element.bootstrapArrayedField()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("should add rows", function() {
|
|
84
|
+
var $add_button = $element.find('.add-arrayed-field-row')
|
|
85
|
+
expect($element.find('.arrayed-field-rows > .row')).toHaveLength(2)
|
|
86
|
+
$add_button.click()
|
|
87
|
+
expect($element.find('.arrayed-field-rows > .row')).toHaveLength(3)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it("should remove rows", function() {
|
|
91
|
+
var $remove_button = $element.find('.arrayed-field-rows .remove-arrayed-field-row:first')
|
|
92
|
+
expect($element.find('.arrayed-field-rows > .row')).toHaveLength(2)
|
|
93
|
+
$remove_button.click()
|
|
94
|
+
expect($element.find('.arrayed-field-rows > .row')).toHaveLength(1)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
if (!Function.prototype.bind) {
|
|
2
|
+
|
|
3
|
+
// PhantomJS doesn't support bind yet
|
|
4
|
+
|
|
5
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
|
|
6
|
+
Function.prototype.bind = function(oThis) {
|
|
7
|
+
if (typeof this !== 'function') {
|
|
8
|
+
// closest thing possible to the ECMAScript 5
|
|
9
|
+
// internal IsCallable function
|
|
10
|
+
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var aArgs = Array.prototype.slice.call(arguments, 1),
|
|
14
|
+
fToBind = this,
|
|
15
|
+
fNOP = function() {},
|
|
16
|
+
fBound = function() {
|
|
17
|
+
return fToBind.apply(this instanceof fNOP
|
|
18
|
+
? this
|
|
19
|
+
: oThis,
|
|
20
|
+
aArgs.concat(Array.prototype.slice.call(arguments)));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (this.prototype) {
|
|
24
|
+
// native functions don't have a prototype
|
|
25
|
+
fNOP.prototype = this.prototype;
|
|
26
|
+
}
|
|
27
|
+
fBound.prototype = new fNOP();
|
|
28
|
+
|
|
29
|
+
return fBound;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
|
|
3
|
+
|
|
4
|
+
Version 2.1.1
|
|
5
|
+
|
|
6
|
+
https://github.com/velesin/jasmine-jquery
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
11
|
+
a copy of this software and associated documentation files (the
|
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
16
|
+
the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be
|
|
19
|
+
included in all copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
22
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
(function (root, factory) {
|
|
31
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
32
|
+
factory(root, root.jasmine, require('jquery'));
|
|
33
|
+
} else {
|
|
34
|
+
factory(root, root.jasmine, root.jQuery);
|
|
35
|
+
}
|
|
36
|
+
}((function() {return this; })(), function (window, jasmine, $) { "use strict";
|
|
37
|
+
|
|
38
|
+
jasmine.spiedEventsKey = function (selector, eventName) {
|
|
39
|
+
return [$(selector).selector, eventName].toString()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
jasmine.getFixtures = function () {
|
|
43
|
+
return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
jasmine.getStyleFixtures = function () {
|
|
47
|
+
return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
jasmine.Fixtures = function () {
|
|
51
|
+
this.containerId = 'jasmine-fixtures'
|
|
52
|
+
this.fixturesCache_ = {}
|
|
53
|
+
this.fixturesPath = 'spec/javascripts/fixtures'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
jasmine.Fixtures.prototype.set = function (html) {
|
|
57
|
+
this.cleanUp()
|
|
58
|
+
return this.createContainer_(html)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
jasmine.Fixtures.prototype.appendSet= function (html) {
|
|
62
|
+
this.addToContainer_(html)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
jasmine.Fixtures.prototype.preload = function () {
|
|
66
|
+
this.read.apply(this, arguments)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
jasmine.Fixtures.prototype.load = function () {
|
|
70
|
+
this.cleanUp()
|
|
71
|
+
this.createContainer_(this.read.apply(this, arguments))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
jasmine.Fixtures.prototype.appendLoad = function () {
|
|
75
|
+
this.addToContainer_(this.read.apply(this, arguments))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
jasmine.Fixtures.prototype.read = function () {
|
|
79
|
+
var htmlChunks = []
|
|
80
|
+
, fixtureUrls = arguments
|
|
81
|
+
|
|
82
|
+
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
|
|
83
|
+
htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return htmlChunks.join('')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
jasmine.Fixtures.prototype.clearCache = function () {
|
|
90
|
+
this.fixturesCache_ = {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
jasmine.Fixtures.prototype.cleanUp = function () {
|
|
94
|
+
$('#' + this.containerId).remove()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
jasmine.Fixtures.prototype.sandbox = function (attributes) {
|
|
98
|
+
var attributesToSet = attributes || {}
|
|
99
|
+
return $('<div id="sandbox" />').attr(attributesToSet)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
jasmine.Fixtures.prototype.createContainer_ = function (html) {
|
|
103
|
+
var container = $('<div>')
|
|
104
|
+
.attr('id', this.containerId)
|
|
105
|
+
.html(html)
|
|
106
|
+
|
|
107
|
+
$(document.body).append(container)
|
|
108
|
+
return container
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
jasmine.Fixtures.prototype.addToContainer_ = function (html){
|
|
112
|
+
var container = $(document.body).find('#'+this.containerId).append(html)
|
|
113
|
+
|
|
114
|
+
if (!container.length) {
|
|
115
|
+
this.createContainer_(html)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) {
|
|
120
|
+
if (typeof this.fixturesCache_[url] === 'undefined') {
|
|
121
|
+
this.loadFixtureIntoCache_(url)
|
|
122
|
+
}
|
|
123
|
+
return this.fixturesCache_[url]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
|
|
127
|
+
var self = this
|
|
128
|
+
, url = this.makeFixtureUrl_(relativeUrl)
|
|
129
|
+
, htmlText = ''
|
|
130
|
+
, request = $.ajax({
|
|
131
|
+
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
|
132
|
+
cache: false,
|
|
133
|
+
url: url,
|
|
134
|
+
dataType: 'html',
|
|
135
|
+
success: function (data, status, $xhr) {
|
|
136
|
+
htmlText = $xhr.responseText
|
|
137
|
+
}
|
|
138
|
+
}).fail(function ($xhr, status, err) {
|
|
139
|
+
throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || [];
|
|
143
|
+
|
|
144
|
+
scripts.each(function(){
|
|
145
|
+
$.ajax({
|
|
146
|
+
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
|
147
|
+
cache: false,
|
|
148
|
+
dataType: 'script',
|
|
149
|
+
url: $(this).attr('src'),
|
|
150
|
+
success: function (data, status, $xhr) {
|
|
151
|
+
htmlText += '<script>' + $xhr.responseText + '</script>'
|
|
152
|
+
},
|
|
153
|
+
error: function ($xhr, status, err) {
|
|
154
|
+
throw new Error('Script could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
self.fixturesCache_[relativeUrl] = htmlText;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
|
|
163
|
+
return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
|
|
167
|
+
return this[methodName].apply(this, passedArguments)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
jasmine.StyleFixtures = function () {
|
|
172
|
+
this.fixturesCache_ = {}
|
|
173
|
+
this.fixturesNodes_ = []
|
|
174
|
+
this.fixturesPath = 'spec/javascripts/fixtures'
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
jasmine.StyleFixtures.prototype.set = function (css) {
|
|
178
|
+
this.cleanUp()
|
|
179
|
+
this.createStyle_(css)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
jasmine.StyleFixtures.prototype.appendSet = function (css) {
|
|
183
|
+
this.createStyle_(css)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
jasmine.StyleFixtures.prototype.preload = function () {
|
|
187
|
+
this.read_.apply(this, arguments)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
jasmine.StyleFixtures.prototype.load = function () {
|
|
191
|
+
this.cleanUp()
|
|
192
|
+
this.createStyle_(this.read_.apply(this, arguments))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
jasmine.StyleFixtures.prototype.appendLoad = function () {
|
|
196
|
+
this.createStyle_(this.read_.apply(this, arguments))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
jasmine.StyleFixtures.prototype.cleanUp = function () {
|
|
200
|
+
while(this.fixturesNodes_.length) {
|
|
201
|
+
this.fixturesNodes_.pop().remove()
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
jasmine.StyleFixtures.prototype.createStyle_ = function (html) {
|
|
206
|
+
var styleText = $('<div></div>').html(html).text()
|
|
207
|
+
, style = $('<style>' + styleText + '</style>')
|
|
208
|
+
|
|
209
|
+
this.fixturesNodes_.push(style)
|
|
210
|
+
$('head').append(style)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
|
|
214
|
+
jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
|
|
215
|
+
jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
|
|
216
|
+
jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
|
|
217
|
+
jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
|
|
218
|
+
jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
|
|
219
|
+
|
|
220
|
+
jasmine.getJSONFixtures = function () {
|
|
221
|
+
return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
jasmine.JSONFixtures = function () {
|
|
225
|
+
this.fixturesCache_ = {}
|
|
226
|
+
this.fixturesPath = 'spec/javascripts/fixtures/json'
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
jasmine.JSONFixtures.prototype.load = function () {
|
|
230
|
+
this.read.apply(this, arguments)
|
|
231
|
+
return this.fixturesCache_
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
jasmine.JSONFixtures.prototype.read = function () {
|
|
235
|
+
var fixtureUrls = arguments
|
|
236
|
+
|
|
237
|
+
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
|
|
238
|
+
this.getFixtureData_(fixtureUrls[urlIndex])
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return this.fixturesCache_
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
jasmine.JSONFixtures.prototype.clearCache = function () {
|
|
245
|
+
this.fixturesCache_ = {}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
|
|
249
|
+
if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
|
|
250
|
+
return this.fixturesCache_[url]
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
|
|
254
|
+
var self = this
|
|
255
|
+
, url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
|
|
256
|
+
|
|
257
|
+
$.ajax({
|
|
258
|
+
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
|
259
|
+
cache: false,
|
|
260
|
+
dataType: 'json',
|
|
261
|
+
url: url,
|
|
262
|
+
success: function (data) {
|
|
263
|
+
self.fixturesCache_[relativeUrl] = data
|
|
264
|
+
},
|
|
265
|
+
error: function ($xhr, status, err) {
|
|
266
|
+
throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
|
|
272
|
+
return this[methodName].apply(this, passedArguments)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
jasmine.jQuery = function () {}
|
|
276
|
+
|
|
277
|
+
jasmine.jQuery.browserTagCaseIndependentHtml = function (html) {
|
|
278
|
+
return $('<div/>').append(html).html()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
jasmine.jQuery.elementToString = function (element) {
|
|
282
|
+
return $(element).map(function () { return this.outerHTML; }).toArray().join(', ')
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
var data = {
|
|
286
|
+
spiedEvents: {}
|
|
287
|
+
, handlers: []
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
jasmine.jQuery.events = {
|
|
291
|
+
spyOn: function (selector, eventName) {
|
|
292
|
+
var handler = function (e) {
|
|
293
|
+
var calls = (typeof data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] !== 'undefined') ? data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0
|
|
294
|
+
data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = {
|
|
295
|
+
args: jasmine.util.argsToArray(arguments),
|
|
296
|
+
calls: ++calls
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
$(selector).on(eventName, handler)
|
|
301
|
+
data.handlers.push(handler)
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
selector: selector,
|
|
305
|
+
eventName: eventName,
|
|
306
|
+
handler: handler,
|
|
307
|
+
reset: function (){
|
|
308
|
+
delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
|
|
309
|
+
},
|
|
310
|
+
calls: {
|
|
311
|
+
count: function () {
|
|
312
|
+
return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
|
|
313
|
+
data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0;
|
|
314
|
+
},
|
|
315
|
+
any: function () {
|
|
316
|
+
return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
|
|
317
|
+
!!data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
args: function (selector, eventName) {
|
|
324
|
+
var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].args
|
|
325
|
+
|
|
326
|
+
if (!actualArgs) {
|
|
327
|
+
throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return actualArgs
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
wasTriggered: function (selector, eventName) {
|
|
334
|
+
return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) {
|
|
338
|
+
var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1)
|
|
339
|
+
|
|
340
|
+
if (Object.prototype.toString.call(expectedArgs) !== '[object Array]')
|
|
341
|
+
actualArgs = actualArgs[0]
|
|
342
|
+
|
|
343
|
+
return util.equals(actualArgs, expectedArgs, customEqualityTesters)
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
wasPrevented: function (selector, eventName) {
|
|
347
|
+
var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
|
|
348
|
+
, args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
|
|
349
|
+
, e = args ? args[0] : undefined
|
|
350
|
+
|
|
351
|
+
return e && e.isDefaultPrevented()
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
wasStopped: function (selector, eventName) {
|
|
355
|
+
var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
|
|
356
|
+
, args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
|
|
357
|
+
, e = args ? args[0] : undefined
|
|
358
|
+
|
|
359
|
+
return e && e.isPropagationStopped()
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
cleanUp: function () {
|
|
363
|
+
data.spiedEvents = {}
|
|
364
|
+
data.handlers = []
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
var hasProperty = function (actualValue, expectedValue) {
|
|
369
|
+
if (expectedValue === undefined)
|
|
370
|
+
return actualValue !== undefined
|
|
371
|
+
|
|
372
|
+
return actualValue === expectedValue
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
beforeEach(function () {
|
|
376
|
+
jasmine.addMatchers({
|
|
377
|
+
toHaveClass: function () {
|
|
378
|
+
return {
|
|
379
|
+
compare: function (actual, className) {
|
|
380
|
+
return { pass: $(actual).hasClass(className) }
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
toHaveCss: function () {
|
|
386
|
+
return {
|
|
387
|
+
compare: function (actual, css) {
|
|
388
|
+
for (var prop in css){
|
|
389
|
+
var value = css[prop]
|
|
390
|
+
// see issue #147 on gh
|
|
391
|
+
;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue
|
|
392
|
+
if ($(actual).css(prop) !== value) return { pass: false }
|
|
393
|
+
}
|
|
394
|
+
return { pass: true }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
toBeVisible: function () {
|
|
400
|
+
return {
|
|
401
|
+
compare: function (actual) {
|
|
402
|
+
return { pass: $(actual).is(':visible') }
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
toBeHidden: function () {
|
|
408
|
+
return {
|
|
409
|
+
compare: function (actual) {
|
|
410
|
+
return { pass: $(actual).is(':hidden') }
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
toBeSelected: function () {
|
|
416
|
+
return {
|
|
417
|
+
compare: function (actual) {
|
|
418
|
+
return { pass: $(actual).is(':selected') }
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
toBeChecked: function () {
|
|
424
|
+
return {
|
|
425
|
+
compare: function (actual) {
|
|
426
|
+
return { pass: $(actual).is(':checked') }
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
toBeEmpty: function () {
|
|
432
|
+
return {
|
|
433
|
+
compare: function (actual) {
|
|
434
|
+
return { pass: $(actual).is(':empty') }
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
toBeInDOM: function () {
|
|
440
|
+
return {
|
|
441
|
+
compare: function (actual) {
|
|
442
|
+
return { pass: $.contains(document.documentElement, $(actual)[0]) }
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
toExist: function () {
|
|
448
|
+
return {
|
|
449
|
+
compare: function (actual) {
|
|
450
|
+
return { pass: $(actual).length }
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
|
|
455
|
+
toHaveLength: function () {
|
|
456
|
+
return {
|
|
457
|
+
compare: function (actual, length) {
|
|
458
|
+
return { pass: $(actual).length === length }
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
toHaveAttr: function () {
|
|
464
|
+
return {
|
|
465
|
+
compare: function (actual, attributeName, expectedAttributeValue) {
|
|
466
|
+
return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) }
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
toHaveProp: function () {
|
|
472
|
+
return {
|
|
473
|
+
compare: function (actual, propertyName, expectedPropertyValue) {
|
|
474
|
+
return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) }
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
toHaveId: function () {
|
|
480
|
+
return {
|
|
481
|
+
compare: function (actual, id) {
|
|
482
|
+
return { pass: $(actual).attr('id') == id }
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
|
|
487
|
+
toHaveHtml: function () {
|
|
488
|
+
return {
|
|
489
|
+
compare: function (actual, html) {
|
|
490
|
+
return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) }
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
|
|
495
|
+
toContainHtml: function () {
|
|
496
|
+
return {
|
|
497
|
+
compare: function (actual, html) {
|
|
498
|
+
var actualHtml = $(actual).html()
|
|
499
|
+
, expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html)
|
|
500
|
+
|
|
501
|
+
return { pass: (actualHtml.indexOf(expectedHtml) >= 0) }
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
|
|
506
|
+
toHaveText: function () {
|
|
507
|
+
return {
|
|
508
|
+
compare: function (actual, text) {
|
|
509
|
+
var actualText = $(actual).text()
|
|
510
|
+
var trimmedText = $.trim(actualText)
|
|
511
|
+
|
|
512
|
+
if (text && $.isFunction(text.test)) {
|
|
513
|
+
return { pass: text.test(actualText) || text.test(trimmedText) }
|
|
514
|
+
} else {
|
|
515
|
+
return { pass: (actualText == text || trimmedText == text) }
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
|
|
521
|
+
toContainText: function () {
|
|
522
|
+
return {
|
|
523
|
+
compare: function (actual, text) {
|
|
524
|
+
var trimmedText = $.trim($(actual).text())
|
|
525
|
+
|
|
526
|
+
if (text && $.isFunction(text.test)) {
|
|
527
|
+
return { pass: text.test(trimmedText) }
|
|
528
|
+
} else {
|
|
529
|
+
return { pass: trimmedText.indexOf(text) != -1 }
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
toHaveValue: function () {
|
|
536
|
+
return {
|
|
537
|
+
compare: function (actual, value) {
|
|
538
|
+
return { pass: $(actual).val() === value }
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
|
|
543
|
+
toHaveData: function () {
|
|
544
|
+
return {
|
|
545
|
+
compare: function (actual, key, expectedValue) {
|
|
546
|
+
return { pass: hasProperty($(actual).data(key), expectedValue) }
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
toContainElement: function () {
|
|
552
|
+
return {
|
|
553
|
+
compare: function (actual, selector) {
|
|
554
|
+
return { pass: $(actual).find(selector).length }
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
toBeMatchedBy: function () {
|
|
560
|
+
return {
|
|
561
|
+
compare: function (actual, selector) {
|
|
562
|
+
return { pass: $(actual).filter(selector).length }
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
|
|
567
|
+
toBeDisabled: function () {
|
|
568
|
+
return {
|
|
569
|
+
compare: function (actual, selector) {
|
|
570
|
+
return { pass: $(actual).is(':disabled') }
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
toBeFocused: function (selector) {
|
|
576
|
+
return {
|
|
577
|
+
compare: function (actual, selector) {
|
|
578
|
+
return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement }
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
|
|
583
|
+
toHandle: function () {
|
|
584
|
+
return {
|
|
585
|
+
compare: function (actual, event) {
|
|
586
|
+
if ( !actual || actual.length === 0 ) return { pass: false };
|
|
587
|
+
var events = $._data($(actual).get(0), "events")
|
|
588
|
+
|
|
589
|
+
if (!events || !event || typeof event !== "string") {
|
|
590
|
+
return { pass: false }
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
var namespaces = event.split(".")
|
|
594
|
+
, eventType = namespaces.shift()
|
|
595
|
+
, sortedNamespaces = namespaces.slice(0).sort()
|
|
596
|
+
, namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
|
|
597
|
+
|
|
598
|
+
if (events[eventType] && namespaces.length) {
|
|
599
|
+
for (var i = 0; i < events[eventType].length; i++) {
|
|
600
|
+
var namespace = events[eventType][i].namespace
|
|
601
|
+
|
|
602
|
+
if (namespaceRegExp.test(namespace))
|
|
603
|
+
return { pass: true }
|
|
604
|
+
}
|
|
605
|
+
} else {
|
|
606
|
+
return { pass: (events[eventType] && events[eventType].length > 0) }
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return { pass: false }
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
|
|
614
|
+
toHandleWith: function () {
|
|
615
|
+
return {
|
|
616
|
+
compare: function (actual, eventName, eventHandler) {
|
|
617
|
+
if ( !actual || actual.length === 0 ) return { pass: false };
|
|
618
|
+
var normalizedEventName = eventName.split('.')[0]
|
|
619
|
+
, stack = $._data($(actual).get(0), "events")[normalizedEventName]
|
|
620
|
+
|
|
621
|
+
for (var i = 0; i < stack.length; i++) {
|
|
622
|
+
if (stack[i].handler == eventHandler) return { pass: true }
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return { pass: false }
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
|
|
630
|
+
toHaveBeenTriggeredOn: function () {
|
|
631
|
+
return {
|
|
632
|
+
compare: function (actual, selector) {
|
|
633
|
+
var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) }
|
|
634
|
+
|
|
635
|
+
result.message = result.pass ?
|
|
636
|
+
"Expected event " + $(actual) + " not to have been triggered on " + selector :
|
|
637
|
+
"Expected event " + $(actual) + " to have been triggered on " + selector
|
|
638
|
+
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
|
|
644
|
+
toHaveBeenTriggered: function (){
|
|
645
|
+
return {
|
|
646
|
+
compare: function (actual) {
|
|
647
|
+
var eventName = actual.eventName
|
|
648
|
+
, selector = actual.selector
|
|
649
|
+
, result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) }
|
|
650
|
+
|
|
651
|
+
result.message = result.pass ?
|
|
652
|
+
"Expected event " + eventName + " not to have been triggered on " + selector :
|
|
653
|
+
"Expected event " + eventName + " to have been triggered on " + selector
|
|
654
|
+
|
|
655
|
+
return result
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
|
|
660
|
+
toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) {
|
|
661
|
+
return {
|
|
662
|
+
compare: function (actual, selector, expectedArgs) {
|
|
663
|
+
var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual)
|
|
664
|
+
, result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) }
|
|
665
|
+
|
|
666
|
+
if (wasTriggered) {
|
|
667
|
+
var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1]
|
|
668
|
+
result.message = result.pass ?
|
|
669
|
+
"Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) :
|
|
670
|
+
"Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
|
|
671
|
+
|
|
672
|
+
} else {
|
|
673
|
+
// todo check on this
|
|
674
|
+
result.message = result.pass ?
|
|
675
|
+
"Expected event " + actual + " not to have been triggered on " + selector :
|
|
676
|
+
"Expected event " + actual + " to have been triggered on " + selector
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return result
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
|
|
684
|
+
toHaveBeenPreventedOn: function () {
|
|
685
|
+
return {
|
|
686
|
+
compare: function (actual, selector) {
|
|
687
|
+
var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) }
|
|
688
|
+
|
|
689
|
+
result.message = result.pass ?
|
|
690
|
+
"Expected event " + actual + " not to have been prevented on " + selector :
|
|
691
|
+
"Expected event " + actual + " to have been prevented on " + selector
|
|
692
|
+
|
|
693
|
+
return result
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
|
|
698
|
+
toHaveBeenPrevented: function () {
|
|
699
|
+
return {
|
|
700
|
+
compare: function (actual) {
|
|
701
|
+
var eventName = actual.eventName
|
|
702
|
+
, selector = actual.selector
|
|
703
|
+
, result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) }
|
|
704
|
+
|
|
705
|
+
result.message = result.pass ?
|
|
706
|
+
"Expected event " + eventName + " not to have been prevented on " + selector :
|
|
707
|
+
"Expected event " + eventName + " to have been prevented on " + selector
|
|
708
|
+
|
|
709
|
+
return result
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
|
|
714
|
+
toHaveBeenStoppedOn: function () {
|
|
715
|
+
return {
|
|
716
|
+
compare: function (actual, selector) {
|
|
717
|
+
var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) }
|
|
718
|
+
|
|
719
|
+
result.message = result.pass ?
|
|
720
|
+
"Expected event " + actual + " not to have been stopped on " + selector :
|
|
721
|
+
"Expected event " + actual + " to have been stopped on " + selector
|
|
722
|
+
|
|
723
|
+
return result;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
|
|
728
|
+
toHaveBeenStopped: function () {
|
|
729
|
+
return {
|
|
730
|
+
compare: function (actual) {
|
|
731
|
+
var eventName = actual.eventName
|
|
732
|
+
, selector = actual.selector
|
|
733
|
+
, result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) }
|
|
734
|
+
|
|
735
|
+
result.message = result.pass ?
|
|
736
|
+
"Expected event " + eventName + " not to have been stopped on " + selector :
|
|
737
|
+
"Expected event " + eventName + " to have been stopped on " + selector
|
|
738
|
+
|
|
739
|
+
return result
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
jasmine.getEnv().addCustomEqualityTester(function(a, b) {
|
|
746
|
+
if (a && b) {
|
|
747
|
+
if (a instanceof $ || jasmine.isDomNode(a)) {
|
|
748
|
+
var $a = $(a)
|
|
749
|
+
|
|
750
|
+
if (b instanceof $)
|
|
751
|
+
return $a.length == b.length && a.is(b)
|
|
752
|
+
|
|
753
|
+
return $a.is(b);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (b instanceof $ || jasmine.isDomNode(b)) {
|
|
757
|
+
var $b = $(b)
|
|
758
|
+
|
|
759
|
+
if (a instanceof $)
|
|
760
|
+
return a.length == $b.length && $b.is(a)
|
|
761
|
+
|
|
762
|
+
return $(b).is(a);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
})
|
|
766
|
+
|
|
767
|
+
jasmine.getEnv().addCustomEqualityTester(function (a, b) {
|
|
768
|
+
if (a instanceof $ && b instanceof $ && a.size() == b.size())
|
|
769
|
+
return a.is(b)
|
|
770
|
+
})
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
afterEach(function () {
|
|
774
|
+
jasmine.getFixtures().cleanUp()
|
|
775
|
+
jasmine.getStyleFixtures().cleanUp()
|
|
776
|
+
jasmine.jQuery.events.cleanUp()
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
window.readFixtures = function () {
|
|
780
|
+
return jasmine.getFixtures().proxyCallTo_('read', arguments)
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
window.preloadFixtures = function () {
|
|
784
|
+
jasmine.getFixtures().proxyCallTo_('preload', arguments)
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
window.loadFixtures = function () {
|
|
788
|
+
jasmine.getFixtures().proxyCallTo_('load', arguments)
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
window.appendLoadFixtures = function () {
|
|
792
|
+
jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
window.setFixtures = function (html) {
|
|
796
|
+
return jasmine.getFixtures().proxyCallTo_('set', arguments)
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
window.appendSetFixtures = function () {
|
|
800
|
+
jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
window.sandbox = function (attributes) {
|
|
804
|
+
return jasmine.getFixtures().sandbox(attributes)
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
window.spyOnEvent = function (selector, eventName) {
|
|
808
|
+
return jasmine.jQuery.events.spyOn(selector, eventName)
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
window.preloadStyleFixtures = function () {
|
|
812
|
+
jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
window.loadStyleFixtures = function () {
|
|
816
|
+
jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
window.appendLoadStyleFixtures = function () {
|
|
820
|
+
jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
window.setStyleFixtures = function (html) {
|
|
824
|
+
jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
window.appendSetStyleFixtures = function (html) {
|
|
828
|
+
jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
window.loadJSONFixtures = function () {
|
|
832
|
+
return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
window.getJSONFixture = function (url) {
|
|
836
|
+
return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
|
|
837
|
+
}
|
|
838
|
+
}));
|