velvetkit 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 +4 -4
- data/README.md +1 -1
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/file_field.html.erb +4 -0
- data/registry/app/components/ui/file_field.rb +73 -0
- data/registry/app/components/ui/session_tabs/add.html.erb +1 -0
- data/registry/app/components/ui/session_tabs/add.rb +52 -0
- data/registry/app/components/ui/session_tabs/tab.html.erb +37 -0
- data/registry/app/components/ui/session_tabs/tab.rb +243 -0
- data/registry/app/components/ui/session_tabs.html.erb +15 -0
- data/registry/app/components/ui/session_tabs.rb +101 -0
- data/registry/app/components/ui/skeleton.html.erb +1 -0
- data/registry/app/components/ui/skeleton.rb +30 -0
- data/registry/app/components/ui/toast/viewport.html.erb +4 -0
- data/registry/app/components/ui/toast/viewport.rb +41 -0
- data/registry/app/components/ui/toast.html.erb +11 -0
- data/registry/app/components/ui/toast.rb +89 -0
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +49 -0
- data/registry/app/javascript/controllers/ui/menu_controller.ts +3 -0
- data/registry/app/javascript/controllers/ui/session_tabs_controller.ts +732 -0
- data/registry/app/javascript/controllers/ui/toast_controller.ts +62 -0
- data/registry/app/javascript/controllers/ui/toast_viewport_controller.ts +82 -0
- data/registry/app/javascript/velvetkit_icons.ts +21 -9
- data/registry/components.yml +8 -0
- data/registry/config/locales/velvetkit.en.yml +19 -0
- data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +3 -0
- data/registry/test/components/previews/ui/file_field_preview/with_error.html.erb +3 -0
- data/registry/test/components/previews/ui/file_field_preview.rb +18 -0
- data/registry/test/components/previews/ui/session_tabs_preview/handling_events.html.erb +46 -0
- data/registry/test/components/previews/ui/session_tabs_preview/saved_views.html.erb +16 -0
- data/registry/test/components/previews/ui/session_tabs_preview/touch_with_confirmation.html.erb +20 -0
- data/registry/test/components/previews/ui/session_tabs_preview.rb +35 -0
- data/registry/test/components/previews/ui/skeleton_preview/card_placeholder.html.erb +10 -0
- data/registry/test/components/previews/ui/skeleton_preview/shapes.html.erb +9 -0
- data/registry/test/components/previews/ui/skeleton_preview.rb +15 -0
- data/registry/test/components/previews/ui/toast_preview/live_viewport.html.erb +21 -0
- data/registry/test/components/previews/ui/toast_preview/variants.html.erb +7 -0
- data/registry/test/components/previews/ui/toast_preview/with_action.html.erb +7 -0
- data/registry/test/components/previews/ui/toast_preview.rb +29 -0
- data/registry/test/components/ui/file_field_test.rb +101 -0
- data/registry/test/components/ui/session_tabs/add_test.rb +52 -0
- data/registry/test/components/ui/session_tabs_test.rb +281 -0
- data/registry/test/components/ui/skeleton_test.rb +65 -0
- data/registry/test/components/ui/toast/viewport_test.rb +72 -0
- data/registry/test/components/ui/toast_test.rb +183 -0
- metadata +39 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::SessionTabs::AddTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_with_add(size: :default, **opts)
|
|
10
|
+
render_inline(UI::SessionTabs.new(size: size)) do |tabs|
|
|
11
|
+
tabs.with_tab(value: "a", active: true) { "Alpha" }
|
|
12
|
+
tabs.with_add(**opts)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_without_url_is_an_event_button
|
|
17
|
+
render_with_add
|
|
18
|
+
button = page.find("button[aria-label='New tab']")
|
|
19
|
+
assert_equal "button", button[:type]
|
|
20
|
+
assert_includes button["data-action"], "click->ui--session-tabs#add"
|
|
21
|
+
assert_no_selector "form"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_with_url_posts_a_form
|
|
25
|
+
render_with_add(url: "/tabs")
|
|
26
|
+
form = page.find("form[action='/tabs']")
|
|
27
|
+
assert_equal "post", form[:method]
|
|
28
|
+
assert form.has_selector?("button[aria-label='New tab'][data-action~='click->ui--session-tabs#add']")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_custom_label
|
|
32
|
+
render_with_add(label: "New order")
|
|
33
|
+
assert_selector "button[aria-label='New order'][title='New order']"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_touch_size
|
|
37
|
+
render_with_add(size: :touch)
|
|
38
|
+
assert_includes page.find("button[aria-label='New tab']")[:class], "size-8"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_default_size_is_compact
|
|
42
|
+
render_with_add
|
|
43
|
+
assert_includes page.find("button[aria-label='New tab']")[:class], "size-7"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_keeps_user_action
|
|
47
|
+
render_with_add(data: { action: "click->analytics#track" })
|
|
48
|
+
action = page.find("button[aria-label='New tab']")["data-action"]
|
|
49
|
+
assert_includes action, "click->analytics#track"
|
|
50
|
+
assert_includes action, "click->ui--session-tabs#add"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::SessionTabsTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_tabs(**root_opts, &block)
|
|
10
|
+
render_inline(UI::SessionTabs.new(**root_opts)) do |tabs|
|
|
11
|
+
if block
|
|
12
|
+
block.call(tabs)
|
|
13
|
+
else
|
|
14
|
+
tabs.with_tab(value: "a", active: true, rename: true, close: true) { "Alpha" }
|
|
15
|
+
tabs.with_tab(value: "b", rename: true, close: true) { "Beta" }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_root_carries_controller_and_values
|
|
21
|
+
render_tabs(min_tabs: 2, return_focus: "#search", rename_param: "view[name]")
|
|
22
|
+
root = page.find("[data-controller~='ui--session-tabs']")
|
|
23
|
+
assert_equal "2", root["data-ui--session-tabs-min-tabs-value"]
|
|
24
|
+
assert_equal "#search", root["data-ui--session-tabs-return-focus-value"]
|
|
25
|
+
assert_equal "view[name]", root["data-ui--session-tabs-rename-param-value"]
|
|
26
|
+
assert_equal "Tab name", root["data-ui--session-tabs-rename-label-value"]
|
|
27
|
+
assert root[:id].start_with?("ui-session-tabs-")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_tablist_has_accessible_name
|
|
31
|
+
render_tabs(label: "Documents")
|
|
32
|
+
assert_selector "[role='tablist'][aria-label='Documents']"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_tablist_label_defaults_to_translation
|
|
36
|
+
render_tabs
|
|
37
|
+
assert_selector "[role='tablist'][aria-label='Open tabs']"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_tab_without_href_is_a_button
|
|
41
|
+
render_tabs
|
|
42
|
+
assert_selector "button[role='tab'][type='button']", text: "Alpha"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_tab_with_href_is_a_link
|
|
46
|
+
render_tabs do |t|
|
|
47
|
+
t.with_tab(value: "a", href: "/docs/a", active: true) { "Alpha" }
|
|
48
|
+
end
|
|
49
|
+
link = page.find("a[role='tab']")
|
|
50
|
+
assert_equal "/docs/a", link[:href]
|
|
51
|
+
assert_equal "page", link["aria-current"]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_active_state_and_roving_tabindex
|
|
55
|
+
render_tabs
|
|
56
|
+
active = page.find("[role='tab']", text: "Alpha")
|
|
57
|
+
inactive = page.find("[role='tab']", text: "Beta")
|
|
58
|
+
assert_equal "true", active["aria-selected"]
|
|
59
|
+
assert_equal "0", active[:tabindex]
|
|
60
|
+
assert_equal "false", inactive["aria-selected"]
|
|
61
|
+
assert_equal "-1", inactive[:tabindex]
|
|
62
|
+
assert_selector "[data-ui--session-tabs-target='tab'][data-value='a'][data-state='active']"
|
|
63
|
+
assert_selector "[data-ui--session-tabs-target='tab'][data-value='b'][data-state='inactive']"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_wrapper_is_presentation
|
|
67
|
+
render_tabs
|
|
68
|
+
assert_selector "[role='presentation'][data-ui--session-tabs-target='tab']", count: 2
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_tab_html_attrs_go_on_the_tab_element
|
|
72
|
+
render_tabs do |t|
|
|
73
|
+
t.with_tab(value: "a", href: "/a", data: { turbo_frame: "pane" }) { "Alpha" }
|
|
74
|
+
end
|
|
75
|
+
tab = page.find("a[role='tab']")
|
|
76
|
+
assert_equal "pane", tab["data-turbo-frame"]
|
|
77
|
+
assert_includes tab["data-action"], "click->ui--session-tabs#select"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_meta_slot
|
|
81
|
+
render_tabs do |t|
|
|
82
|
+
t.with_tab(value: "a") do |tab|
|
|
83
|
+
tab.with_meta { "3 items" }
|
|
84
|
+
"Alpha"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
assert_selector "[role='tab'] span", text: "3 items"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_no_menu_without_actions
|
|
91
|
+
render_tabs do |t|
|
|
92
|
+
t.with_tab(value: "a") { "Alpha" }
|
|
93
|
+
end
|
|
94
|
+
assert_no_selector "[data-controller~='ui--menu']"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_menu_items_follow_enabled_actions
|
|
98
|
+
render_tabs do |t|
|
|
99
|
+
t.with_tab(value: "a", rename: true) { "Alpha" }
|
|
100
|
+
t.with_tab(value: "b") { "Beta" }
|
|
101
|
+
end
|
|
102
|
+
assert_selector "[role='menuitem']", text: "Rename", visible: :all
|
|
103
|
+
assert_no_selector "[role='menuitem']", text: "Duplicate", visible: :all
|
|
104
|
+
assert_no_selector "[role='menuitem']", text: "Close", visible: :all
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_menu_trigger_is_labelled_by_tab
|
|
108
|
+
render_tabs
|
|
109
|
+
trigger = page.find("[data-ui--session-tabs-target='menuTrigger']", match: :first)
|
|
110
|
+
assert_equal "Tab options", trigger["aria-label"]
|
|
111
|
+
label_id = page.find("[data-ui--session-tabs-target='label']", text: "Alpha")[:id]
|
|
112
|
+
assert_equal label_id, trigger["aria-describedby"]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_action_urls_and_flags
|
|
116
|
+
render_tabs do |t|
|
|
117
|
+
t.with_tab(value: "a", rename: "/a/rename", duplicate: "/a/dup", move: true, close: "/a",
|
|
118
|
+
close_confirm: "Discard?") { "Alpha" }
|
|
119
|
+
t.with_tab(value: "b") { "Beta" }
|
|
120
|
+
end
|
|
121
|
+
tab = page.find("[data-value='a']")
|
|
122
|
+
assert_equal "/a/rename", tab["data-rename-url"]
|
|
123
|
+
assert_equal "/a/dup", tab["data-duplicate-url"]
|
|
124
|
+
assert_equal "/a", tab["data-close-url"]
|
|
125
|
+
assert_nil tab["data-move-url"]
|
|
126
|
+
assert_equal "true", tab["data-move-enabled"]
|
|
127
|
+
assert_equal "Discard?", tab["data-close-confirm"]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_menu_actions_are_wired
|
|
131
|
+
render_tabs do |t|
|
|
132
|
+
t.with_tab(value: "a", rename: true, duplicate: true, move: true, close: true) { "Alpha" }
|
|
133
|
+
t.with_tab(value: "b") { "Beta" }
|
|
134
|
+
end
|
|
135
|
+
%w[rename duplicate moveLeft moveRight close].each do |action|
|
|
136
|
+
assert_selector "[role='menuitem'][data-action='click->ui--session-tabs##{action}']", visible: :all
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_move_left_hidden_on_first_and_move_right_on_last
|
|
141
|
+
render_tabs do |t|
|
|
142
|
+
t.with_tab(value: "a", move: true) { "Alpha" }
|
|
143
|
+
t.with_tab(value: "b", move: true) { "Beta" }
|
|
144
|
+
end
|
|
145
|
+
first = page.find("[data-value='a']")
|
|
146
|
+
last = page.find("[data-value='b']")
|
|
147
|
+
assert first.has_selector?("[data-move='left'][hidden][data-disabled]", visible: :all)
|
|
148
|
+
assert first.has_selector?("[data-move='right']:not([hidden])", visible: :all)
|
|
149
|
+
assert last.has_selector?("[data-move='right'][hidden][data-disabled]", visible: :all)
|
|
150
|
+
assert last.has_selector?("[data-move='left']:not([hidden])", visible: :all)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_fixed_tab_is_never_passed
|
|
154
|
+
render_tabs do |t|
|
|
155
|
+
t.with_tab(value: "default") { "Default" }
|
|
156
|
+
t.with_tab(value: "a", move: true) { "Alpha" }
|
|
157
|
+
t.with_tab(value: "b", move: true) { "Beta" }
|
|
158
|
+
end
|
|
159
|
+
alpha = page.find("[data-value='a']")
|
|
160
|
+
assert alpha.has_selector?("[data-move='left'][hidden]", visible: :all)
|
|
161
|
+
assert_nil page.find("[data-value='default']")["data-move-enabled"]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def test_movable_tab_gets_a_drag_handle
|
|
165
|
+
render_tabs do |t|
|
|
166
|
+
t.with_tab(value: "a", move: true) { "Alpha" }
|
|
167
|
+
end
|
|
168
|
+
handle = page.find("[data-ui--session-tabs-target='handle']", visible: :all)
|
|
169
|
+
assert_equal "pointerdown->ui--session-tabs#dragStart", handle["data-action"]
|
|
170
|
+
assert_equal "true", handle["aria-hidden"]
|
|
171
|
+
assert_includes handle[:class], "touch-none"
|
|
172
|
+
assert handle.has_selector?("[data-lucide='grip-vertical']", visible: :all)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_controls_reveal_on_hover_and_slide_in
|
|
176
|
+
render_tabs do |t|
|
|
177
|
+
t.with_tab(value: "a", move: true, rename: true) { "Alpha" }
|
|
178
|
+
end
|
|
179
|
+
grip = page.find("[data-ui--session-tabs-target='handle'] [data-lucide]", visible: :all)[:class]
|
|
180
|
+
menu = page.find("[data-ui--session-tabs-target='menuTrigger']")[:class]
|
|
181
|
+
dots = page.find("[data-ui--session-tabs-target='menuTrigger'] [data-lucide]", visible: :all)[:class]
|
|
182
|
+
[ grip, menu ].each do |classes|
|
|
183
|
+
assert_includes classes, "opacity-0"
|
|
184
|
+
assert_includes classes, "group-hover/tab:opacity-100"
|
|
185
|
+
assert_includes classes, "group-focus-within/tab:opacity-100"
|
|
186
|
+
assert_includes classes, "[@media(hover:none)]:opacity-100"
|
|
187
|
+
end
|
|
188
|
+
assert_includes grip, "-translate-x-2"
|
|
189
|
+
assert_includes dots, "translate-x-2"
|
|
190
|
+
assert_includes dots, "group-hover/tab:translate-x-0"
|
|
191
|
+
assert_includes page.find("[data-value='a']")[:class], "hover:bg-primary/5"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def test_fixed_tab_has_no_handle
|
|
195
|
+
render_tabs do |t|
|
|
196
|
+
t.with_tab(value: "a", rename: true) { "Alpha" }
|
|
197
|
+
end
|
|
198
|
+
assert_no_selector "[data-ui--session-tabs-target='handle']", visible: :all
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def test_tab_body_is_draggable_but_not_natively
|
|
202
|
+
render_tabs do |t|
|
|
203
|
+
t.with_tab(value: "a", href: "/a", move: true) { "Alpha" }
|
|
204
|
+
end
|
|
205
|
+
tab = page.find("a[role='tab']")
|
|
206
|
+
assert_includes tab["data-action"], "pointerdown->ui--session-tabs#pressStart"
|
|
207
|
+
assert_equal "false", tab[:draggable]
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def test_menu_trigger_is_compact
|
|
211
|
+
render_tabs
|
|
212
|
+
assert_includes page.find("[data-ui--session-tabs-target='menuTrigger']", match: :first)[:class], "size-6"
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_close_hidden_at_min_tabs
|
|
216
|
+
render_tabs do |t|
|
|
217
|
+
t.with_tab(value: "a", close: true) { "Alpha" }
|
|
218
|
+
end
|
|
219
|
+
assert_selector "[role='menuitem'][data-close-part][hidden][data-disabled]", visible: :all
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def test_close_available_above_min_tabs
|
|
223
|
+
render_tabs
|
|
224
|
+
assert_selector "[role='menuitem'][data-close-part]:not([hidden])", visible: :all, count: 2
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def test_close_is_destructive_and_divided
|
|
228
|
+
render_tabs
|
|
229
|
+
item = page.find("[role='menuitem'][data-close-part]", match: :first, visible: :all)
|
|
230
|
+
assert_includes item[:class], "text-destructive"
|
|
231
|
+
assert_selector "[role='separator'][data-close-part]", visible: :all, count: 2
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_extra_menu_items
|
|
235
|
+
render_tabs do |t|
|
|
236
|
+
t.with_tab(value: "a", close: true) do |tab|
|
|
237
|
+
tab.with_menu_item("Pin", data: { action: "click->pins#toggle" })
|
|
238
|
+
"Alpha"
|
|
239
|
+
end
|
|
240
|
+
t.with_tab(value: "b") { "Beta" }
|
|
241
|
+
end
|
|
242
|
+
assert_selector "[role='menuitem'][data-action='click->pins#toggle']", text: "Pin", visible: :all
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def test_confirm_dialog_is_rendered_once
|
|
246
|
+
render_tabs
|
|
247
|
+
assert_selector "[data-ui--session-tabs-target='dialog'] dialog", count: 1, visible: :all
|
|
248
|
+
assert_selector "[data-ui--session-tabs-target='confirmMessage']", visible: :all
|
|
249
|
+
assert_selector "button[data-action='click->ui--session-tabs#confirmClose']", text: "Close tab", visible: :all
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def test_touch_size
|
|
253
|
+
render_tabs(size: :touch)
|
|
254
|
+
assert_includes page.find("[data-value='a']")[:class], "h-11"
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_default_size
|
|
258
|
+
render_tabs
|
|
259
|
+
assert_includes page.find("[data-value='a']")[:class], "h-9"
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def test_unknown_size_falls_back
|
|
263
|
+
render_tabs(size: :huge)
|
|
264
|
+
assert_includes page.find("[data-value='a']")[:class], "h-9"
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def test_user_class_and_attrs_on_root
|
|
268
|
+
render_tabs(class: "my-tabs", id: "doc-tabs", data: { turbo_permanent: true })
|
|
269
|
+
root = page.find("#doc-tabs")
|
|
270
|
+
assert_includes root[:class], "my-tabs"
|
|
271
|
+
assert_equal "ui--session-tabs", root["data-controller"]
|
|
272
|
+
assert_equal "true", root["data-turbo-permanent"]
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def test_values_with_spaces_get_safe_ids
|
|
276
|
+
render_tabs do |t|
|
|
277
|
+
t.with_tab(value: "Saved view 1") { "One" }
|
|
278
|
+
end
|
|
279
|
+
assert page.find("[role='tab']")[:id].end_with?("-tab-saved-view-1")
|
|
280
|
+
end
|
|
281
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::SkeletonTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def skeleton_el
|
|
10
|
+
page.find("div", visible: :all)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_renders_a_div
|
|
14
|
+
render_inline(UI::Skeleton.new)
|
|
15
|
+
assert skeleton_el.present?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_pulses_regardless_of_shape
|
|
19
|
+
render_inline(UI::Skeleton.new)
|
|
20
|
+
assert_includes skeleton_el[:class].split, "animate-pulse"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_hidden_from_screen_readers
|
|
24
|
+
render_inline(UI::Skeleton.new)
|
|
25
|
+
assert_equal "true", skeleton_el["aria-hidden"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_default_shape_is_text
|
|
29
|
+
render_inline(UI::Skeleton.new)
|
|
30
|
+
classes = skeleton_el[:class].split
|
|
31
|
+
assert_includes classes, "h-4"
|
|
32
|
+
assert_includes classes, "w-full"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_circle_shape
|
|
36
|
+
render_inline(UI::Skeleton.new(shape: :circle))
|
|
37
|
+
classes = skeleton_el[:class].split
|
|
38
|
+
assert_includes classes, "size-10"
|
|
39
|
+
assert_includes classes, "rounded-full"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_rectangle_shape
|
|
43
|
+
render_inline(UI::Skeleton.new(shape: :rectangle))
|
|
44
|
+
classes = skeleton_el[:class].split
|
|
45
|
+
assert_includes classes, "h-24"
|
|
46
|
+
assert_includes classes, "w-full"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_user_class_merge
|
|
50
|
+
render_inline(UI::Skeleton.new(class: "w-32"))
|
|
51
|
+
assert_includes skeleton_el[:class].split, "w-32"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_user_class_overrides_shape_sizing_via_tailwind_merge
|
|
55
|
+
render_inline(UI::Skeleton.new(shape: :text, class: "h-10"))
|
|
56
|
+
classes = skeleton_el[:class].split
|
|
57
|
+
assert_includes classes, "h-10"
|
|
58
|
+
refute_includes classes, "h-4"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_html_attrs_passthrough
|
|
62
|
+
render_inline(UI::Skeleton.new(id: "my-id", data: { test_id: "s" }))
|
|
63
|
+
assert_selector "div#my-id[data-test-id='s']"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::Toast::ViewportTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def viewport_el
|
|
10
|
+
page.find("##{UI::Toast::Viewport::ID}", visible: :all)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_renders_with_default_id
|
|
14
|
+
render_inline(UI::Toast::Viewport.new)
|
|
15
|
+
assert_equal "ui-toast-viewport", viewport_el["id"]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_renders_with_custom_id
|
|
19
|
+
render_inline(UI::Toast::Viewport.new(id: "my-toasts"))
|
|
20
|
+
assert page.has_css?("#my-toasts", visible: :all)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_default_position_is_bottom_right
|
|
24
|
+
render_inline(UI::Toast::Viewport.new)
|
|
25
|
+
classes = viewport_el[:class].split
|
|
26
|
+
assert_includes classes, "bottom-0"
|
|
27
|
+
assert_includes classes, "right-0"
|
|
28
|
+
assert_includes classes, "items-end"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_top_position_reverses_stack_order
|
|
32
|
+
render_inline(UI::Toast::Viewport.new(position: :top_right))
|
|
33
|
+
classes = viewport_el[:class].split
|
|
34
|
+
assert_includes classes, "top-0"
|
|
35
|
+
assert_includes classes, "flex-col-reverse"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_data_controller
|
|
39
|
+
render_inline(UI::Toast::Viewport.new)
|
|
40
|
+
assert_equal "ui--toast-viewport", viewport_el["data-controller"]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_renders_one_template_per_variant
|
|
44
|
+
render_inline(UI::Toast::Viewport.new)
|
|
45
|
+
templates = page.all("template[data-ui--toast-viewport-target='template']", visible: :all)
|
|
46
|
+
assert_equal UI::Toast::Viewport::VARIANTS.map(&:to_s).sort,
|
|
47
|
+
templates.map { |t| t["data-variant"] }.sort
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_templates_carry_title_and_description_targets
|
|
51
|
+
# Capybara's rack_test driver parses <template> as an ordinary element
|
|
52
|
+
# with no HTML5 content fragment, so its children never show up through
|
|
53
|
+
# Capybara/Nokogiri node traversal; assert on the raw markup instead.
|
|
54
|
+
html = render_inline(UI::Toast::Viewport.new).to_html
|
|
55
|
+
UI::Toast::Viewport::VARIANTS.each do |variant|
|
|
56
|
+
template_html = html[/<template[^>]*data-variant="#{variant}"[^>]*>(.*?)<\/template>/m, 1]
|
|
57
|
+
assert template_html, "no template found for #{variant}"
|
|
58
|
+
assert_includes template_html, "data-ui--toast-target=\"title\""
|
|
59
|
+
assert_includes template_html, "data-ui--toast-target=\"description\""
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_user_class_merge
|
|
64
|
+
render_inline(UI::Toast::Viewport.new(class: "my-viewport"))
|
|
65
|
+
assert_includes viewport_el[:class].split, "my-viewport"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_html_attrs_passthrough
|
|
69
|
+
render_inline(UI::Toast::Viewport.new(data: { test_id: "v" }))
|
|
70
|
+
assert_equal "v", viewport_el["data-test-id"]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::ToastTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def toast_el
|
|
10
|
+
page.find("[data-slot='toast']")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_renders_container
|
|
14
|
+
render_inline(UI::Toast.new(title: "Saved"))
|
|
15
|
+
assert toast_el.present?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_fill_mode_forwards_prevents_a_flash_before_removal
|
|
19
|
+
# tw-animate-css's animate-in/animate-out default to fill-mode: none, so
|
|
20
|
+
# without this the element snaps back to fully visible right as the exit
|
|
21
|
+
# animation ends, a flicker just before the controller removes it.
|
|
22
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
23
|
+
assert_includes toast_el[:class].split, "fill-mode-forwards"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_surface_is_neutral_regardless_of_variant
|
|
27
|
+
# Color lives on the icon only, not the surface — matching
|
|
28
|
+
# Dialog/Sheet/Popover/Menu rather than Alert's tinted banner.
|
|
29
|
+
%i[default success destructive warning info].each do |variant|
|
|
30
|
+
render_inline(UI::Toast.new(variant: variant, title: "x"))
|
|
31
|
+
classes = toast_el[:class].split
|
|
32
|
+
assert_includes classes, "bg-popover"
|
|
33
|
+
assert_includes classes, "text-popover-foreground"
|
|
34
|
+
refute classes.any? { |c| c.match?(/^(bg|border)-(emerald|amber|sky|destructive)/) },
|
|
35
|
+
"variant #{variant} colored something other than the icon"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_default_variant_classes
|
|
40
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
41
|
+
classes = toast_el[:class].split
|
|
42
|
+
assert_includes classes, "[&>i]:text-muted-foreground"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_success_variant_classes
|
|
46
|
+
render_inline(UI::Toast.new(variant: :success, title: "x"))
|
|
47
|
+
classes = toast_el[:class].split
|
|
48
|
+
assert_includes classes, "[&>i]:text-emerald-600"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_destructive_variant_classes
|
|
52
|
+
render_inline(UI::Toast.new(variant: :destructive, title: "x"))
|
|
53
|
+
classes = toast_el[:class].split
|
|
54
|
+
assert_includes classes, "[&>i]:text-destructive"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_warning_variant_classes
|
|
58
|
+
render_inline(UI::Toast.new(variant: :warning, title: "x"))
|
|
59
|
+
classes = toast_el[:class].split
|
|
60
|
+
assert_includes classes, "[&>i]:text-amber-600"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_info_variant_classes
|
|
64
|
+
render_inline(UI::Toast.new(variant: :info, title: "x"))
|
|
65
|
+
classes = toast_el[:class].split
|
|
66
|
+
assert_includes classes, "[&>i]:text-sky-600"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_default_icon_per_variant
|
|
70
|
+
{ default: "info", success: "circle-check", destructive: "circle-alert", warning: "circle-alert", info: "info" }
|
|
71
|
+
.each do |variant, icon|
|
|
72
|
+
render_inline(UI::Toast.new(variant: variant, title: "x"))
|
|
73
|
+
assert_selector "i[data-lucide='#{icon}']"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_icon_false_suppresses_icon
|
|
78
|
+
render_inline(UI::Toast.new(title: "x", icon: false))
|
|
79
|
+
refute_selector "[data-slot='toast'] > i"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_icon_override
|
|
83
|
+
render_inline(UI::Toast.new(title: "x", icon: "rocket"))
|
|
84
|
+
assert_selector "[data-slot='toast'] > i[data-lucide='rocket']"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_title_renders
|
|
88
|
+
render_inline(UI::Toast.new(title: "Saved"))
|
|
89
|
+
assert_selector "[data-ui--toast-target='title']", text: "Saved"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_description_renders
|
|
93
|
+
render_inline(UI::Toast.new(title: "Saved", description: "All set."))
|
|
94
|
+
assert_selector "[data-ui--toast-target='description']", text: "All set."
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_no_description_renders_no_description_node
|
|
98
|
+
render_inline(UI::Toast.new(title: "Saved"))
|
|
99
|
+
refute_selector "[data-ui--toast-target='description']"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_default_role_and_live_region
|
|
103
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
104
|
+
assert_equal "status", toast_el["role"]
|
|
105
|
+
assert_equal "polite", toast_el["aria-live"]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_destructive_role_and_live_region
|
|
109
|
+
render_inline(UI::Toast.new(variant: :destructive, title: "x"))
|
|
110
|
+
assert_equal "alert", toast_el["role"]
|
|
111
|
+
assert_equal "assertive", toast_el["aria-live"]
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_dismissible_by_default
|
|
115
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
116
|
+
assert_selector "button[aria-label='Dismiss']"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_dismissible_false_hides_close_button
|
|
120
|
+
render_inline(UI::Toast.new(title: "x", dismissible: false))
|
|
121
|
+
refute_selector "button[aria-label='Dismiss']"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_close_button_wired_to_controller
|
|
125
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
126
|
+
button = page.find("button[aria-label='Dismiss']")
|
|
127
|
+
assert_includes button["data-action"], "click->ui--toast#dismiss"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_data_controller
|
|
131
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
132
|
+
assert_equal "ui--toast", toast_el["data-controller"]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_default_duration_value_is_5_seconds_in_ms
|
|
136
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
137
|
+
assert_equal "5000", toast_el["data-ui--toast-duration-value"]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_custom_duration_value_is_given_in_seconds
|
|
141
|
+
render_inline(UI::Toast.new(title: "x", duration: 10))
|
|
142
|
+
assert_equal "10000", toast_el["data-ui--toast-duration-value"]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_duration_accepts_an_active_support_duration
|
|
146
|
+
render_inline(UI::Toast.new(title: "x", duration: 10.seconds))
|
|
147
|
+
assert_equal "10000", toast_el["data-ui--toast-duration-value"]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_persistent_duration_value
|
|
151
|
+
render_inline(UI::Toast.new(title: "x", duration: 0))
|
|
152
|
+
assert_equal "0", toast_el["data-ui--toast-duration-value"]
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def test_pause_and_resume_wired_on_hover
|
|
156
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
157
|
+
action = toast_el["data-action"]
|
|
158
|
+
assert_includes action, "mouseenter->ui--toast#pause"
|
|
159
|
+
assert_includes action, "mouseleave->ui--toast#resume"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def test_initial_state_is_open
|
|
163
|
+
render_inline(UI::Toast.new(title: "x"))
|
|
164
|
+
assert_equal "open", toast_el["data-state"]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def test_renders_action_slot
|
|
168
|
+
render_inline(UI::Toast.new(title: "x")) do |toast|
|
|
169
|
+
toast.with_action { "Undo" }
|
|
170
|
+
end
|
|
171
|
+
assert_selector "[data-slot='toast'] div", text: "Undo"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_user_class_merge
|
|
175
|
+
render_inline(UI::Toast.new(title: "x", class: "my-toast"))
|
|
176
|
+
assert_includes toast_el[:class].split, "my-toast"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def test_html_attrs_passthrough
|
|
180
|
+
render_inline(UI::Toast.new(title: "x", id: "my-id", data: { test_id: "t" }))
|
|
181
|
+
assert_selector "[data-slot='toast']#my-id[data-test-id='t']"
|
|
182
|
+
end
|
|
183
|
+
end
|