booties 0.1.0 → 0.2.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 +5 -5
- data/README.md +172 -0
- data/Rakefile +5 -4
- data/app/controllers/booties/application_controller.rb +4 -1
- data/app/helpers/booties/application_helper.rb +3 -26
- data/app/helpers/booties/badge_helper.rb +6 -3
- data/app/helpers/booties/breadcrumb_helper.rb +29 -0
- data/app/helpers/booties/button_helper.rb +10 -8
- data/app/helpers/booties/dropdown_helper.rb +71 -0
- data/app/helpers/booties/flag_helper.rb +7 -4
- data/app/helpers/booties/modal_helper.rb +4 -1
- data/app/helpers/booties/panel_helper.rb +3 -1
- data/app/helpers/booties/popover_helper.rb +28 -19
- data/app/helpers/booties/tooltip_helper.rb +12 -8
- data/config/routes.rb +2 -0
- data/lib/booties.rb +3 -1
- data/lib/booties/engine.rb +7 -1
- data/lib/booties/modal.rb +13 -12
- data/lib/booties/panel.rb +21 -18
- data/lib/booties/utils.rb +8 -10
- data/lib/booties/version.rb +3 -1
- data/lib/tasks/booties_tasks.rake +2 -0
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +0 -4
- data/test/dummy/app/controllers/samples_controller.rb +28 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/app/views/samples/badges.html.erb +2 -0
- data/test/dummy/app/views/{home → samples}/breadcrumbs.html.erb +2 -1
- data/test/dummy/app/views/samples/buttons.html.erb +2 -0
- data/test/dummy/app/views/samples/dropdowns.html.erb +6 -0
- data/test/dummy/app/views/samples/flags.html.erb +2 -0
- data/test/dummy/app/views/samples/modals.html.erb +12 -0
- data/test/dummy/app/views/samples/panels.html.erb +14 -0
- data/test/dummy/app/views/samples/popovers.html.erb +9 -0
- data/test/dummy/app/views/samples/tooltips.html.erb +3 -0
- data/test/dummy/bin/bundle +1 -1
- data/test/dummy/bin/rails +1 -1
- data/test/dummy/bin/setup +17 -13
- data/test/dummy/bin/update +28 -0
- data/test/dummy/config.ru +2 -1
- data/test/dummy/config/application.rb +13 -12
- data/test/dummy/config/boot.rb +2 -2
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +24 -16
- data/test/dummy/config/environments/production.rb +23 -28
- data/test/dummy/config/environments/test.rb +5 -11
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +6 -1
- data/test/dummy/config/locales/en.yml +10 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +16 -8
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/log/test.log +11202 -19551
- data/test/dummy/public/404.html +6 -6
- data/test/dummy/public/422.html +6 -6
- data/test/dummy/public/500.html +6 -6
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/33/33EUCQBNqL6TOaGyMFn9wz2v39pHMJ4LOUUFUteIHHM.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/7Q/7Q2gtOOyCVPFrfYz4KjmXJsM_m8Yra4MjgsQmfVGxZY.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/8c/8cROjTzeZZQaOFNLPKGuMtXO7EHxNfiEa72qt65UoF4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/F6/F6RhC2MbCvVanNZZe44hqlJNKAdIrH4NUzRxj5N2_EQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Fc/FcMeZRcfG4LrhIhl3xrAg3EhSZInU4efHmUrjIs4keE.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/H3/H3dfPRbxbWIB6dQXrQ6xA9nDJqy4dOq1ujslocGVY9U.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/LK/LKisVDbQmzgRQKdFoNH5tRbTr72CrlM_2q7MZczv2Pg.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Pc/Pce9HMZhc6XmsNfLUN84Enw7mySJ7ZYzys9mXmCVXqA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Po/PoftKmjB8lzW06EMKeru1CsqVtULc0MsiTysT2JNqvU.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Su/SuILTE3Es0N_r-36Ddu2E6h49WcwH_-RsZyG4SPwKFQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/cJ/cJG59MHf0x4qJKYES0pa0nLpOFpFF7YwrrvIVKIixyA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/fw/fwPYklzExHPpgeuv53ew_8OIpJVRyaHj2Jtj2JP9j5A.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/jc/jc_TR7ZZTSFDDRKdgc-KnZskUESr2rLOqcYZej83LvU.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/rV/rVy4-idUuK0Va9FLw3G8pYeZFwJAwmvs_bQcbq6_Cd0.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/rY/rYyeRvy3oIuNfWeDhoriNlAlVjN4Wg4A3_9_OTDFin4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/tY/tYFbDrMNElXwgmisit50aNXJvRU2zlIFk5g-EJ1CQTc.cache +0 -0
- data/test/helpers/booties/badge_helper_test.rb +7 -5
- data/test/helpers/booties/breadcrumb_helper_test.rb +13 -0
- data/test/helpers/booties/button_helper_test.rb +14 -12
- data/test/helpers/booties/dropdown_helper_test.rb +43 -0
- data/test/helpers/booties/flag_helper_test.rb +7 -5
- data/test/helpers/booties/modal_helper_test.rb +9 -7
- data/test/helpers/booties/panel_helper_test.rb +4 -2
- data/test/helpers/booties/popover_helper_test.rb +33 -42
- data/test/helpers/booties/tooltip_helper_test.rb +19 -40
- data/test/integration/samples_test.rb +103 -0
- data/test/lib/booties/modal_test.rb +193 -0
- data/test/{booties → lib/booties}/panel_test.rb +40 -22
- data/test/lib/booties/utils_test.rb +41 -0
- data/test/stub_view.rb +14 -7
- data/test/test_helper.rb +10 -11
- metadata +124 -98
- data/app/assets/javascripts/booties/application.js +0 -13
- data/app/assets/stylesheets/booties/application.css +0 -15
- data/test/booties/modal_test.rb +0 -170
- data/test/booties/utils_test.rb +0 -26
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/assets/javascripts/home.js +0 -2
- data/test/dummy/app/assets/stylesheets/home.css +0 -4
- data/test/dummy/app/controllers/home_controller.rb +0 -25
- data/test/dummy/app/helpers/home_helper.rb +0 -2
- data/test/dummy/app/views/home/badge.html.erb +0 -3
- data/test/dummy/app/views/home/button.html.erb +0 -2
- data/test/dummy/app/views/home/flag.html.erb +0 -5
- data/test/dummy/app/views/home/modal.html.erb +0 -16
- data/test/dummy/app/views/home/panel.html.erb +0 -25
- data/test/dummy/app/views/home/popover.html.erb +0 -7
- data/test/dummy/app/views/home/tooltip.html.erb +0 -7
- data/test/dummy/config/initializers/assets.rb +0 -11
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/locales/booties.yml +0 -4
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/log/development.log +0 -420
- data/test/dummy/test/controllers/home_controller_test.rb +0 -108
- data/test/helpers/booties/application_helper_test.rb +0 -11
- data/test/integration/navigation_test.rb +0 -9
|
@@ -1,55 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
|
|
3
5
|
module Booties
|
|
4
6
|
class TooltipHelperTest < ActionView::TestCase
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
assert_equal expected, tooltip(title: 'foo bar') { 'baz' }
|
|
7
|
+
def test_tooltip_renders_span_tag_with_given_title
|
|
8
|
+
assert_dom_equal '<span title="required" data-toggle="tooltip">*</span>',
|
|
9
|
+
tooltip('*', title: 'required')
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
assert_equal expected, tooltip(title: 'foo bar', placement: :bottom) { 'baz' }
|
|
12
|
+
def test_tooltip_accepts_content_as_block
|
|
13
|
+
assert_dom_equal '<span title="required" data-toggle="tooltip">*</span>',
|
|
14
|
+
tooltip(title: 'required') { '*' }
|
|
17
15
|
end
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
assert_equal expected, tooltip(title: 'foo bar', placement: :right) { 'baz' }
|
|
17
|
+
def test_tooltip_with_custom_placement
|
|
18
|
+
assert_dom_equal \
|
|
19
|
+
'<span title="required" data-toggle="tooltip" data-placement="bottom">*</span>',
|
|
20
|
+
tooltip('*', title: 'required', placement: :bottom)
|
|
24
21
|
end
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
assert_equal expected, tooltip(title: 'foo bar', placement: :left) { 'baz' }
|
|
23
|
+
def test_tooltip_renders_tooltip_using_alternative_wrapper_tag
|
|
24
|
+
assert_dom_equal '<abbr title="required" data-toggle="tooltip">*</abbr>',
|
|
25
|
+
tooltip('*', title: 'required', wrapper_tag: :abbr)
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
assert_equal 'invalid placement: :bogus, ' \
|
|
38
|
-
'valid placements are :left, :right, :top, :bottom', e.message
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test '#tooltip renders tooltip using alternative wrapper tag' do
|
|
42
|
-
expected = content_tag :abbr, 'baz',
|
|
43
|
-
data: { toggle: 'tooltip' }, title: 'foo'
|
|
44
|
-
|
|
45
|
-
assert_equal expected, tooltip(title: 'foo', wrapper_tag: :abbr) { 'baz' }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test '#tooltip accepts additional html attributes' do
|
|
49
|
-
expected = content_tag :span, 'baz',
|
|
50
|
-
data: { toggle: 'tooltip' }, title: 'foo', class: 'bar'
|
|
51
|
-
|
|
52
|
-
assert_equal expected, tooltip(title: 'foo', class: 'bar') { 'baz' }
|
|
28
|
+
def test_tooltip_accepts_additional_html_attributes
|
|
29
|
+
assert_dom_equal \
|
|
30
|
+
'<abbr class="initialism" title="HyperText Markup Language" data-toggle="tooltip">HTML</abbr>',
|
|
31
|
+
tooltip('HTML', title: 'HyperText Markup Language', class: 'initialism', wrapper_tag: :abbr)
|
|
53
32
|
end
|
|
54
33
|
end
|
|
55
34
|
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class NavigationTest < ActionDispatch::IntegrationTest
|
|
6
|
+
def test_badges
|
|
7
|
+
get samples_badges_url
|
|
8
|
+
assert_select 'span.badge', '101'
|
|
9
|
+
assert_select 'span.badge.foo', '42'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_breadcrumbs
|
|
13
|
+
get samples_breadcrumbs_url
|
|
14
|
+
assert_select 'ol.breadcrumb' do
|
|
15
|
+
assert_select 'li:first-child a', 'Foo'
|
|
16
|
+
assert_select 'li:last-child.active', 'Bar'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_buttons
|
|
21
|
+
get samples_buttons_url
|
|
22
|
+
assert_select 'a.btn.btn-default', 'Foo'
|
|
23
|
+
assert_select 'a.btn.btn-danger.btn-xs[data-method="delete"]', 'Bar'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_dropdowns
|
|
27
|
+
get samples_dropdowns_url
|
|
28
|
+
assert_select 'a.dropdown-toggle[role="button"][data-toggle="dropdown"]', 'Foo'
|
|
29
|
+
assert_select 'ul.dropdown-menu' do
|
|
30
|
+
assert_select 'li', 'Foo'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_flags
|
|
35
|
+
get samples_flags_url
|
|
36
|
+
assert_select 'span.label.label-default', 'Foo'
|
|
37
|
+
assert_select 'span.label.label-primary.foo', 'Bar'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_modals
|
|
41
|
+
get samples_modals_url
|
|
42
|
+
assert_select 'div.modal.fade#foo' do
|
|
43
|
+
assert_select 'div.modal-dialog.modal-lg' do
|
|
44
|
+
assert_select 'div.modal-content' do
|
|
45
|
+
assert_select 'div.modal-header' do
|
|
46
|
+
assert_select 'button.close[data-dismiss="modal"][type="button"]', '×'
|
|
47
|
+
assert_select 'h4.modal-title', 'Title'
|
|
48
|
+
end
|
|
49
|
+
assert_select 'div.modal-body' do
|
|
50
|
+
assert_select 'p', 'Body'
|
|
51
|
+
end
|
|
52
|
+
assert_select 'div.modal-footer' do
|
|
53
|
+
assert_select 'button.btn.btn-default[data-dismiss="modal"][type="button"]', 'Dismiss'
|
|
54
|
+
assert_select 'a.btn.btn-primary[href="/bar"]', 'Confirm'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_panels
|
|
62
|
+
get samples_panels_url
|
|
63
|
+
|
|
64
|
+
assert_select 'div.panel.panel-default' do
|
|
65
|
+
assert_select 'div.panel-heading' do
|
|
66
|
+
assert_select 'h3.panel-title', 'Title'
|
|
67
|
+
end
|
|
68
|
+
assert_select 'div.panel-body', 'Body'
|
|
69
|
+
assert_select 'div.panel-footer', 'Footer'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
assert_select 'div.panel.panel-info' do
|
|
73
|
+
assert_select 'div.panel-heading' do
|
|
74
|
+
assert_select 'h3.panel-title', 'Title'
|
|
75
|
+
end
|
|
76
|
+
assert_select 'table caption', 'Use table instead of .panel-body'
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_popovers
|
|
81
|
+
get samples_popovers_url
|
|
82
|
+
|
|
83
|
+
assert_select 'button', text: 'Text' do
|
|
84
|
+
assert_select '[type="button"]'
|
|
85
|
+
assert_select '[data-toggle="popover"]'
|
|
86
|
+
assert_select '[data-content="Lorem ipsum dolor sit amet"]'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
assert_select 'a', text: 'Text' do
|
|
90
|
+
assert_select '[role="button"]'
|
|
91
|
+
assert_select '[data-toggle="popover"]'
|
|
92
|
+
assert_select '[data-placement="right"]'
|
|
93
|
+
assert_select '[data-trigger="focus"]'
|
|
94
|
+
assert_select '[title="Lorem ipsum dolor sit amet"]'
|
|
95
|
+
assert_select '[data-content="Occaecati corrupti atque quasi sit"]'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_tooltips
|
|
100
|
+
get samples_tooltips_url
|
|
101
|
+
assert_select 'span[data-toggle="tooltip"][title="Lorem ipsum dolor sit amet"]', 'Lorem ipsum…'
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'stub_view'
|
|
5
|
+
|
|
6
|
+
module Booties
|
|
7
|
+
class ModalTest < Minitest::Test
|
|
8
|
+
def setup
|
|
9
|
+
@template = StubView.new
|
|
10
|
+
@backend = I18n.backend
|
|
11
|
+
I18n.backend = I18n::Backend::KeyValue.new({})
|
|
12
|
+
I18n.enforce_available_locales = false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def teardown
|
|
16
|
+
I18n.backend = @backend
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_render_renders_a_fading_modal_with_an_id_and_a_dialog
|
|
20
|
+
modal = Modal.new @template, id: 'foo'
|
|
21
|
+
expected = '<div class="modal fade" id="foo"><div class="modal-dialog">' \
|
|
22
|
+
'<div class="modal-content"></div></div></div>'
|
|
23
|
+
actual = modal.render {}
|
|
24
|
+
assert_equal expected, actual
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_render_renders_a_non_fading_modal_when_fade_is_falsey
|
|
28
|
+
modal = Modal.new @template, id: 'foo', fade: false
|
|
29
|
+
expected = '<div class="modal" id="foo"><div class="modal-dialog">' \
|
|
30
|
+
'<div class="modal-content"></div></div></div>'
|
|
31
|
+
actual = modal.render {}
|
|
32
|
+
assert_equal expected, actual
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_render_passes_misc_options_to_outer_container
|
|
36
|
+
modal = Modal.new @template, id: 'foo'
|
|
37
|
+
expected = /<div class="modal fade foo" id="foo" data-bar="baz">/
|
|
38
|
+
actual = modal.render(class: 'foo', data: { bar: 'baz' }) {}
|
|
39
|
+
assert_match expected, actual
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_large_modal
|
|
43
|
+
modal = Modal.new @template, id: 'foo', size: :large
|
|
44
|
+
expected = /<div class="modal-dialog modal-lg">/
|
|
45
|
+
actual = modal.render {}
|
|
46
|
+
assert_match expected, actual
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_small_modal
|
|
50
|
+
modal = Modal.new @template, id: 'foo', size: :small
|
|
51
|
+
expected = /<div class="modal-dialog modal-sm">/
|
|
52
|
+
actual = modal.render {}
|
|
53
|
+
assert_match expected, actual
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_dialog_renders_a_modal_dialog_with_a_modal_content
|
|
57
|
+
modal = Modal.new @template, id: 'foo'
|
|
58
|
+
expected = '<div class="modal-dialog"><div class="modal-content">' \
|
|
59
|
+
'</div></div>'
|
|
60
|
+
actual = modal.dialog {}
|
|
61
|
+
assert_equal expected, actual
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_content_renders_a_modal_content
|
|
65
|
+
modal = Modal.new @template, id: 'foo'
|
|
66
|
+
expected = '<div class="modal-content"></div>'
|
|
67
|
+
actual = modal.content {}
|
|
68
|
+
assert_equal expected, actual
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_content_yields_modal_to_block
|
|
72
|
+
modal = Modal.new @template, id: 'foo'
|
|
73
|
+
yielded_modal = nil
|
|
74
|
+
modal.content do |m|
|
|
75
|
+
yielded_modal = m
|
|
76
|
+
end
|
|
77
|
+
assert_same modal, yielded_modal
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_header_renders_a_modal_header_with_a_title_and_a_dismissal
|
|
81
|
+
modal = Modal.new @template, id: 'foo'
|
|
82
|
+
expected = '<div class="modal-header">' \
|
|
83
|
+
'<button class="close" data-dismiss="modal" type="button">' \
|
|
84
|
+
'×' \
|
|
85
|
+
'</button><h4 class="modal-title">content</h4></div>'
|
|
86
|
+
actual = modal.header { 'content' }
|
|
87
|
+
assert_equal expected, actual
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_header_renders_a_modal_header_withouth_a_dismissal
|
|
91
|
+
modal = Modal.new @template, id: 'foo'
|
|
92
|
+
expected = '<div class="modal-header">' \
|
|
93
|
+
'<h4 class="modal-title">content</h4></div>'
|
|
94
|
+
actual = modal.header(close: false) { 'content' }
|
|
95
|
+
assert_equal expected, actual
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_header_uses_html_dismissal
|
|
99
|
+
icon = '<span class="glyphicon glyphicon-remove" aria-label="Dismiss"></span>'
|
|
100
|
+
translations = {}
|
|
101
|
+
I18n.backend = I18n::Backend::KeyValue.new translations
|
|
102
|
+
I18n.backend.store_translations I18n.locale,
|
|
103
|
+
booties: { modal: { dismiss_html: icon } }
|
|
104
|
+
|
|
105
|
+
modal = Modal.new @template, id: 'foo'
|
|
106
|
+
expected = %r{<button class="close" data-dismiss="modal" type="button">#{icon}</button>}
|
|
107
|
+
actual = modal.header { 'content' }
|
|
108
|
+
assert_match expected, actual
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_header_falls_back_on_non_html_dismissal
|
|
112
|
+
translations = {}
|
|
113
|
+
I18n.backend = I18n::Backend::KeyValue.new translations
|
|
114
|
+
I18n.backend.store_translations I18n.locale,
|
|
115
|
+
booties: { modal: { dismiss: 'close' } }
|
|
116
|
+
|
|
117
|
+
modal = Modal.new @template, id: 'foo'
|
|
118
|
+
expected = %r{<button class="close" data-dismiss="modal" type="button">close</button>}
|
|
119
|
+
actual = modal.header { 'content' }
|
|
120
|
+
assert_match expected, actual
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_header_falls_back_on_default_dismissal
|
|
124
|
+
translations = {}
|
|
125
|
+
I18n.backend = I18n::Backend::KeyValue.new translations
|
|
126
|
+
|
|
127
|
+
modal = Modal.new @template, id: 'foo'
|
|
128
|
+
expected = %r{<button class="close" data-dismiss="modal" type="button">×</button>}
|
|
129
|
+
actual = modal.header { 'content' }
|
|
130
|
+
assert_match expected, actual
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_body_renders_a_modal_body
|
|
134
|
+
modal = Modal.new @template, id: 'foo'
|
|
135
|
+
expected = '<div class="modal-body">content</div>'
|
|
136
|
+
actual = modal.body { 'content' }
|
|
137
|
+
assert_equal expected, actual
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_footer_renders_a_modal_footer
|
|
141
|
+
modal = Modal.new @template, id: 'foo'
|
|
142
|
+
expected = '<div class="modal-footer">content</div>'
|
|
143
|
+
actual = modal.footer { 'content' }
|
|
144
|
+
assert_equal expected, actual
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_title_renders_a_modal_title
|
|
148
|
+
modal = Modal.new @template, id: 'foo'
|
|
149
|
+
expected = '<h4 class="modal-title">content</h4>'
|
|
150
|
+
actual = modal.title('content')
|
|
151
|
+
assert_equal expected, actual
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_title_accepts_content_as_a_block
|
|
155
|
+
modal = Modal.new @template, id: 'foo'
|
|
156
|
+
expected = '<h4 class="modal-title">content</h4>'
|
|
157
|
+
actual = modal.title { 'content' }
|
|
158
|
+
assert_equal expected, actual
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_dismiss_renders_a_dismiss_button
|
|
162
|
+
modal = Modal.new @template, id: 'foo'
|
|
163
|
+
expected = '<button class="close" data-dismiss="modal" type="button">' \
|
|
164
|
+
'content</button>'
|
|
165
|
+
actual = modal.dismiss('content')
|
|
166
|
+
assert_equal expected, actual
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_dismiss_accepts_content_as_a_block
|
|
170
|
+
modal = Modal.new @template, id: 'foo'
|
|
171
|
+
expected = '<button class="close" data-dismiss="modal" type="button">' \
|
|
172
|
+
'content</button>'
|
|
173
|
+
actual = modal.dismiss { 'content' }
|
|
174
|
+
assert_equal expected, actual
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def test_dismiss_accepts_custom_class
|
|
178
|
+
modal = Modal.new @template, id: 'foo'
|
|
179
|
+
expected = '<button class="btn btn-default" data-dismiss="modal"' \
|
|
180
|
+
' type="button">content</button>'
|
|
181
|
+
actual = modal.dismiss('content', class: 'btn btn-default')
|
|
182
|
+
assert_equal expected, actual
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_dismiss_accepts_custom_class_and_block
|
|
186
|
+
modal = Modal.new @template, id: 'foo'
|
|
187
|
+
expected = '<button class="btn btn-default" data-dismiss="modal"' \
|
|
188
|
+
' type="button">content</button>'
|
|
189
|
+
actual = modal.dismiss(class: 'btn btn-default') { 'content' }
|
|
190
|
+
assert_equal expected, actual
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'stub_view'
|
|
3
5
|
|
|
4
6
|
module Booties
|
|
5
7
|
class PanelTest < Minitest::Test
|
|
6
8
|
def setup
|
|
7
|
-
@
|
|
9
|
+
@template = StubView.new
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def test_default_panel
|
|
11
13
|
expected = '<div class="panel panel-default">content</div>'
|
|
12
|
-
|
|
14
|
+
actual = panel.render { 'content' }
|
|
15
|
+
assert_equal expected, actual
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def test_panel_with_custom_context
|
|
16
|
-
panel = Panel.new @
|
|
19
|
+
panel = Panel.new @template, context: :primary
|
|
17
20
|
expected = '<div class="panel panel-primary">content</div>'
|
|
18
|
-
|
|
21
|
+
actual = panel.render { 'content' }
|
|
22
|
+
assert_equal expected, actual
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def test_render_panel_with_custom_wrapper_tag
|
|
22
|
-
panel = Panel.new @
|
|
26
|
+
panel = Panel.new @template, wrapper_tag: 'fieldset'
|
|
23
27
|
expected = '<fieldset class="panel panel-default"></fieldset>'
|
|
24
|
-
|
|
28
|
+
actual = panel.render {}
|
|
29
|
+
assert_equal expected, actual
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
def test_optional_arguments_to_panel
|
|
28
|
-
panel = Panel.new @
|
|
33
|
+
panel = Panel.new @template, id: 'foo', class: 'bar'
|
|
29
34
|
expected = '<div class="panel panel-default bar" id="foo"></div>'
|
|
30
|
-
|
|
35
|
+
actual = panel.render {}
|
|
36
|
+
assert_equal expected, actual
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
def test_render_yields_panel_to_block
|
|
34
|
-
panel = Panel.new @
|
|
40
|
+
panel = Panel.new @template
|
|
35
41
|
yielded_panel = nil
|
|
36
42
|
panel.render { |p| yielded_panel = p }
|
|
37
43
|
assert_same panel, yielded_panel
|
|
@@ -39,68 +45,80 @@ module Booties
|
|
|
39
45
|
|
|
40
46
|
def test_panel_heading
|
|
41
47
|
expected = '<div class="panel-heading">content</div>'
|
|
42
|
-
|
|
48
|
+
actual = panel.heading('content')
|
|
49
|
+
assert_equal expected, actual
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
def test_panel_heading_accepts_block
|
|
46
53
|
expected = '<div class="panel-heading">content</div>'
|
|
47
|
-
|
|
54
|
+
actual = panel.heading { 'content' }
|
|
55
|
+
assert_equal expected, actual
|
|
48
56
|
end
|
|
49
57
|
|
|
50
58
|
def test_panel_heading_with_optional_arguments
|
|
51
59
|
expected = '<div class="panel-heading foo" id="bar"></div>'
|
|
52
|
-
|
|
60
|
+
actual = panel.heading('', class: 'foo', id: 'bar')
|
|
61
|
+
assert_equal expected, actual
|
|
53
62
|
end
|
|
54
63
|
|
|
55
64
|
def test_panel_title
|
|
56
65
|
expected = '<h3 class="panel-title">content</h3>'
|
|
57
|
-
|
|
66
|
+
actual = panel.title('content')
|
|
67
|
+
assert_equal expected, actual
|
|
58
68
|
end
|
|
59
69
|
|
|
60
70
|
def test_panel_title_accepts_block
|
|
61
71
|
expected = '<h3 class="panel-title">content</h3>'
|
|
62
|
-
|
|
72
|
+
actual = panel.title { 'content' }
|
|
73
|
+
assert_equal expected, actual
|
|
63
74
|
end
|
|
64
75
|
|
|
65
76
|
def test_panel_title_with_optional_arguments
|
|
66
77
|
expected = '<h3 class="panel-title foo" id="bar"></h3>'
|
|
67
|
-
|
|
78
|
+
actual = panel.title('', class: 'foo', id: 'bar')
|
|
79
|
+
assert_equal expected, actual
|
|
68
80
|
end
|
|
69
81
|
|
|
70
82
|
def test_panel_body
|
|
71
83
|
expected = '<div class="panel-body">content</div>'
|
|
72
|
-
|
|
84
|
+
actual = panel.body('content')
|
|
85
|
+
assert_equal expected, actual
|
|
73
86
|
end
|
|
74
87
|
|
|
75
88
|
def test_panel_body_accepts_block
|
|
76
89
|
expected = '<div class="panel-body">content</div>'
|
|
77
|
-
|
|
90
|
+
actual = panel.body { 'content' }
|
|
91
|
+
assert_equal expected, actual
|
|
78
92
|
end
|
|
79
93
|
|
|
80
94
|
def test_panel_body_with_optional_arguments
|
|
81
95
|
expected = '<div class="panel-body foo" id="bar"></div>'
|
|
82
|
-
|
|
96
|
+
actual = panel.body('', class: 'foo', id: 'bar')
|
|
97
|
+
assert_equal expected, actual
|
|
83
98
|
end
|
|
84
99
|
|
|
85
100
|
def test_panel_footer
|
|
86
101
|
expected = '<div class="panel-footer">content</div>'
|
|
87
|
-
|
|
102
|
+
actual = panel.footer('content')
|
|
103
|
+
assert_equal expected, actual
|
|
88
104
|
end
|
|
89
105
|
|
|
90
106
|
def test_panel_footer_accepts_block
|
|
91
107
|
expected = '<div class="panel-footer">content</div>'
|
|
92
|
-
|
|
108
|
+
actual = panel.footer { 'content' }
|
|
109
|
+
assert_equal expected, actual
|
|
93
110
|
end
|
|
94
111
|
|
|
95
112
|
def test_panel_footer_with_optional_arguments
|
|
96
113
|
expected = '<div class="panel-footer foo" id="bar"></div>'
|
|
97
|
-
|
|
114
|
+
actual = panel.footer('', class: 'foo', id: 'bar')
|
|
115
|
+
assert_equal expected, actual
|
|
98
116
|
end
|
|
99
117
|
|
|
100
118
|
private
|
|
101
119
|
|
|
102
120
|
def panel
|
|
103
|
-
@panel ||= Panel.new @
|
|
121
|
+
@panel ||= Panel.new @template
|
|
104
122
|
end
|
|
105
123
|
end
|
|
106
124
|
end
|