velvetkit 0.4.1 → 0.5.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 +4 -4
- data/CHANGELOG.md +143 -2
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/accordion/trigger.rb +1 -1
- data/registry/app/components/ui/badge.rb +1 -1
- data/registry/app/components/ui/base.rb +2 -2
- data/registry/app/components/ui/button.rb +1 -1
- data/registry/app/components/ui/card/action.html.erb +1 -0
- data/registry/app/components/ui/card/action.rb +14 -0
- data/registry/app/components/ui/card/content.html.erb +1 -1
- data/registry/app/components/ui/card/content.rb +4 -2
- data/registry/app/components/ui/card/description.html.erb +1 -1
- data/registry/app/components/ui/card/description.rb +4 -2
- data/registry/app/components/ui/card/footer.html.erb +1 -1
- data/registry/app/components/ui/card/footer.rb +4 -2
- data/registry/app/components/ui/card/header.html.erb +1 -1
- data/registry/app/components/ui/card/header.rb +9 -2
- data/registry/app/components/ui/card/title.html.erb +1 -1
- data/registry/app/components/ui/card/title.rb +4 -2
- data/registry/app/components/ui/card.html.erb +1 -1
- data/registry/app/components/ui/card.rb +49 -3
- data/registry/app/components/ui/carousel.html.erb +7 -0
- data/registry/app/components/ui/carousel.rb +60 -0
- data/registry/app/components/ui/chart.html.erb +3 -3
- data/registry/app/components/ui/chart.rb +18 -10
- data/registry/app/components/ui/checkbox.html.erb +6 -0
- data/registry/app/components/ui/checkbox.rb +11 -4
- data/registry/app/components/ui/fieldset.html.erb +6 -0
- data/registry/app/components/ui/fieldset.rb +76 -0
- data/registry/app/components/ui/gallery/image.rb +14 -1
- data/registry/app/components/ui/gallery.html.erb +32 -3
- data/registry/app/components/ui/gallery.rb +46 -7
- data/registry/app/components/ui/link.rb +1 -1
- data/registry/app/components/ui/menu/item.rb +1 -1
- data/registry/app/components/ui/radio_group/item.html.erb +1 -1
- data/registry/app/components/ui/radio_group/item.rb +5 -1
- data/registry/app/components/ui/radio_group.html.erb +1 -1
- data/registry/app/components/ui/radio_group.rb +42 -2
- data/registry/app/components/ui/scrubber.html.erb +18 -0
- data/registry/app/components/ui/scrubber.rb +62 -0
- data/registry/app/components/ui/select.html.erb +1 -1
- data/registry/app/components/ui/select.rb +16 -1
- data/registry/app/components/ui/selection_bar.html.erb +7 -0
- data/registry/app/components/ui/selection_bar.rb +75 -0
- data/registry/app/components/ui/sidebar/group_label.rb +1 -1
- data/registry/app/components/ui/sidebar/inset.rb +5 -2
- data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
- data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
- data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
- data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
- data/registry/app/components/ui/sidebar.html.erb +3 -3
- data/registry/app/components/ui/sidebar.rb +91 -13
- data/registry/app/components/ui/switch.rb +2 -2
- data/registry/app/components/ui/table/column.html.erb +1 -1
- data/registry/app/components/ui/table/column.rb +26 -2
- data/registry/app/components/ui/table/head.html.erb +1 -1
- data/registry/app/components/ui/table/head.rb +15 -2
- data/registry/app/components/ui/table/row.html.erb +1 -1
- data/registry/app/components/ui/table/row.rb +19 -5
- data/registry/app/components/ui/table.html.erb +2 -2
- data/registry/app/components/ui/table.rb +29 -4
- data/registry/app/components/ui/tabs/trigger.rb +1 -1
- data/registry/app/components/ui/toggle_group.html.erb +1 -1
- data/registry/app/components/ui/toggle_group.rb +26 -3
- data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
- data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
- data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
- data/registry/components.yml +12 -4
- data/registry/config/locales/velvetkit.en.yml +16 -0
- data/registry/icons/lucide/arrow-down.svg +16 -0
- data/registry/icons/lucide/arrow-up.svg +16 -0
- data/registry/icons/lucide/image.svg +17 -0
- data/registry/icons/lucide/star.svg +15 -0
- data/registry/icons/phosphor/arrow-down.svg +2 -0
- data/registry/icons/phosphor/arrow-up.svg +2 -0
- data/registry/icons/phosphor/image.svg +2 -0
- data/registry/icons/phosphor/star.svg +2 -0
- data/registry/icons/tabler/arrow-down.svg +18 -0
- data/registry/icons/tabler/arrow-up.svg +18 -0
- data/registry/icons/tabler/photo.svg +19 -0
- data/registry/icons/tabler/star.svg +16 -0
- data/registry/icons.yml +4 -0
- data/registry/test/components/previews/ui/card_preview/edge_to_edge.html.erb +19 -0
- data/registry/test/components/previews/ui/card_preview/image.html.erb +12 -0
- data/registry/test/components/previews/ui/card_preview/just_content.html.erb +10 -0
- data/registry/test/components/previews/ui/card_preview/open_bill.html.erb +18 -0
- data/registry/test/components/previews/ui/card_preview/playground.html.erb +17 -0
- data/registry/test/components/previews/ui/card_preview/settings_form.html.erb +15 -24
- data/registry/test/components/previews/ui/card_preview/sign_in.html.erb +23 -0
- data/registry/test/components/previews/ui/card_preview/small.html.erb +17 -0
- data/registry/test/components/previews/ui/card_preview/spacing.html.erb +13 -0
- data/registry/test/components/previews/ui/card_preview/stats.html.erb +11 -0
- data/registry/test/components/previews/ui/card_preview/team.html.erb +21 -0
- data/registry/test/components/previews/ui/card_preview.rb +42 -28
- data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
- data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
- data/registry/test/components/previews/ui/chart_preview.rb +7 -1
- data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
- data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
- data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
- data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
- data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
- data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
- data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
- data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
- data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
- data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
- data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
- data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
- data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
- data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
- data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
- data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
- data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
- data/registry/test/components/previews/ui/table_preview.rb +9 -0
- data/registry/test/components/ui/button_test.rb +2 -2
- data/registry/test/components/ui/card/action_test.rb +19 -0
- data/registry/test/components/ui/card/content_test.rb +1 -11
- data/registry/test/components/ui/card/footer_test.rb +3 -2
- data/registry/test/components/ui/card/header_test.rb +3 -4
- data/registry/test/components/ui/card/title_test.rb +3 -4
- data/registry/test/components/ui/card_test.rb +63 -2
- data/registry/test/components/ui/carousel_test.rb +38 -0
- data/registry/test/components/ui/chart_test.rb +20 -0
- data/registry/test/components/ui/checkbox_test.rb +11 -2
- data/registry/test/components/ui/fieldset_test.rb +119 -0
- data/registry/test/components/ui/gallery_test.rb +40 -5
- data/registry/test/components/ui/link_test.rb +1 -1
- data/registry/test/components/ui/number_input_test.rb +1 -1
- data/registry/test/components/ui/radio_group_test.rb +106 -0
- data/registry/test/components/ui/scrubber_test.rb +43 -0
- data/registry/test/components/ui/select_test.rb +21 -0
- data/registry/test/components/ui/selection_bar_test.rb +46 -0
- data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
- data/registry/test/components/ui/sidebar_test.rb +79 -1
- data/registry/test/components/ui/switch_test.rb +4 -4
- data/registry/test/components/ui/toggle_group_test.rb +45 -0
- metadata +60 -5
- data/registry/test/components/previews/ui/card_preview/complete.html.erb +0 -31
- data/registry/test/components/previews/ui/card_preview/default.html.erb +0 -7
- data/registry/test/components/previews/ui/card_preview/with_footer.html.erb +0 -13
- data/registry/test/components/previews/ui/card_preview/with_header.html.erb +0 -11
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::Card::ActionTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_sits_in_the_headers_second_column
|
|
10
|
+
render_inline(UI::Card::Action.new) { "Invite" }
|
|
11
|
+
action = page.find("[data-slot='card-action']", text: "Invite")
|
|
12
|
+
%w[col-start-2 row-span-2 row-start-1 justify-self-end].each { |c| assert_includes action[:class].split, c }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_passes_class_and_attributes
|
|
16
|
+
render_inline(UI::Card::Action.new(class: "self-center", id: "a", data: { testid: "t" })) { "x" }
|
|
17
|
+
assert_selector "#a.self-center[data-testid='t'][data-slot='card-action']"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -14,8 +14,7 @@ class UI::Card::ContentTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Content.new) { "x" }
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
|
-
assert_includes classes, "
|
|
18
|
-
assert_includes classes, "pt-0"
|
|
17
|
+
assert_includes classes, "px-(--card-spacing)"
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def test_user_class_override
|
|
@@ -29,13 +28,4 @@ class UI::Card::ContentTest < ViewComponent::TestCase
|
|
|
29
28
|
render_inline(UI::Card::Content.new(id: "my-content", data: { test_id: "c" })) { "x" }
|
|
30
29
|
assert_selector "div#my-content[data-test-id='c']"
|
|
31
30
|
end
|
|
32
|
-
|
|
33
|
-
# Content sits flush under a header, but needs its own top padding when it
|
|
34
|
-
# is the first thing in the card.
|
|
35
|
-
def test_content_first_in_a_card_gets_top_padding
|
|
36
|
-
render_inline(UI::Card::Content.new) { "Body" }
|
|
37
|
-
classes = page.find("div")[:class].split
|
|
38
|
-
assert_includes classes, "pt-0"
|
|
39
|
-
assert_includes classes, "first:pt-6"
|
|
40
|
-
end
|
|
41
31
|
end
|
|
@@ -16,8 +16,9 @@ class UI::Card::FooterTest < ViewComponent::TestCase
|
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
17
|
assert_includes classes, "flex"
|
|
18
18
|
assert_includes classes, "items-center"
|
|
19
|
-
assert_includes classes, "p-
|
|
20
|
-
assert_includes classes, "
|
|
19
|
+
assert_includes classes, "p-(--card-spacing)"
|
|
20
|
+
assert_includes classes, "border-t"
|
|
21
|
+
assert_includes classes, "bg-muted/50"
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def test_user_class_override
|
|
@@ -14,10 +14,9 @@ class UI::Card::HeaderTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Header.new) { "x" }
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
|
-
assert_includes classes, "
|
|
18
|
-
assert_includes classes, "
|
|
19
|
-
assert_includes classes, "
|
|
20
|
-
assert_includes classes, "p-6"
|
|
17
|
+
assert_includes classes, "grid"
|
|
18
|
+
assert_includes classes, "gap-1"
|
|
19
|
+
assert_includes classes, "px-(--card-spacing)"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def test_renders_with_title_slot
|
|
@@ -14,10 +14,9 @@ class UI::Card::TitleTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Title.new) { "x" }
|
|
16
16
|
classes = page.find("h3")[:class].split
|
|
17
|
-
assert_includes classes, "text-
|
|
18
|
-
assert_includes classes, "font-
|
|
19
|
-
assert_includes classes, "leading-
|
|
20
|
-
assert_includes classes, "tracking-tight"
|
|
17
|
+
assert_includes classes, "text-base"
|
|
18
|
+
assert_includes classes, "font-medium"
|
|
19
|
+
assert_includes classes, "leading-snug"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def test_user_class_override
|
|
@@ -15,10 +15,10 @@ class UI::CardTest < ViewComponent::TestCase
|
|
|
15
15
|
render_inline(UI::Card.new) { "x" }
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
17
|
assert_includes classes, "rounded-xl"
|
|
18
|
-
assert_includes classes, "
|
|
18
|
+
assert_includes classes, "ring-1"
|
|
19
19
|
assert_includes classes, "bg-card"
|
|
20
20
|
assert_includes classes, "text-card-foreground"
|
|
21
|
-
|
|
21
|
+
assert_not_includes classes, "overflow-hidden"
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def test_renders_with_header_slot
|
|
@@ -64,4 +64,65 @@ class UI::CardTest < ViewComponent::TestCase
|
|
|
64
64
|
render_inline(UI::Card.new(id: "my-card", data: { test_id: "card-x" })) { "x" }
|
|
65
65
|
assert_selector "div#my-card[data-test-id='card-x']"
|
|
66
66
|
end
|
|
67
|
+
|
|
68
|
+
def root = page.find("[data-slot='card']")
|
|
69
|
+
|
|
70
|
+
def test_size_and_spacing
|
|
71
|
+
render_inline(UI::Card.new) { "x" }
|
|
72
|
+
assert_equal "default", root["data-size"]
|
|
73
|
+
assert_includes root[:style], "--card-spacing: calc(var(--spacing) * 4)"
|
|
74
|
+
render_inline(UI::Card.new(size: :sm)) { "x" }
|
|
75
|
+
assert_equal "sm", root["data-size"]
|
|
76
|
+
assert_includes root[:style], "calc(var(--spacing) * 3)"
|
|
77
|
+
render_inline(UI::Card.new(size: :sm, spacing: 8)) { "x" }
|
|
78
|
+
assert_includes root[:style], "calc(var(--spacing) * 8)"
|
|
79
|
+
render_inline(UI::Card.new(size: :nonsense)) { "x" }
|
|
80
|
+
assert_equal "default", root["data-size"]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_keeps_the_apps_style_and_data
|
|
84
|
+
render_inline(UI::Card.new(style: "max-width: 10rem", data: { testid: "c" })) { "x" }
|
|
85
|
+
assert_includes root[:style], "max-width: 10rem"
|
|
86
|
+
assert_equal "c", root["data-testid"]
|
|
87
|
+
assert_equal "card", root["data-slot"]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_each_part_is_marked_so_the_card_can_lay_itself_out
|
|
91
|
+
render_inline(UI::Card.new) do |card|
|
|
92
|
+
card.with_header do |header|
|
|
93
|
+
header.with_title { "T" }
|
|
94
|
+
header.with_description { "D" }
|
|
95
|
+
header.with_action { "A" }
|
|
96
|
+
end
|
|
97
|
+
card.with_content { "C" }
|
|
98
|
+
card.with_footer { "F" }
|
|
99
|
+
end
|
|
100
|
+
assert_selector "[data-slot='card'] > [data-slot='card-header'] > h3[data-slot='card-title']", text: "T"
|
|
101
|
+
assert_selector "[data-slot='card-header'] > p[data-slot='card-description']", text: "D"
|
|
102
|
+
assert_selector "[data-slot='card-header'] > [data-slot='card-action']", text: "A"
|
|
103
|
+
assert_selector "[data-slot='card'] > [data-slot='card-content']", text: "C"
|
|
104
|
+
assert_selector "[data-slot='card'] > [data-slot='card-footer']", text: "F"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_image_comes_first_edge_to_edge
|
|
108
|
+
render_inline(UI::Card.new) do |card|
|
|
109
|
+
card.with_header { "H" }
|
|
110
|
+
card.with_image(src: "data:image/gif;base64,R0lGOD", alt: "A hill", class: "aspect-square")
|
|
111
|
+
end
|
|
112
|
+
image = page.find("[data-slot='card'] > img:first-child")
|
|
113
|
+
assert_equal "card-image", image["data-slot"]
|
|
114
|
+
assert_equal "A hill", image[:alt]
|
|
115
|
+
classes = image[:class].split
|
|
116
|
+
assert_includes classes, "rounded-t-xl"
|
|
117
|
+
assert_includes classes, "aspect-square"
|
|
118
|
+
assert_not_includes classes, "aspect-video"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_a_block_with_no_parts_has_no_part_styles_of_its_own
|
|
122
|
+
render_inline(UI::Card.new(class: "p-6")) { "<div>raw</div>".html_safe }
|
|
123
|
+
assert_no_selector "[data-slot='card'] > [data-slot^='card-']"
|
|
124
|
+
assert_includes root[:class].split, "p-6"
|
|
125
|
+
assert_not_includes root[:class].split, "flex"
|
|
126
|
+
assert_not_includes root[:class].split, "text-sm"
|
|
127
|
+
end
|
|
67
128
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::CarouselTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_carousel(**opts)
|
|
10
|
+
render_inline(UI::Carousel.new(label: "Highlights", **opts)) do |carousel|
|
|
11
|
+
carousel.with_item { "Coast" }
|
|
12
|
+
carousel.with_item { "Garden" }
|
|
13
|
+
carousel.with_item { "City" }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_a_named_region_of_snapping_items
|
|
18
|
+
render_carousel(item_class: "w-64")
|
|
19
|
+
region = page.find("[role=region][aria-roledescription=carousel][aria-label=Highlights][data-controller='ui--carousel']")
|
|
20
|
+
assert_includes region.find("ul")[:class], "snap-x"
|
|
21
|
+
assert_equal %w[Coast Garden City], page.all("ul li").map(&:text)
|
|
22
|
+
assert_includes page.all("ul li").first[:class], "w-64"
|
|
23
|
+
assert_includes page.all("ul li").first[:class], "snap-start"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_buttons_start_hidden_and_control_the_strip
|
|
27
|
+
render_carousel
|
|
28
|
+
track = page.find("ul")[:id]
|
|
29
|
+
assert_selector "button[aria-label=Previous][hidden][aria-controls='#{track}'][data-action='ui--carousel#previous']", visible: :all
|
|
30
|
+
assert_selector "button[aria-label=Next][hidden][aria-controls='#{track}'] svg[data-icon='chevron-right']", visible: :all
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_gap_class_and_attributes
|
|
34
|
+
render_carousel(gap: 6, class: "mt-4", id: "highlights")
|
|
35
|
+
assert_selector "#highlights.mt-4"
|
|
36
|
+
assert_includes page.find("ul")[:class], "gap-6"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -96,6 +96,26 @@ class UI::ChartTest < ViewComponent::TestCase
|
|
|
96
96
|
assert_selector "td", text: "41.5%", visible: :all
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def test_precision_sets_the_decimals
|
|
100
|
+
render_chart(format: :currency, precision: 0)
|
|
101
|
+
assert_equal [ "$1,200", "$1,501", "$900" ], config["series"].first["text"]
|
|
102
|
+
render_chart(precision: 1, series: [ { name: "Load", data: [ 1234.56, 2, 3 ] } ])
|
|
103
|
+
assert_selector "td", text: "1,234.6", visible: :all
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_show_data_false_keeps_the_table_for_screen_readers
|
|
107
|
+
render_chart(show_data: false)
|
|
108
|
+
assert_no_selector "details", visible: :all
|
|
109
|
+
assert_no_selector "summary", visible: :all
|
|
110
|
+
assert_selector "div.sr-only table td", text: "1,200", visible: :all
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_a_pie_sits_beside_its_legend_by_its_own_width
|
|
114
|
+
render_chart(type: :donut, series: [ { name: "Plan", data: [ 1, 2, 3 ] } ])
|
|
115
|
+
assert_includes page.find("[data-slot='chart']")[:class], "@container"
|
|
116
|
+
assert_selector "div.\\@md\\:flex-row"
|
|
117
|
+
end
|
|
118
|
+
|
|
99
119
|
def test_missing_values_leave_a_gap
|
|
100
120
|
render_chart(series: [ { name: "Sales", data: [ 1, nil, 3 ] } ])
|
|
101
121
|
assert_nil config["series"].first["data"][1]
|
|
@@ -77,7 +77,7 @@ class UI::CheckboxTest < ViewComponent::TestCase
|
|
|
77
77
|
def test_check_overlay_span_present_with_peer_checked_class
|
|
78
78
|
render_inline(UI::Checkbox.new(name: "test"))
|
|
79
79
|
wrapper = page.find(".relative.inline-flex")
|
|
80
|
-
overlay = wrapper.
|
|
80
|
+
overlay = wrapper.all("span.pointer-events-none").first
|
|
81
81
|
classes = overlay[:class].split
|
|
82
82
|
assert_includes classes, "peer-checked:opacity-100"
|
|
83
83
|
assert_includes classes, "opacity-0"
|
|
@@ -85,11 +85,20 @@ class UI::CheckboxTest < ViewComponent::TestCase
|
|
|
85
85
|
|
|
86
86
|
def test_check_icon_inside_overlay
|
|
87
87
|
render_inline(UI::Checkbox.new(name: "test"))
|
|
88
|
-
overlay = page.
|
|
88
|
+
overlay = page.all("span.pointer-events-none").first
|
|
89
89
|
icon = overlay.find("svg", visible: :all)
|
|
90
90
|
assert icon.matches_css?("[data-icon='check']")
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Script sets `indeterminate` on "select all" when some rows are chosen.
|
|
94
|
+
def test_a_partly_checked_box_shows_a_dash
|
|
95
|
+
render_inline(UI::Checkbox.new(name: "test"))
|
|
96
|
+
assert_includes page.find("input")[:class], "indeterminate:bg-primary"
|
|
97
|
+
dash = page.all("span.pointer-events-none").last
|
|
98
|
+
assert_includes dash[:class].split, "peer-indeterminate:opacity-100"
|
|
99
|
+
assert dash.find("svg", visible: :all).matches_css?("[data-icon='minus']")
|
|
100
|
+
end
|
|
101
|
+
|
|
93
102
|
def test_user_class_override_via_tailwind_merge
|
|
94
103
|
render_inline(UI::Checkbox.new(name: "test", class: "border-red-500"))
|
|
95
104
|
input = page.find("input[type='checkbox']")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::FieldsetTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
Settings = Struct.new(:channels) do
|
|
10
|
+
include ActiveModel::Validations
|
|
11
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Settings")
|
|
12
|
+
validates :channels, presence: true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def form_builder_for(record)
|
|
16
|
+
ActionView::Helpers::FormBuilder.new(:settings, record, vc_test_controller.view_context, {})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_renders_a_fieldset_named_by_its_legend
|
|
20
|
+
render_inline(UI::Fieldset.new(legend: "Notifications", id: "notify")) { "controls" }
|
|
21
|
+
assert_selector "fieldset#notify[aria-labelledby='notify-legend']", text: "controls"
|
|
22
|
+
assert_selector "fieldset > legend#notify-legend:first-child", text: "Notifications"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_hint_and_error_describe_the_group
|
|
26
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Change it any time.", error: "Choose a plan", id: "plan"))
|
|
27
|
+
assert_selector "fieldset[aria-describedby='plan-hint plan-error']"
|
|
28
|
+
assert_selector "p#plan-hint", text: "Change it any time."
|
|
29
|
+
assert_selector "p#plan-error.text-destructive", text: "Choose a plan"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_hint_comes_before_the_controls_and_the_error_after
|
|
33
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint", error: "Error")) { "<span>controls</span>".html_safe }
|
|
34
|
+
assert_equal %w[legend p span p], page.all("fieldset > *").map(&:tag_name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_makes_an_id_when_given_none
|
|
38
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint"))
|
|
39
|
+
id = page.find("fieldset")[:id]
|
|
40
|
+
assert id.start_with?("ui-fieldset-")
|
|
41
|
+
assert_selector "legend##{id}-legend"
|
|
42
|
+
assert_selector "p##{id}-hint"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_nothing_to_describe_means_no_aria_describedby
|
|
46
|
+
render_inline(UI::Fieldset.new(legend: "Plan"))
|
|
47
|
+
assert_no_selector "fieldset[aria-describedby]"
|
|
48
|
+
assert_no_selector "p"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_required_marks_the_legend
|
|
52
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true))
|
|
53
|
+
assert_selector "legend span.text-destructive", text: "*"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_disabled_disables_the_fieldset
|
|
57
|
+
render_inline(UI::Fieldset.new(legend: "Plan", disabled: true))
|
|
58
|
+
assert_selector "fieldset[disabled]"
|
|
59
|
+
assert_selector "legend.text-muted-foreground"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_a_plain_group_takes_no_required_or_invalid
|
|
63
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true, error: "Choose one"))
|
|
64
|
+
assert_no_selector "fieldset[aria-required]"
|
|
65
|
+
assert_no_selector "fieldset[aria-invalid]"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_a_radiogroup_is_required_and_invalid
|
|
69
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true, error: true, role: "radiogroup"))
|
|
70
|
+
assert_selector "fieldset[role='radiogroup'][aria-required='true'][aria-invalid='true']"
|
|
71
|
+
assert_no_selector "p.text-destructive"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_wrap_only_with_something_to_show
|
|
75
|
+
assert UI::Fieldset.new(legend: "Plan").wrap?
|
|
76
|
+
assert UI::Fieldset.new(legend: false, hint: "Hint").wrap?
|
|
77
|
+
assert UI::Fieldset.new(legend: false, error: "Error").wrap?
|
|
78
|
+
refute UI::Fieldset.new(legend: false).wrap?
|
|
79
|
+
refute UI::Fieldset.new.wrap?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_form_binding_names_it_and_shows_the_models_errors
|
|
83
|
+
render_inline(UI::Fieldset.new(form: form_builder_for(Settings.new([]).tap(&:validate)), field: :channels, id: "ch"))
|
|
84
|
+
assert_selector "legend", text: "Channels"
|
|
85
|
+
assert_selector "p#ch-error", text: "Channels can't be blank"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_legend_overrides_the_attribute_name_and_false_drops_it
|
|
89
|
+
form = form_builder_for(Settings.new([]))
|
|
90
|
+
render_inline(UI::Fieldset.new(form: form, field: :channels, legend: "Where to notify you"))
|
|
91
|
+
assert_selector "legend", text: "Where to notify you"
|
|
92
|
+
render_inline(UI::Fieldset.new(form: form, field: :channels, legend: false))
|
|
93
|
+
assert_no_selector "legend"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_user_class_and_attrs_pass_through
|
|
97
|
+
render_inline(UI::Fieldset.new(legend: "Plan", class: "gap-6", data: { testid: "plan" }, aria: { label: "Billing plan" }))
|
|
98
|
+
fieldset = page.find("fieldset[data-testid='plan'][aria-label='Billing plan']")
|
|
99
|
+
assert_includes fieldset[:class].split, "gap-6"
|
|
100
|
+
refute_includes fieldset[:class].split, "gap-3"
|
|
101
|
+
assert fieldset[:"aria-labelledby"].present?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_never_an_empty_legend
|
|
105
|
+
render_inline(UI::Fieldset.new(legend: true)) { "x" }
|
|
106
|
+
assert_no_selector "legend"
|
|
107
|
+
assert_no_selector "fieldset[aria-labelledby]"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_your_aria_describedby_adds_to_the_hint_and_error
|
|
111
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint", id: "plan", aria: { describedby: "terms" }))
|
|
112
|
+
assert_selector "fieldset[aria-describedby='plan-hint terms']"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_a_long_legend_has_room_to_wrap
|
|
116
|
+
render_inline(UI::Fieldset.new(legend: "Plan"))
|
|
117
|
+
assert_includes page.find("legend")[:class].split, "leading-snug"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -95,7 +95,7 @@ class UI::GalleryTest < ViewComponent::TestCase
|
|
|
95
95
|
render_gallery
|
|
96
96
|
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom in']", visible: :all
|
|
97
97
|
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom out']", visible: :all
|
|
98
|
-
assert_selector "dialog
|
|
98
|
+
assert_selector "dialog .end-4.top-4 button[aria-label='Close']", visible: :all
|
|
99
99
|
assert_selector "dialog button.start-4.top-1\\/2[aria-label='Previous image']", visible: :all
|
|
100
100
|
assert_selector "dialog button.end-4.top-1\\/2[aria-label='Next image']", visible: :all
|
|
101
101
|
end
|
|
@@ -175,18 +175,53 @@ class UI::GalleryTest < ViewComponent::TestCase
|
|
|
175
175
|
|
|
176
176
|
def test_buttons_keep_the_kits_focus_ring
|
|
177
177
|
render_gallery
|
|
178
|
-
assert_selector "button[aria-label='Show image 1'].focus\\:ring-primary"
|
|
179
|
-
assert_selector "button[aria-label='Next image'].focus\\:ring-primary", count: 1, visible: :all
|
|
178
|
+
assert_selector "button[aria-label='Show image 1'].focus-visible\\:ring-primary"
|
|
179
|
+
assert_selector "button[aria-label='Next image'].focus-visible\\:ring-primary", count: 1, visible: :all
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
def test_overlay_buttons_ring_in_white_to_show_on_the_dark_backdrop
|
|
183
183
|
render_gallery
|
|
184
|
-
assert_selector "dialog button[aria-label='Next image'].focus\\:ring-white", visible: :all
|
|
185
|
-
assert_selector "dialog button[aria-label='Close'].focus\\:ring-white", visible: :all
|
|
184
|
+
assert_selector "dialog button[aria-label='Next image'].focus-visible\\:ring-white", visible: :all
|
|
185
|
+
assert_selector "dialog button[aria-label='Close'].focus-visible\\:ring-white", visible: :all
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
def test_class_and_html_attributes_pass_through
|
|
189
189
|
render_gallery(class: "max-w-md", id: "photos", data: { foo: "bar" })
|
|
190
190
|
assert_selector "#photos.max-w-md[data-foo='bar'][data-controller='ui--gallery']"
|
|
191
191
|
end
|
|
192
|
+
|
|
193
|
+
def render_grid
|
|
194
|
+
render_inline(UI::Gallery.new(strip: false, label: "Photos")) do |gallery|
|
|
195
|
+
gallery.with_image(src: "/coast.jpg", alt: "Coast", zoom_src: "/coast-big.jpg") do |image|
|
|
196
|
+
image.with_info { "Taken in May" }
|
|
197
|
+
image.with_action { "<button>Favourite</button>".html_safe }
|
|
198
|
+
end
|
|
199
|
+
gallery.with_image(src: "/garden.jpg", alt: "Garden")
|
|
200
|
+
gallery.trigger(0, class: "aspect-square") { "<img src='/coast-sm.jpg' alt=''>".html_safe } +
|
|
201
|
+
gallery.trigger(1) { "<img src='/garden-sm.jpg' alt=''>".html_safe }
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def test_without_a_strip_the_page_opens_each_image
|
|
206
|
+
render_grid
|
|
207
|
+
assert_no_selector "[data-ui--gallery-target='track']", visible: :all
|
|
208
|
+
assert_no_selector "button[aria-label='Show image 1']", visible: :all
|
|
209
|
+
assert_selector "button.aspect-square[aria-label='Open Coast'][aria-haspopup=dialog][data-action='ui--gallery#open'][data-ui--gallery-index-param='0'][data-ui--gallery-target=trigger] img"
|
|
210
|
+
assert_selector "button[aria-label='Open Garden'][data-ui--gallery-index-param='1']"
|
|
211
|
+
assert_selector "li[data-ui--gallery-target=slide][data-zoom-src='/coast-big.jpg'][data-alt=Coast]", visible: :all
|
|
212
|
+
assert_selector "dialog button[aria-label='Next image']", visible: :all
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_info_and_actions_show_in_the_overlay_for_their_image
|
|
216
|
+
render_grid
|
|
217
|
+
toggle = page.find("dialog button[aria-label=Info][aria-expanded=false][data-action='ui--gallery#toggleInfo']", visible: :all)
|
|
218
|
+
panel = page.find("dialog aside##{toggle[:"aria-controls"]}[hidden]", visible: :all)
|
|
219
|
+
assert_equal "Taken in May", panel.find("[data-ui--gallery-target=perImage][data-index='0']", visible: :all).text(:all)
|
|
220
|
+
assert_selector "dialog [data-ui--gallery-target=perImage][data-index='0'] button", text: "Favourite", visible: :all
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_no_info_button_when_no_image_has_info
|
|
224
|
+
render_gallery
|
|
225
|
+
assert_no_selector "button[aria-label=Info]", visible: :all
|
|
226
|
+
end
|
|
192
227
|
end
|
|
@@ -43,7 +43,7 @@ class UI::LinkTest < ViewComponent::TestCase
|
|
|
43
43
|
link = page.find("a", text: "Delete")
|
|
44
44
|
classes = link[:class].split
|
|
45
45
|
assert_includes classes, "bg-destructive"
|
|
46
|
-
assert_includes classes, "focus:ring-destructive"
|
|
46
|
+
assert_includes classes, "focus-visible:ring-destructive"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def test_size_sm
|
|
@@ -47,7 +47,7 @@ class UI::NumberInputTest < ViewComponent::TestCase
|
|
|
47
47
|
|
|
48
48
|
def test_buttons_keep_the_kits_focus_ring
|
|
49
49
|
render_input
|
|
50
|
-
assert_selector "button.focus\\:ring-2.focus\\:ring-primary.focus\\:z-10", count: 2
|
|
50
|
+
assert_selector "button.focus-visible\\:ring-2.focus-visible\\:ring-primary.focus\\:z-10", count: 2
|
|
51
51
|
assert_no_selector "button.focus\\:ring-0"
|
|
52
52
|
assert_no_selector "[data-slot='input-group'].overflow-hidden"
|
|
53
53
|
end
|
|
@@ -136,4 +136,110 @@ class UI::RadioGroupTest < ViewComponent::TestCase
|
|
|
136
136
|
assert_includes classes, "peer"
|
|
137
137
|
assert_includes classes, "appearance-none"
|
|
138
138
|
end
|
|
139
|
+
|
|
140
|
+
Account = Struct.new(:plan, :seats) do
|
|
141
|
+
include ActiveModel::Validations
|
|
142
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Account")
|
|
143
|
+
validates :plan, presence: true
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def form_builder_for(record)
|
|
147
|
+
ActionView::Helpers::FormBuilder.new(:account, record, vc_test_controller.view_context, {})
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_a_legend_makes_the_fieldset_the_radiogroup
|
|
151
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", hint: "Change it any time.", required: true)) do |rg|
|
|
152
|
+
rg.with_item(value: "free", label: "Free")
|
|
153
|
+
end
|
|
154
|
+
fieldset = page.find("fieldset[role='radiogroup'][aria-required='true']")
|
|
155
|
+
assert_equal "#{fieldset[:id]}-legend", fieldset[:"aria-labelledby"]
|
|
156
|
+
assert_equal "#{fieldset[:id]}-hint", fieldset[:"aria-describedby"]
|
|
157
|
+
assert_selector "legend", text: "Plan"
|
|
158
|
+
assert_selector "[role='radiogroup']", count: 1
|
|
159
|
+
assert_selector "fieldset > div.flex-col input[type='radio'][name='plan'][required]"
|
|
160
|
+
assert_selector "span.text-destructive", text: "*", count: 1
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_without_a_legend_hint_or_error_it_is_unchanged
|
|
164
|
+
render_inline(UI::RadioGroup.new(name: "plan")) { |rg| rg.with_item(value: "free") }
|
|
165
|
+
assert_no_selector "fieldset"
|
|
166
|
+
assert_selector "div[role='radiogroup']"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_error_marks_the_group_invalid
|
|
170
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", error: "Choose a plan")) { |rg| rg.with_item(value: "free") }
|
|
171
|
+
fieldset = page.find("fieldset[aria-invalid='true']")
|
|
172
|
+
assert_selector "p##{fieldset[:id]}-error", text: "Choose a plan"
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_class_and_attrs_stay_on_the_radios_container
|
|
176
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", id: "plans", class: "flex-row", data: { testid: "plans" })) do |rg|
|
|
177
|
+
rg.with_item(value: "free")
|
|
178
|
+
end
|
|
179
|
+
assert_selector "fieldset > div#plans.flex-row[data-testid='plans']"
|
|
180
|
+
assert_no_selector "fieldset[data-testid]"
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_form_builder_names_and_values
|
|
184
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan)) do |rg|
|
|
185
|
+
rg.with_item(value: "free", label: "Free")
|
|
186
|
+
rg.with_item(value: "pro", label: "Pro")
|
|
187
|
+
end
|
|
188
|
+
assert_selector "input[name='account[plan]']", count: 2
|
|
189
|
+
assert page.find("input[value='pro']").checked?
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_values_compare_as_strings
|
|
193
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil, 5)), field: :seats)) do |rg|
|
|
194
|
+
rg.with_item(value: 5, label: "Five")
|
|
195
|
+
end
|
|
196
|
+
assert page.find("input[value='5']").checked?
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_a_bound_group_shows_the_models_error_without_growing_a_legend
|
|
200
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil).tap(&:validate)), field: :plan)) do |rg|
|
|
201
|
+
rg.with_item(value: "free", label: "Free")
|
|
202
|
+
end
|
|
203
|
+
assert_selector "fieldset[role='radiogroup'][aria-invalid='true']"
|
|
204
|
+
assert_selector "p.text-destructive", text: "Plan can't be blank"
|
|
205
|
+
assert_no_selector "legend"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_renders_no_whitespace_around_itself
|
|
209
|
+
render_inline(UI::RadioGroup.new(name: "plan")) { |rg| rg.with_item(value: "free") }
|
|
210
|
+
assert rendered_content.start_with?("<div"), rendered_content[0, 20].inspect
|
|
211
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan")) { |rg| rg.with_item(value: "free") }
|
|
212
|
+
assert rendered_content.start_with?("<fieldset"), rendered_content[0, 20].inspect
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_a_blank_legend_is_no_legend
|
|
216
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan, legend: "")) do |rg|
|
|
217
|
+
rg.with_item(value: "free")
|
|
218
|
+
end
|
|
219
|
+
assert_no_selector "fieldset"
|
|
220
|
+
assert_no_selector "legend"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_legend_true_uses_the_attribute_name
|
|
224
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan, legend: true)) do |rg|
|
|
225
|
+
rg.with_item(value: "free")
|
|
226
|
+
end
|
|
227
|
+
assert_selector "legend", text: "Plan"
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def test_your_aria_attributes_move_to_the_fieldset
|
|
231
|
+
render_inline(UI::RadioGroup.new(name: "plan", hint: "Change it any time.", aria: { label: "Billing plan" })) do |rg|
|
|
232
|
+
rg.with_item(value: "free")
|
|
233
|
+
end
|
|
234
|
+
assert_selector "fieldset[role='radiogroup'][aria-label='Billing plan']"
|
|
235
|
+
assert_no_selector "div[aria-label]"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def test_error_false_hides_the_models_error
|
|
239
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil).tap(&:validate)), field: :plan, error: false)) do |rg|
|
|
240
|
+
rg.with_item(value: "free")
|
|
241
|
+
end
|
|
242
|
+
assert_no_selector "fieldset"
|
|
243
|
+
assert_selector "div[role='radiogroup']"
|
|
244
|
+
end
|
|
139
245
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::ScrubberTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_scrubber(**opts)
|
|
10
|
+
render_inline(UI::Scrubber.new(label: "Jump to a date", for: "library", **opts)) do |scrubber|
|
|
11
|
+
scrubber.with_mark(href: "#2026-03", label: "March 2026", major: "2026")
|
|
12
|
+
scrubber.with_mark(href: "#2026-02", label: "February 2026")
|
|
13
|
+
scrubber.with_mark(href: "#2025-12", label: "December 2025", major: "2025")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_a_named_nav_watching_what_scrolls
|
|
18
|
+
render_scrubber
|
|
19
|
+
nav = page.find("nav[aria-label='Jump to a date'][data-controller='ui--scrubber']")
|
|
20
|
+
assert_equal "library", nav[:"data-ui--scrubber-for-value"]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_each_mark_links_to_its_heading_and_only_one_is_a_tab_stop
|
|
24
|
+
render_scrubber
|
|
25
|
+
marks = page.all("a[data-ui--scrubber-target=mark]", visible: :all)
|
|
26
|
+
assert_equal %w[#2026-03 #2026-02 #2025-12], marks.map { |mark| mark[:href] }
|
|
27
|
+
assert_equal [ "March 2026", "February 2026", "December 2025" ], marks.map { |mark| mark[:"aria-label"] }
|
|
28
|
+
assert_equal %w[0 -1 -1], marks.map { |mark| mark[:tabindex] }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_majors_show_their_text_and_the_rest_are_dots
|
|
32
|
+
render_scrubber
|
|
33
|
+
assert_selector "a[data-major=true]", text: "2026", visible: :all
|
|
34
|
+
assert_selector "a[data-major=false] span.rounded-full", visible: :all
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_the_rail_drags_and_the_tip_and_line_are_hidden_from_screen_readers
|
|
38
|
+
render_scrubber(class: "fixed end-0")
|
|
39
|
+
assert_selector "nav.fixed.end-0 [data-ui--scrubber-target=rail][data-action*='pointerdown->ui--scrubber#grab']"
|
|
40
|
+
assert_selector "[data-ui--scrubber-target=thumb][aria-hidden=true]", visible: :all
|
|
41
|
+
assert_selector "[data-ui--scrubber-target=tip][aria-hidden=true]", visible: :all
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -90,6 +90,27 @@ class UI::SelectTest < ViewComponent::TestCase
|
|
|
90
90
|
|
|
91
91
|
# --- label, states, sizes ---------------------------------------------
|
|
92
92
|
|
|
93
|
+
def test_aria_label_names_the_visible_button_not_the_hidden_select
|
|
94
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-label": "Sort by"))
|
|
95
|
+
assert_equal "Sort by", trigger["aria-label"]
|
|
96
|
+
assert_equal trigger[:id], listbox["aria-labelledby"]
|
|
97
|
+
assert_nil native["aria-label"]
|
|
98
|
+
assert_equal "true", native["aria-hidden"]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_the_aria_hash_names_the_button_too
|
|
102
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, aria: { label: "Sort by" }))
|
|
103
|
+
assert_equal "Sort by", trigger["aria-label"]
|
|
104
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-labelledby": "heading"))
|
|
105
|
+
assert_equal "heading", trigger["aria-labelledby"]
|
|
106
|
+
assert_nil native["aria-labelledby"]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_other_attributes_still_reach_the_native_select
|
|
110
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-label": "Sort by", data: { testid: "s" }))
|
|
111
|
+
assert_equal "s", native["data-testid"]
|
|
112
|
+
end
|
|
113
|
+
|
|
93
114
|
def test_label_is_associated_with_the_trigger
|
|
94
115
|
render_inline(UI::Select.new(name: "section", options: TEAMS, label: "Team"))
|
|
95
116
|
assert_equal trigger[:id], page.find("label")[:for]
|