velvetkit 0.5.0 → 0.6.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 +63 -18
- 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/carousel.html.erb +9 -4
- data/registry/app/components/ui/carousel.rb +42 -1
- data/registry/app/components/ui/checkbox.rb +2 -2
- data/registry/app/components/ui/file_tree/file_item.html.erb +9 -0
- data/registry/app/components/ui/file_tree/file_item.rb +50 -0
- data/registry/app/components/ui/file_tree/folder.html.erb +9 -0
- data/registry/app/components/ui/file_tree/folder.rb +76 -0
- data/registry/app/components/ui/file_tree.html.erb +1 -0
- data/registry/app/components/ui/file_tree.rb +93 -0
- data/registry/app/components/ui/gallery.rb +4 -4
- 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.rb +1 -1
- data/registry/app/components/ui/rating.html.erb +16 -0
- data/registry/app/components/ui/rating.rb +200 -0
- data/registry/app/components/ui/sidebar/group_label.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_button.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_item.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_sub.rb +1 -1
- data/registry/app/components/ui/switch.rb +2 -2
- data/registry/app/components/ui/tabs/trigger.rb +1 -1
- data/registry/app/javascript/controllers/ui/carousel_controller.ts +59 -1
- data/registry/app/javascript/controllers/ui/file_tree_controller.ts +189 -0
- data/registry/app/javascript/controllers/ui/rating_controller.ts +117 -0
- data/registry/components.yml +4 -0
- data/registry/config/locales/velvetkit.en.yml +13 -0
- data/registry/test/components/previews/ui/carousel_preview/with_indicators.html.erb +10 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +7 -3
- data/registry/test/components/previews/ui/file_tree_preview/changes.html.erb +13 -0
- data/registry/test/components/previews/ui/file_tree_preview/from_data.html.erb +14 -0
- data/registry/test/components/previews/ui/file_tree_preview/picking_a_file.html.erb +25 -0
- data/registry/test/components/previews/ui/file_tree_preview/without_guides.html.erb +10 -0
- data/registry/test/components/previews/ui/file_tree_preview.rb +41 -0
- data/registry/test/components/previews/ui/image_preview/radii.html.erb +3 -3
- data/registry/test/components/previews/ui/image_preview/sizing.html.erb +9 -4
- data/registry/test/components/previews/ui/image_preview.rb +14 -1
- data/registry/test/components/previews/ui/rating_preview/in_form.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview/model_errors.html.erb +20 -0
- data/registry/test/components/previews/ui/rating_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/rating_preview/scores.html.erb +18 -0
- data/registry/test/components/previews/ui/rating_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview.rb +28 -0
- data/registry/test/components/ui/base_test.rb +27 -0
- data/registry/test/components/ui/button_test.rb +2 -2
- data/registry/test/components/ui/carousel_test.rb +48 -0
- data/registry/test/components/ui/confirm_dialog_test.rb +3 -0
- data/registry/test/components/ui/file_tree_test.rb +187 -0
- data/registry/test/components/ui/gallery_test.rb +4 -4
- 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/rating_test.rb +271 -0
- data/registry/test/components/ui/switch_test.rb +4 -4
- metadata +25 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::FileTreeTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_project(active: false, open: nil, **opts)
|
|
10
|
+
render_inline(UI::FileTree.new(**opts)) do |tree|
|
|
11
|
+
tree.with_folder(name: "app", open: open) do |app|
|
|
12
|
+
app.with_folder(name: "models") do |models|
|
|
13
|
+
models.with_file(name: "user.rb", href: "/blob/app/models/user.rb", active: active)
|
|
14
|
+
end
|
|
15
|
+
app.with_file(name: "application.rb", href: "/blob/app/application.rb")
|
|
16
|
+
end
|
|
17
|
+
tree.with_file(name: "README.md", href: "/blob/README.md")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_renders_a_labelled_tree_wired_to_its_controller
|
|
22
|
+
render_project
|
|
23
|
+
assert_selector "ul[role='tree'][aria-label='Files'][data-slot='file-tree'][data-controller='ui--file-tree']"
|
|
24
|
+
assert_selector "ul[role='tree'][data-action='click->ui--file-tree#click keydown->ui--file-tree#keydown']"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_label_names_the_tree
|
|
28
|
+
render_project(label: "Project files")
|
|
29
|
+
assert_selector "ul[role='tree'][aria-label='Project files']"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_rows_are_treeitems_in_the_order_given
|
|
33
|
+
render_project
|
|
34
|
+
assert_equal %w[app models user.rb application.rb README.md],
|
|
35
|
+
page.all("[role='treeitem']", visible: :all).map { |row| row["data-name"] }
|
|
36
|
+
assert_selector "li[role='none'] > [role='treeitem']", count: 5, visible: :all
|
|
37
|
+
assert_selector "[role='treeitem'][data-ui--file-tree-target='item']", count: 5, visible: :all
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_rows_carry_their_level
|
|
41
|
+
render_project
|
|
42
|
+
{ "app" => 1, "models" => 2, "user.rb" => 3, "application.rb" => 2, "README.md" => 1 }.each do |name, level|
|
|
43
|
+
assert_selector "[role='treeitem'][data-name='#{name}'][aria-level='#{level}']", visible: :all
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_only_the_first_row_is_in_the_tab_order
|
|
48
|
+
render_project
|
|
49
|
+
assert_selector "[role='treeitem'][tabindex='0']", count: 1
|
|
50
|
+
assert_selector "[role='treeitem'][data-name='app'][tabindex='0']"
|
|
51
|
+
assert_selector "[role='treeitem'][tabindex='-1']", count: 4, visible: :all
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_a_folder_owns_its_group
|
|
55
|
+
render_project
|
|
56
|
+
folder = page.find("[data-slot='file-tree-folder'][data-name='app']")
|
|
57
|
+
assert_selector "ul##{folder['aria-owns']}[role='group'][data-slot='file-tree-group']", visible: :all
|
|
58
|
+
assert_selector "ul##{folder['aria-owns']} > li > [data-name='models']", visible: :all
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_folders_start_closed
|
|
62
|
+
render_project
|
|
63
|
+
assert_selector "[data-name='app'][aria-expanded='false']"
|
|
64
|
+
assert_selector "ul[role='group'][hidden][data-state='closed']", count: 2, visible: :all
|
|
65
|
+
assert_no_selector "[data-name='README.md'][hidden]"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_an_open_folders_group_is_marked_open
|
|
69
|
+
render_project(open: true)
|
|
70
|
+
assert_selector "ul[role='group'][data-state='open']:not([hidden])", count: 1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_folders_holding_the_active_file_start_open
|
|
74
|
+
render_project(active: true)
|
|
75
|
+
assert_selector "[data-name='app'][aria-expanded='true']"
|
|
76
|
+
assert_selector "[data-name='models'][aria-expanded='true']"
|
|
77
|
+
assert_no_selector "ul[role='group'][hidden]", visible: :all
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_open_decides_over_the_active_file
|
|
81
|
+
render_project(active: true, open: false)
|
|
82
|
+
assert_selector "[data-name='app'][aria-expanded='false']"
|
|
83
|
+
render_project(open: true)
|
|
84
|
+
assert_selector "[data-name='app'][aria-expanded='true']"
|
|
85
|
+
assert_selector "[data-name='models'][aria-expanded='false']"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_a_file_with_an_href_is_a_link
|
|
89
|
+
render_project
|
|
90
|
+
assert_selector "a[role='treeitem'][href='/blob/README.md'][data-slot='file-tree-file']"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_the_active_link_is_the_current_page_and_selected
|
|
94
|
+
render_project(active: true)
|
|
95
|
+
assert_selector "a[data-name='user.rb'][aria-current='page'][aria-selected='true']"
|
|
96
|
+
assert_selector "a[data-name='README.md'][aria-selected='false']"
|
|
97
|
+
assert_no_selector "a[data-name='README.md'][aria-current]"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_a_file_without_an_href_is_a_row_to_pick
|
|
101
|
+
render_inline(UI::FileTree.new) do |tree|
|
|
102
|
+
tree.with_file(name: "notes.md", value: "docs/notes.md", active: true)
|
|
103
|
+
tree.with_file(name: "todo.md")
|
|
104
|
+
end
|
|
105
|
+
assert_selector "span[role='treeitem'][data-name='notes.md'][data-value='docs/notes.md'][aria-selected='true']"
|
|
106
|
+
assert_selector "span[role='treeitem'][data-name='todo.md'][data-value='todo.md'][aria-selected='false']"
|
|
107
|
+
assert_no_selector "[aria-current]"
|
|
108
|
+
assert_no_selector "a"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_folders_are_not_selectable
|
|
112
|
+
render_project
|
|
113
|
+
assert_no_selector "[data-slot='file-tree-folder'][aria-selected]", visible: :all
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_icons
|
|
117
|
+
render_project(active: true)
|
|
118
|
+
assert_selector "[data-name='app'] svg[data-icon='chevron-right']"
|
|
119
|
+
assert_selector "[data-name='app'] svg[data-icon='folder']"
|
|
120
|
+
assert_selector "[data-name='README.md'] svg[data-icon='file']"
|
|
121
|
+
assert_no_selector "[data-name='README.md'] svg[data-icon='chevron-right']"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_icon_swaps_the_icon
|
|
125
|
+
render_inline(UI::FileTree.new) do |tree|
|
|
126
|
+
tree.with_folder(name: "docs", icon: "book-open")
|
|
127
|
+
tree.with_file(name: "notes.md", icon: "file-text")
|
|
128
|
+
end
|
|
129
|
+
assert_selector "[data-name='docs'] svg[data-icon='book-open']"
|
|
130
|
+
assert_selector "[data-name='notes.md'] svg[data-icon='file-text']"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_a_files_block_shows_at_the_end_of_its_row
|
|
134
|
+
render_inline(UI::FileTree.new) { |tree| tree.with_file(name: "user.rb") { "M" } }
|
|
135
|
+
assert_selector "[data-name='user.rb'] > span:last-child", text: "M"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_guides_draw_a_line_down_open_folders
|
|
139
|
+
render_project
|
|
140
|
+
assert_selector "ul[role='group'].before\\:bg-border", count: 2, visible: :all
|
|
141
|
+
render_project(guides: false)
|
|
142
|
+
assert_no_selector "ul[role='group'].before\\:bg-border", visible: :all
|
|
143
|
+
assert_selector "ul[role='group'].ps-5\\.5", count: 2, visible: :all
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_a_guide_starts_below_its_folders_focus_ring
|
|
147
|
+
render_project
|
|
148
|
+
assert_selector "[data-slot='file-tree-folder'].peer\\/row + ul.peer-focus\\/row\\:before\\:top-1\\.5",
|
|
149
|
+
count: 2, visible: :all
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_builds_from_data
|
|
153
|
+
render_inline(UI::FileTree.new(items: [
|
|
154
|
+
{ name: "app", children: [
|
|
155
|
+
{ name: "models", children: [ { name: "user.rb", value: "app/models/user.rb", active: true } ] }
|
|
156
|
+
] },
|
|
157
|
+
{ "name" => "README.md", "href" => "/blob/README.md" }
|
|
158
|
+
]))
|
|
159
|
+
assert_equal %w[app models user.rb README.md], page.all("[role='treeitem']").map { |row| row["data-name"] }
|
|
160
|
+
assert_selector "[data-name='app'][aria-expanded='true']"
|
|
161
|
+
assert_selector "[data-name='user.rb'][aria-level='3'][aria-selected='true'][data-value='app/models/user.rb']"
|
|
162
|
+
assert_selector "a[data-name='README.md'][href='/blob/README.md']"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_an_empty_children_list_is_an_empty_folder
|
|
166
|
+
render_inline(UI::FileTree.new(items: [ { name: "tmp", children: [] } ]))
|
|
167
|
+
assert_selector "[data-slot='file-tree-folder'][data-name='tmp'][aria-expanded='false']"
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def test_data_and_slots_together
|
|
171
|
+
render_inline(UI::FileTree.new(items: [ { name: "Gemfile" } ])) { |tree| tree.with_file(name: "Rakefile") }
|
|
172
|
+
assert_equal %w[Gemfile Rakefile], page.all("[role='treeitem']").map { |row| row["data-name"] }
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_class_and_attributes_pass_through
|
|
176
|
+
render_inline(UI::FileTree.new(class: "max-w-xs", id: "files", data: { turbo: false }, aria: { describedby: "hint" })) do |tree|
|
|
177
|
+
tree.with_folder(name: "app", class: "font-semibold", id: "app-folder")
|
|
178
|
+
tree.with_file(name: "README.md", class: "italic", data: { turbo_frame: "blob" })
|
|
179
|
+
end
|
|
180
|
+
assert_selector "ul#files.max-w-xs[role='tree'][data-turbo='false'][aria-describedby='hint'][aria-label='Files']"
|
|
181
|
+
assert_selector "ul#files[data-controller='ui--file-tree']"
|
|
182
|
+
assert_selector "span.font-semibold[data-name='app']"
|
|
183
|
+
assert_selector "ul#app-folder-group[role='group']", visible: :all
|
|
184
|
+
assert_selector "[data-name='app'][aria-owns='app-folder-group']"
|
|
185
|
+
assert_selector "span.italic[data-name='README.md'][data-turbo-frame='blob'][data-ui--file-tree-target='item']"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
@@ -175,14 +175,14 @@ 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
|
|
179
|
-
assert_selector "button[aria-label='Next image'].focus
|
|
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
|
|
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
|
|
185
|
-
assert_selector "dialog button[aria-label='Close'].focus
|
|
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
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
def test_class_and_html_attributes_pass_through
|
|
@@ -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
|
|
46
|
+
assert_includes classes, "focus: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
|
|
50
|
+
assert_selector "button.focus\\:ring-2.focus\\: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
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::RatingTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
Review = Struct.new(:rating) do
|
|
10
|
+
include ActiveModel::Validations
|
|
11
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Review")
|
|
12
|
+
validates :rating, presence: true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def form_builder_for(record)
|
|
16
|
+
ActionView::Helpers::FormBuilder.new(:review, record, vc_test_controller.view_context, {})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# --- Shown ------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def test_shows_a_score_as_one_named_image
|
|
22
|
+
render_inline(UI::Rating.new(value: 4.5))
|
|
23
|
+
assert_selector "[role='img'][aria-label='Rated 4.5 out of 5']"
|
|
24
|
+
assert_no_selector "input"
|
|
25
|
+
assert_no_selector "[role='radiogroup']"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_fills_to_the_nearest_half_star
|
|
29
|
+
render_inline(UI::Rating.new(value: 3.7))
|
|
30
|
+
assert_selector "[role='img'] > svg.text-amber-500", count: 3
|
|
31
|
+
assert_selector "[role='img'] > span.relative", count: 1
|
|
32
|
+
assert_selector "[role='img'] > span.relative > span.w-1\\/2.overflow-hidden svg"
|
|
33
|
+
assert_selector "[role='img'] > svg.text-border.dark\\:text-muted", count: 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_rounds_to_whole_stars_when_closer
|
|
37
|
+
render_inline(UI::Rating.new(value: 4.2))
|
|
38
|
+
assert_selector "[role='img'] > svg.text-amber-500", count: 4
|
|
39
|
+
assert_no_selector "[role='img'] > span.relative"
|
|
40
|
+
assert_selector "[role='img'][aria-label='Rated 4.2 out of 5']"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_no_score_is_five_empty_stars
|
|
44
|
+
render_inline(UI::Rating.new)
|
|
45
|
+
assert_selector "[role='img'][aria-label='Rated 0 out of 5'] > svg.text-border.dark\\:text-muted", count: 5
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_a_score_out_of_range_is_held_to_it
|
|
49
|
+
render_inline(UI::Rating.new(value: 7))
|
|
50
|
+
assert_selector "[role='img'][aria-label='Rated 5 out of 5'] > svg.text-amber-500", count: 5
|
|
51
|
+
render_inline(UI::Rating.new(value: -2))
|
|
52
|
+
assert_selector "[role='img'][aria-label='Rated 0 out of 5']"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_a_score_given_as_a_string_or_decimal
|
|
56
|
+
render_inline(UI::Rating.new(value: "3.5"))
|
|
57
|
+
assert_selector "[role='img'][aria-label='Rated 3.5 out of 5']"
|
|
58
|
+
render_inline(UI::Rating.new(value: BigDecimal("4.0")))
|
|
59
|
+
assert_selector "[role='img'][aria-label='Rated 4 out of 5']"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_max_sets_how_many_stars
|
|
63
|
+
render_inline(UI::Rating.new(value: 7, max: 10))
|
|
64
|
+
assert_selector "[role='img'][aria-label='Rated 7 out of 10'] > svg", count: 10
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_the_value_and_count_beside_the_stars
|
|
68
|
+
render_inline(UI::Rating.new(value: 4.5, count: 1234, show_value: true))
|
|
69
|
+
assert_selector "span[aria-hidden='true'].tabular-nums", text: "4.5"
|
|
70
|
+
assert_selector "span[aria-hidden='true']", text: "(1,234)"
|
|
71
|
+
assert_selector "span.sr-only", text: "1234 ratings"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_one_rating_is_singular
|
|
75
|
+
render_inline(UI::Rating.new(value: 5, count: 1))
|
|
76
|
+
assert_selector "span.sr-only", text: "1 rating"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_neither_value_nor_count_by_default
|
|
80
|
+
render_inline(UI::Rating.new(value: 4))
|
|
81
|
+
assert_no_selector ".tabular-nums"
|
|
82
|
+
assert_no_selector ".sr-only"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_another_icon
|
|
86
|
+
render_inline(UI::Rating.new(value: 2, icon: "circle-check"))
|
|
87
|
+
assert_selector "svg[data-icon='circle-check']", count: 5
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_sizes
|
|
91
|
+
render_inline(UI::Rating.new(value: 2, size: :sm))
|
|
92
|
+
assert_includes page.find("[role='img']")[:class].split, "[&_svg]:size-4"
|
|
93
|
+
render_inline(UI::Rating.new(value: 2, size: :lg))
|
|
94
|
+
assert_includes page.find("[role='img']")[:class].split, "[&_svg]:size-6"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_class_and_attributes_on_the_shown_score
|
|
98
|
+
render_inline(UI::Rating.new(value: 4, class: "text-base", id: "score", data: { testid: "score" }))
|
|
99
|
+
score = page.find("span#score[data-testid='score']")
|
|
100
|
+
assert_includes score[:class].split, "text-base"
|
|
101
|
+
refute_includes score[:class].split, "text-sm"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# --- Chosen -----------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
def test_a_name_makes_it_a_radio_for_each_half_star
|
|
107
|
+
render_inline(UI::Rating.new(name: "review[rating]", id: "rate"))
|
|
108
|
+
assert_selector "div#rate[role='radiogroup'][aria-label='Rating'][data-controller='ui--rating']"
|
|
109
|
+
expected = %w[0.5 1 1.5 2 2.5 3 3.5 4 4.5 5]
|
|
110
|
+
actual = page.all("input[type='radio'][name='review[rating]']", visible: :all).map(&:value)
|
|
111
|
+
assert_equal expected, actual
|
|
112
|
+
assert_selector "label[for='rate-3'][data-ui--rating-target='star'] span.sr-only", text: "3 out of 5"
|
|
113
|
+
assert_no_selector "[role='img']"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_a_half_star_value_checks_its_option
|
|
117
|
+
render_inline(UI::Rating.new(name: "rating", value: 0.5))
|
|
118
|
+
assert_equal [ "0.5" ], page.all("input[checked]", visible: :all).map(&:value)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_a_fractional_value_checks_the_nearest_half_star
|
|
122
|
+
render_inline(UI::Rating.new(name: "rating", value: 3.6))
|
|
123
|
+
assert_equal [ "3.5" ], page.all("input[checked]", visible: :all).map(&:value)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_each_half_star_is_lit_by_css_up_to_the_checked_one
|
|
127
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
128
|
+
classes = page.find("label", match: :first)[:class].split
|
|
129
|
+
assert_includes classes, "[input:checked+&]:text-amber-500"
|
|
130
|
+
assert_includes classes, "[&:has(~input:checked)]:text-amber-500"
|
|
131
|
+
assert_includes classes, "data-[lit=true]:!text-amber-500"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# The stars draw no focus ring: the chosen score shows where the field is.
|
|
135
|
+
def test_a_half_star_draws_no_focus_ring
|
|
136
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
137
|
+
classes = page.find("label", match: :first)[:class].split
|
|
138
|
+
refute classes.any? { _1.include?("focus") || _1.include?("ring") || _1.include?("drop-shadow") }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Both halves of a hovered star grow from its middle, so it grows as one.
|
|
142
|
+
def test_a_hovered_star_grows_from_its_middle
|
|
143
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
144
|
+
start_half, end_half = page.all("label", minimum: 2).first(2).map { _1[:class].split }
|
|
145
|
+
assert_includes start_half, "motion-safe:data-[hovered=true]:scale-125"
|
|
146
|
+
assert_includes start_half, "origin-right"
|
|
147
|
+
assert_includes start_half, "rtl:origin-left"
|
|
148
|
+
assert_includes end_half, "origin-left"
|
|
149
|
+
assert_includes end_half, "rtl:origin-right"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_each_radio_sits_before_its_half_star
|
|
153
|
+
render_inline(UI::Rating.new(name: "rating", max: 3))
|
|
154
|
+
expected = Array.new(6) { %w[input label] }.flatten
|
|
155
|
+
actual = page.all("[role='radiogroup'] > *", visible: :all).map(&:tag_name)
|
|
156
|
+
assert_equal expected, actual
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_hover_reset_and_change_wiring
|
|
160
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
161
|
+
assert_selector "[data-action='mouseleave->ui--rating#reset reset@document->ui--rating#formReset']"
|
|
162
|
+
assert_selector "label[data-action='mouseenter->ui--rating#preview']", count: 10
|
|
163
|
+
assert_selector "input[data-action='change->ui--rating#choose']", count: 10, visible: :all
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_label_names_the_field
|
|
167
|
+
render_inline(UI::Rating.new(name: "rating", label: "Delivery"))
|
|
168
|
+
assert_selector "[role='radiogroup'][aria-label='Delivery']"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_required_and_disabled
|
|
172
|
+
render_inline(UI::Rating.new(name: "rating", required: true, disabled: true))
|
|
173
|
+
assert_selector "input[required][disabled]", count: 10, visible: :all
|
|
174
|
+
assert_selector "label.cursor-not-allowed.opacity-50", count: 10
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Choosing clears the error with JavaScript, so it needs the error's id.
|
|
178
|
+
def test_the_error_to_clear_once_chosen
|
|
179
|
+
render_inline(UI::Rating.new(name: "rating", legend: "Delivery", error: "Pick a score"))
|
|
180
|
+
error_id = page.find("fieldset p", text: "Pick a score")[:id]
|
|
181
|
+
assert_selector "[data-controller='ui--rating'][data-ui--rating-error-value='#{error_id}']"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def test_no_error_to_clear
|
|
185
|
+
render_inline(UI::Rating.new(name: "rating", legend: "Delivery"))
|
|
186
|
+
assert_no_selector "[data-ui--rating-error-value]"
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def test_a_field_shows_its_score_beside_the_stars
|
|
190
|
+
render_inline(UI::Rating.new(name: "rating", value: 3.5, show_value: true))
|
|
191
|
+
score = page.find("output[aria-hidden='true']", text: "3.5/5")
|
|
192
|
+
assert_selector "[data-ui--rating-score-value='#{score[:id]}']"
|
|
193
|
+
assert_selector "label[data-value='4'][data-score='4/5']"
|
|
194
|
+
assert_selector "label[data-value='4.5'][data-score='4.5/5']"
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_a_field_with_no_score_shows_zero
|
|
198
|
+
render_inline(UI::Rating.new(name: "rating", show_value: true))
|
|
199
|
+
assert_selector "output", text: "0/5"
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_a_field_shows_no_score_by_default
|
|
203
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
204
|
+
assert_no_selector "output"
|
|
205
|
+
assert_no_selector "[data-ui--rating-score-value]"
|
|
206
|
+
assert_no_selector "label[data-score]"
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_thanks_show_once_chosen
|
|
210
|
+
render_inline(UI::Rating.new(name: "rating", legend: "Delivery", thanks: true))
|
|
211
|
+
thanks = page.find("p[role='status'][hidden].text-emerald-600", text: "Thank you for your rating", visible: :all)
|
|
212
|
+
assert_selector "[data-ui--rating-thanks-value='#{thanks[:id]}']"
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_thanks_in_your_words
|
|
216
|
+
render_inline(UI::Rating.new(name: "rating", thanks: "Thanks, noted!"))
|
|
217
|
+
assert_selector "p[role='status']", text: "Thanks, noted!", visible: :all
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def test_no_thanks_by_default
|
|
221
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
222
|
+
assert_no_selector "p[role='status']", visible: :all
|
|
223
|
+
assert_no_selector "[data-ui--rating-thanks-value]"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def test_a_legend_renders_through_fieldset
|
|
227
|
+
render_inline(UI::Rating.new(name: "rating", legend: "Your rating", hint: "Out of five.", required: true, id: "r"))
|
|
228
|
+
fieldset = page.find("fieldset[role='radiogroup'][aria-required='true']")
|
|
229
|
+
assert fieldset[:"aria-labelledby"].present?
|
|
230
|
+
assert_nil fieldset[:"aria-label"]
|
|
231
|
+
assert_selector "legend", text: "Your rating"
|
|
232
|
+
assert_selector "fieldset > p", text: "Out of five."
|
|
233
|
+
assert_selector "fieldset > div#r:not([role])"
|
|
234
|
+
assert_equal 1, page.all("[role='radiogroup']").size
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def test_legend_true_without_a_form_still_names_it
|
|
238
|
+
render_inline(UI::Rating.new(name: "rating", legend: true, hint: "Out of five."))
|
|
239
|
+
assert_no_selector "legend"
|
|
240
|
+
assert_selector "fieldset[role='radiogroup'][aria-label='Rating']"
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_bound_to_a_form
|
|
244
|
+
render_inline(UI::Rating.new(form: form_builder_for(Review.new(4)), field: :rating))
|
|
245
|
+
assert_equal [ "4" ], page.all("input[name='review[rating]'][checked]", visible: :all).map(&:value)
|
|
246
|
+
assert_no_selector "fieldset"
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def test_bound_shows_the_models_errors_and_its_name
|
|
250
|
+
render_inline(UI::Rating.new(form: form_builder_for(Review.new(nil).tap(&:validate)), field: :rating, legend: true))
|
|
251
|
+
assert_selector "legend", text: "Rating"
|
|
252
|
+
assert_selector "fieldset[role='radiogroup'][aria-invalid='true']"
|
|
253
|
+
assert_selector "p.text-destructive", text: "Rating can't be blank"
|
|
254
|
+
assert_no_selector "input[checked]", visible: :all
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_class_and_attributes_on_the_stars
|
|
258
|
+
render_inline(UI::Rating.new(name: "rating", class: "gap-2", data: { testid: "stars" }))
|
|
259
|
+
stars = page.find("[role='radiogroup'][data-testid='stars'][data-controller='ui--rating']")
|
|
260
|
+
assert_includes stars[:class].split, "gap-2"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def test_renders_no_whitespace_around_itself
|
|
264
|
+
render_inline(UI::Rating.new(name: "rating"))
|
|
265
|
+
assert rendered_content.start_with?("<div"), rendered_content[0, 20].inspect
|
|
266
|
+
render_inline(UI::Rating.new(name: "rating", legend: "Rating"))
|
|
267
|
+
assert rendered_content.start_with?("<fieldset"), rendered_content[0, 20].inspect
|
|
268
|
+
render_inline(UI::Rating.new(value: 3))
|
|
269
|
+
assert rendered_content.start_with?("<span"), rendered_content[0, 20].inspect
|
|
270
|
+
end
|
|
271
|
+
end
|
|
@@ -87,12 +87,12 @@ class UI::SwitchTest < ViewComponent::TestCase
|
|
|
87
87
|
def test_track_span_has_focus_ring_via_peer_focus_visible
|
|
88
88
|
render_inline(UI::Switch.new(name: "notify"))
|
|
89
89
|
track = page.all("span", visible: :all).find { |s|
|
|
90
|
-
s[:class].to_s.include?("peer-focus
|
|
90
|
+
s[:class].to_s.include?("peer-focus:ring-2")
|
|
91
91
|
}
|
|
92
|
-
assert track, "track span with peer-focus
|
|
92
|
+
assert track, "track span with peer-focus:ring-2 should exist"
|
|
93
93
|
classes = track[:class].split
|
|
94
|
-
assert_includes classes, "peer-focus
|
|
95
|
-
assert_includes classes, "peer-focus
|
|
94
|
+
assert_includes classes, "peer-focus:ring-primary"
|
|
95
|
+
assert_includes classes, "peer-focus:ring-offset-1"
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
# ── Thumb ────────────────────────────────────────────────────────────────────
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: velvetkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rathan Kumar
|
|
@@ -149,6 +149,12 @@ files:
|
|
|
149
149
|
- registry/app/components/ui/fieldset.rb
|
|
150
150
|
- registry/app/components/ui/file_field.html.erb
|
|
151
151
|
- registry/app/components/ui/file_field.rb
|
|
152
|
+
- registry/app/components/ui/file_tree.html.erb
|
|
153
|
+
- registry/app/components/ui/file_tree.rb
|
|
154
|
+
- registry/app/components/ui/file_tree/file_item.html.erb
|
|
155
|
+
- registry/app/components/ui/file_tree/file_item.rb
|
|
156
|
+
- registry/app/components/ui/file_tree/folder.html.erb
|
|
157
|
+
- registry/app/components/ui/file_tree/folder.rb
|
|
152
158
|
- registry/app/components/ui/form_field.html.erb
|
|
153
159
|
- registry/app/components/ui/form_field.rb
|
|
154
160
|
- registry/app/components/ui/form_field/messages.html.erb
|
|
@@ -216,6 +222,8 @@ files:
|
|
|
216
222
|
- registry/app/components/ui/radio_group.rb
|
|
217
223
|
- registry/app/components/ui/radio_group/item.html.erb
|
|
218
224
|
- registry/app/components/ui/radio_group/item.rb
|
|
225
|
+
- registry/app/components/ui/rating.html.erb
|
|
226
|
+
- registry/app/components/ui/rating.rb
|
|
219
227
|
- registry/app/components/ui/scan_input.html.erb
|
|
220
228
|
- registry/app/components/ui/scan_input.rb
|
|
221
229
|
- registry/app/components/ui/scrubber.html.erb
|
|
@@ -348,6 +356,7 @@ files:
|
|
|
348
356
|
- registry/app/javascript/controllers/ui/date_picker_controller.ts
|
|
349
357
|
- registry/app/javascript/controllers/ui/dialog_controller.ts
|
|
350
358
|
- registry/app/javascript/controllers/ui/file_field_controller.ts
|
|
359
|
+
- registry/app/javascript/controllers/ui/file_tree_controller.ts
|
|
351
360
|
- registry/app/javascript/controllers/ui/gallery_controller.ts
|
|
352
361
|
- registry/app/javascript/controllers/ui/kbd_controller.ts
|
|
353
362
|
- registry/app/javascript/controllers/ui/menu_controller.ts
|
|
@@ -357,6 +366,7 @@ files:
|
|
|
357
366
|
- registry/app/javascript/controllers/ui/password_visibility_controller.ts
|
|
358
367
|
- registry/app/javascript/controllers/ui/popover_controller.ts
|
|
359
368
|
- registry/app/javascript/controllers/ui/progress_controller.ts
|
|
369
|
+
- registry/app/javascript/controllers/ui/rating_controller.ts
|
|
360
370
|
- registry/app/javascript/controllers/ui/scan_input_controller.ts
|
|
361
371
|
- registry/app/javascript/controllers/ui/scrubber_controller.ts
|
|
362
372
|
- registry/app/javascript/controllers/ui/select_controller.ts
|
|
@@ -703,6 +713,7 @@ files:
|
|
|
703
713
|
- registry/test/components/previews/ui/card_preview/team.html.erb
|
|
704
714
|
- registry/test/components/previews/ui/carousel_preview.rb
|
|
705
715
|
- registry/test/components/previews/ui/carousel_preview/highlights.html.erb
|
|
716
|
+
- registry/test/components/previews/ui/carousel_preview/with_indicators.html.erb
|
|
706
717
|
- registry/test/components/previews/ui/chart_preview.rb
|
|
707
718
|
- registry/test/components/previews/ui/chart_preview/cash_flow.html.erb
|
|
708
719
|
- registry/test/components/previews/ui/chart_preview/donut.html.erb
|
|
@@ -770,6 +781,11 @@ files:
|
|
|
770
781
|
- registry/test/components/previews/ui/file_field_preview/product_photos.html.erb
|
|
771
782
|
- registry/test/components/previews/ui/file_field_preview/single_image.html.erb
|
|
772
783
|
- registry/test/components/previews/ui/file_field_preview/with_error.html.erb
|
|
784
|
+
- registry/test/components/previews/ui/file_tree_preview.rb
|
|
785
|
+
- registry/test/components/previews/ui/file_tree_preview/changes.html.erb
|
|
786
|
+
- registry/test/components/previews/ui/file_tree_preview/from_data.html.erb
|
|
787
|
+
- registry/test/components/previews/ui/file_tree_preview/picking_a_file.html.erb
|
|
788
|
+
- registry/test/components/previews/ui/file_tree_preview/without_guides.html.erb
|
|
773
789
|
- registry/test/components/previews/ui/form_field_preview.rb
|
|
774
790
|
- registry/test/components/previews/ui/form_field_preview/custom_control.html.erb
|
|
775
791
|
- registry/test/components/previews/ui/form_field_preview/default.html.erb
|
|
@@ -857,6 +873,12 @@ files:
|
|
|
857
873
|
- registry/test/components/previews/ui/radio_group_preview/default.html.erb
|
|
858
874
|
- registry/test/components/previews/ui/radio_group_preview/disabled.html.erb
|
|
859
875
|
- registry/test/components/previews/ui/radio_group_preview/with_required.html.erb
|
|
876
|
+
- registry/test/components/previews/ui/rating_preview.rb
|
|
877
|
+
- registry/test/components/previews/ui/rating_preview/in_form.html.erb
|
|
878
|
+
- registry/test/components/previews/ui/rating_preview/model_errors.html.erb
|
|
879
|
+
- registry/test/components/previews/ui/rating_preview/playground.html.erb
|
|
880
|
+
- registry/test/components/previews/ui/rating_preview/scores.html.erb
|
|
881
|
+
- registry/test/components/previews/ui/rating_preview/sizes.html.erb
|
|
860
882
|
- registry/test/components/previews/ui/scan_input_preview.rb
|
|
861
883
|
- registry/test/components/previews/ui/scan_input_preview/_simulate.html.erb
|
|
862
884
|
- registry/test/components/previews/ui/scan_input_preview/library_checkout.html.erb
|
|
@@ -1023,6 +1045,7 @@ files:
|
|
|
1023
1045
|
- registry/test/components/ui/empty_state_test.rb
|
|
1024
1046
|
- registry/test/components/ui/fieldset_test.rb
|
|
1025
1047
|
- registry/test/components/ui/file_field_test.rb
|
|
1048
|
+
- registry/test/components/ui/file_tree_test.rb
|
|
1026
1049
|
- registry/test/components/ui/form_field/messages_test.rb
|
|
1027
1050
|
- registry/test/components/ui/form_field_test.rb
|
|
1028
1051
|
- registry/test/components/ui/gallery_test.rb
|
|
@@ -1052,6 +1075,7 @@ files:
|
|
|
1052
1075
|
- registry/test/components/ui/progress_test.rb
|
|
1053
1076
|
- registry/test/components/ui/radio_group/item_test.rb
|
|
1054
1077
|
- registry/test/components/ui/radio_group_test.rb
|
|
1078
|
+
- registry/test/components/ui/rating_test.rb
|
|
1055
1079
|
- registry/test/components/ui/scan_input_test.rb
|
|
1056
1080
|
- registry/test/components/ui/scrubber_test.rb
|
|
1057
1081
|
- registry/test/components/ui/select_test.rb
|