velvetkit 0.3.0 → 0.4.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 +80 -0
- data/README.md +5 -1
- data/lib/generators/velvetkit/add/add_generator.rb +58 -0
- data/lib/velvetkit/version.rb +4 -1
- data/lib/velvetkit.rb +7 -0
- data/registry/app/assets/tailwind/velvetkit.css +90 -155
- data/registry/app/components/ui/chart.html.erb +47 -0
- data/registry/app/components/ui/chart.rb +177 -0
- data/registry/app/components/ui/command/group.rb +27 -0
- data/registry/app/components/ui/command/item.rb +64 -0
- data/registry/app/components/ui/command.html.erb +41 -0
- data/registry/app/components/ui/command.rb +122 -0
- data/registry/app/components/ui/date_picker.html.erb +58 -64
- data/registry/app/components/ui/date_picker.rb +199 -75
- data/registry/app/components/ui/file_field.html.erb +14 -4
- data/registry/app/components/ui/file_field.rb +179 -28
- data/registry/app/components/ui/gallery/image.rb +20 -0
- data/registry/app/components/ui/gallery.html.erb +52 -0
- data/registry/app/components/ui/gallery.rb +164 -0
- data/registry/app/components/ui/kbd.html.erb +27 -0
- data/registry/app/components/ui/kbd.rb +134 -0
- data/registry/app/components/ui/number_input.html.erb +11 -0
- data/registry/app/components/ui/number_input.rb +103 -0
- data/registry/app/components/ui/progress/segment.rb +25 -0
- data/registry/app/components/ui/progress.html.erb +25 -0
- data/registry/app/components/ui/progress.rb +182 -0
- data/registry/app/components/ui/select.html.erb +24 -5
- data/registry/app/components/ui/select.rb +44 -5
- data/registry/app/components/ui/timeline/item.html.erb +21 -0
- data/registry/app/components/ui/timeline/item.rb +145 -0
- data/registry/app/components/ui/timeline.html.erb +1 -0
- data/registry/app/components/ui/timeline.rb +42 -0
- data/registry/app/javascript/chart_js.ts +37 -0
- data/registry/app/javascript/controllers/ui/_internal/date_format.ts +74 -0
- data/registry/app/javascript/controllers/ui/_internal/shortcut.ts +80 -0
- data/registry/app/javascript/controllers/ui/chart_controller.ts +585 -0
- data/registry/app/javascript/controllers/ui/command_controller.ts +454 -0
- data/registry/app/javascript/controllers/ui/date_picker_controller.ts +247 -82
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +288 -16
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +568 -0
- data/registry/app/javascript/controllers/ui/kbd_controller.ts +60 -0
- data/registry/app/javascript/controllers/ui/number_input_controller.ts +111 -0
- data/registry/app/javascript/controllers/ui/progress_controller.ts +87 -0
- data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
- data/registry/app/javascript/vanilla_calendar.ts +15 -0
- data/registry/components.yml +19 -3
- data/registry/config/locales/velvetkit.en.yml +73 -0
- data/registry/icons/lucide/download.svg +17 -0
- data/registry/icons/lucide/file-plus.svg +18 -0
- data/registry/icons/lucide/file.svg +16 -0
- data/registry/icons/lucide/folder.svg +15 -0
- data/registry/icons/lucide/keyboard.svg +23 -0
- data/registry/icons/lucide/minus.svg +15 -0
- data/registry/icons/lucide/package.svg +18 -0
- data/registry/icons/lucide/pause.svg +16 -0
- data/registry/icons/lucide/percent.svg +17 -0
- data/registry/icons/lucide/printer.svg +17 -0
- data/registry/icons/lucide/receipt.svg +17 -0
- data/registry/icons/lucide/sun-moon.svg +19 -0
- data/registry/icons/lucide/truck.svg +19 -0
- data/registry/icons/lucide/user-plus.svg +18 -0
- data/registry/icons/lucide/zoom-in.svg +18 -0
- data/registry/icons/lucide/zoom-out.svg +17 -0
- data/registry/icons/phosphor/circle-half.svg +2 -0
- data/registry/icons/phosphor/download-simple.svg +2 -0
- data/registry/icons/phosphor/file-plus.svg +2 -0
- data/registry/icons/phosphor/file.svg +2 -0
- data/registry/icons/phosphor/folder.svg +2 -0
- data/registry/icons/phosphor/keyboard.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-minus.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-plus.svg +2 -0
- data/registry/icons/phosphor/minus.svg +2 -0
- data/registry/icons/phosphor/package.svg +2 -0
- data/registry/icons/phosphor/pause.svg +2 -0
- data/registry/icons/phosphor/percent.svg +2 -0
- data/registry/icons/phosphor/printer.svg +2 -0
- data/registry/icons/phosphor/receipt.svg +2 -0
- data/registry/icons/phosphor/truck.svg +2 -0
- data/registry/icons/phosphor/user-plus.svg +2 -0
- data/registry/icons/tabler/download.svg +18 -0
- data/registry/icons/tabler/file-plus.svg +19 -0
- data/registry/icons/tabler/file.svg +17 -0
- data/registry/icons/tabler/folder.svg +16 -0
- data/registry/icons/tabler/keyboard.svg +23 -0
- data/registry/icons/tabler/minus.svg +16 -0
- data/registry/icons/tabler/package.svg +20 -0
- data/registry/icons/tabler/percentage.svg +18 -0
- data/registry/icons/tabler/player-pause.svg +17 -0
- data/registry/icons/tabler/printer.svg +18 -0
- data/registry/icons/tabler/receipt.svg +16 -0
- data/registry/icons/tabler/sun-moon.svg +21 -0
- data/registry/icons/tabler/truck.svg +18 -0
- data/registry/icons/tabler/user-plus.svg +19 -0
- data/registry/icons/tabler/zoom-in.svg +19 -0
- data/registry/icons/tabler/zoom-out.svg +18 -0
- data/registry/icons.yml +16 -0
- data/registry/test/components/previews/ui/chart_preview/cash_flow.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/donut.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/margin.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/pie.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/sales.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/stock.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/takings.html.erb +8 -0
- data/registry/test/components/previews/ui/chart_preview.rb +46 -0
- data/registry/test/components/previews/ui/command_preview/_picked.html.erb +14 -0
- data/registry/test/components/previews/ui/command_preview/dialog.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/inline.html.erb +16 -0
- data/registry/test/components/previews/ui/command_preview/playground.html.erb +15 -0
- data/registry/test/components/previews/ui/command_preview/server_search.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/shortcuts.html.erb +12 -0
- data/registry/test/components/previews/ui/command_preview/till.html.erb +17 -0
- data/registry/test/components/previews/ui/command_preview.rb +25 -0
- data/registry/test/components/previews/ui/date_picker_preview/custom_presets.html.erb +6 -0
- data/registry/test/components/previews/ui/date_picker_preview/in_form.html.erb +11 -0
- data/registry/test/components/previews/ui/date_picker_preview/range.html.erb +5 -0
- data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +4 -3
- data/registry/test/components/previews/ui/date_picker_preview.rb +26 -6
- data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +1 -1
- data/registry/test/components/previews/ui/file_field_preview/product_photos.html.erb +12 -0
- data/registry/test/components/previews/ui/file_field_preview/single_image.html.erb +4 -0
- data/registry/test/components/previews/ui/file_field_preview.rb +32 -5
- data/registry/test/components/previews/ui/gallery_preview/hover_zoom.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/landscape.html.erb +5 -0
- data/registry/test/components/previews/ui/gallery_preview/product_page.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/single.html.erb +3 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +45 -0
- data/registry/test/components/previews/ui/kbd_preview/bound.html.erb +20 -0
- data/registry/test/components/previews/ui/kbd_preview/keys.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/menu.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/search_field.html.erb +8 -0
- data/registry/test/components/previews/ui/kbd_preview/shortcuts_list.html.erb +17 -0
- data/registry/test/components/previews/ui/kbd_preview/till.html.erb +23 -0
- data/registry/test/components/previews/ui/kbd_preview/tooltip_and_buttons.html.erb +14 -0
- data/registry/test/components/previews/ui/kbd_preview.rb +32 -0
- data/registry/test/components/previews/ui/number_input_preview/cart.html.erb +11 -0
- data/registry/test/components/previews/ui/number_input_preview/decimals.html.erb +4 -0
- data/registry/test/components/previews/ui/number_input_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/number_input_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/number_input_preview/stock_adjustment.html.erb +3 -0
- data/registry/test/components/previews/ui/number_input_preview.rb +36 -0
- data/registry/test/components/previews/ui/progress_preview/file_upload.html.erb +36 -0
- data/registry/test/components/previews/ui/progress_preview/free_shipping.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/indeterminate.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/sizes_and_tones.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/steps.html.erb +9 -0
- data/registry/test/components/previews/ui/progress_preview/storage.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/storage_by_category.html.erb +7 -0
- data/registry/test/components/previews/ui/progress_preview/tasks_by_status.html.erb +14 -0
- data/registry/test/components/previews/ui/progress_preview/traffic_by_source.html.erb +15 -0
- data/registry/test/components/previews/ui/progress_preview.rb +46 -0
- data/registry/test/components/previews/ui/select_preview/server_search.html.erb +22 -0
- data/registry/test/components/previews/ui/select_preview.rb +5 -0
- data/registry/test/components/previews/ui/timeline_preview/activity_log.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored_by_meaning.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/failed_delivery.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview/order_status.html.erb +9 -0
- data/registry/test/components/previews/ui/timeline_preview/real_dates.html.erb +5 -0
- data/registry/test/components/previews/ui/timeline_preview/stock_history.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview.rb +40 -0
- data/registry/test/components/ui/chart_test.rb +187 -0
- data/registry/test/components/ui/command/group_test.rb +19 -0
- data/registry/test/components/ui/command/item_test.rb +47 -0
- data/registry/test/components/ui/command_test.rb +110 -0
- data/registry/test/components/ui/date_picker_test.rb +129 -111
- data/registry/test/components/ui/file_field_test.rb +105 -9
- data/registry/test/components/ui/gallery_test.rb +192 -0
- data/registry/test/components/ui/kbd_test.rb +150 -0
- data/registry/test/components/ui/number_input_test.rb +155 -0
- data/registry/test/components/ui/progress_test.rb +188 -0
- data/registry/test/components/ui/select_test.rb +62 -0
- data/registry/test/components/ui/timeline_test.rb +175 -0
- metadata +147 -2
- data/registry/app/javascript/cally.ts +0 -8
|
@@ -7,176 +7,194 @@ class UI::DatePickerTest < ViewComponent::TestCase
|
|
|
7
7
|
def teardown_fixtures(*); end
|
|
8
8
|
|
|
9
9
|
def render_picker(**options)
|
|
10
|
-
render_inline(UI::DatePicker.new(**
|
|
10
|
+
render_inline(UI::DatePicker.new(**options))
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def typed = page.find("input[type='text']")
|
|
14
|
-
def hidden = page.find("input[type='hidden']", visible: :all)
|
|
15
13
|
def root = page.find("div[data-controller='ui--date-picker']")
|
|
14
|
+
def typed = page.all("input[data-ui--date-picker-target='field']")
|
|
15
|
+
def hidden(name) = page.find("input[type='hidden'][name='#{name}']", visible: :all)
|
|
16
|
+
def presets = page.all("button[data-ui--date-picker-target='preset']", visible: :all)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
def with_format(format)
|
|
19
|
+
original = I18n.backend.translate(:en, "date.formats.typed")
|
|
20
|
+
I18n.backend.store_translations(:en, date: { formats: { typed: format } })
|
|
21
|
+
yield
|
|
22
|
+
ensure
|
|
23
|
+
I18n.backend.store_translations(:en, date: { formats: { typed: original } })
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# ── A single date ─────────────────────────────────────────────────────────
|
|
18
27
|
|
|
19
|
-
# The typed field carries no name, so a half-typed date can never reach the
|
|
20
|
-
# server: only the hidden ISO field is submitted.
|
|
21
28
|
def test_only_the_hidden_field_is_submitted
|
|
22
|
-
render_picker
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
render_picker(name: "event[date]", value: Date.new(2026, 8, 15))
|
|
30
|
+
assert_equal "2026-08-15", hidden("event[date]").value
|
|
31
|
+
assert_nil typed.first[:name]
|
|
25
32
|
end
|
|
26
33
|
|
|
27
|
-
def
|
|
28
|
-
render_picker(
|
|
29
|
-
assert_equal "
|
|
30
|
-
assert_equal "
|
|
34
|
+
def test_the_typed_field_shows_the_locale_format
|
|
35
|
+
render_picker(name: "d", value: "2026-08-15")
|
|
36
|
+
assert_equal "15/08/2026", typed.first.value
|
|
37
|
+
assert_equal "dd/mm/yyyy", typed.first[:placeholder]
|
|
38
|
+
assert_equal "10", typed.first[:maxlength]
|
|
39
|
+
assert_equal "numeric", typed.first[:inputmode]
|
|
31
40
|
end
|
|
32
41
|
|
|
33
42
|
def test_both_fields_are_empty_without_a_value
|
|
34
|
-
render_picker
|
|
35
|
-
assert_equal "", typed
|
|
36
|
-
assert_equal "", hidden
|
|
43
|
+
render_picker(name: "d")
|
|
44
|
+
assert_equal "", typed.first.value.to_s
|
|
45
|
+
assert_equal "", hidden("d").value.to_s
|
|
37
46
|
end
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
render_picker
|
|
46
|
-
assert_equal "DD/MM/YYYY", typed[:placeholder]
|
|
48
|
+
def test_the_field_opens_the_calendar_on_focus_and_click
|
|
49
|
+
render_picker(name: "d")
|
|
50
|
+
action = typed.first["data-action"]
|
|
51
|
+
assert_includes action, "focus->ui--date-picker#open"
|
|
52
|
+
assert_includes action, "click->ui--date-picker#open"
|
|
53
|
+
assert_includes action, "input->ui--date-picker#typed"
|
|
47
54
|
end
|
|
48
55
|
|
|
49
|
-
def
|
|
50
|
-
render_picker
|
|
56
|
+
def test_order_and_separator_come_from_the_locale_format
|
|
57
|
+
render_picker(name: "d")
|
|
51
58
|
assert_equal "DMY", root["data-ui--date-picker-order-value"]
|
|
52
59
|
assert_equal "/", root["data-ui--date-picker-separator-value"]
|
|
53
60
|
end
|
|
54
61
|
|
|
55
|
-
# A locale that writes dates the other way round changes all three together
|
|
56
|
-
# and needs no change here.
|
|
57
62
|
def test_a_different_locale_format_changes_the_placeholder_and_the_parser
|
|
58
63
|
with_format("%m-%d-%Y") do
|
|
59
|
-
render_picker(
|
|
60
|
-
assert_equal "
|
|
64
|
+
render_picker(name: "d", value: "2026-08-15")
|
|
65
|
+
assert_equal "mm-dd-yyyy", typed.first[:placeholder]
|
|
66
|
+
assert_equal "08-15-2026", typed.first.value
|
|
61
67
|
assert_equal "MDY", root["data-ui--date-picker-order-value"]
|
|
62
68
|
assert_equal "-", root["data-ui--date-picker-separator-value"]
|
|
63
|
-
assert_equal "05-02-2012", typed[:value]
|
|
64
69
|
end
|
|
65
70
|
end
|
|
66
71
|
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
def test_the_calendar_loads_with_its_stylesheet_and_starts_hidden
|
|
73
|
+
render_picker(name: "d", min: Date.new(2026, 1, 1), max: "2026-12-31")
|
|
74
|
+
assert_match(/vanilla_calendar.*\.js\z/, root["data-ui--date-picker-module-url-value"])
|
|
75
|
+
assert_match(/vanilla_calendar.*\.css\z/, root["data-ui--date-picker-style-url-value"])
|
|
76
|
+
assert_equal "2026-01-01", root["data-ui--date-picker-min-value"]
|
|
77
|
+
assert_equal "2026-12-31", root["data-ui--date-picker-max-value"]
|
|
78
|
+
assert_selector "[role='dialog'][hidden] .velvetkit-calendar > [data-ui--date-picker-target='calendar']", visible: :all
|
|
79
|
+
assert_selector "button[aria-haspopup='dialog'][aria-expanded='false'][aria-label='Open the calendar']"
|
|
73
80
|
end
|
|
74
81
|
|
|
75
|
-
|
|
82
|
+
def test_a_single_date_has_no_presets_or_range_prompt
|
|
83
|
+
render_picker(name: "d")
|
|
84
|
+
assert_empty presets
|
|
85
|
+
assert_no_selector "[data-ui--date-picker-target='status']", visible: :all
|
|
86
|
+
assert_equal "false", root["data-ui--date-picker-range-value"]
|
|
87
|
+
end
|
|
76
88
|
|
|
77
|
-
|
|
89
|
+
def test_clear_shows_only_with_a_value_that_can_be_emptied
|
|
90
|
+
render_picker(name: "d")
|
|
91
|
+
assert_selector "button[aria-label='Clear'][hidden]", visible: :all
|
|
92
|
+
render_picker(name: "d", value: "2026-08-15")
|
|
93
|
+
assert_selector "button[aria-label='Clear']:not([hidden])"
|
|
94
|
+
render_picker(name: "d", value: "2026-08-15", required: true)
|
|
95
|
+
assert_selector "button[aria-label='Clear'][hidden]", visible: :all
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
Holiday = Struct.new(:starts_on) do
|
|
78
99
|
def self.human_attribute_name(name, *) = name.to_s.humanize
|
|
79
100
|
def to_model = self
|
|
80
101
|
def model_name = ActiveModel::Name.new(self.class, nil, "Holiday")
|
|
81
102
|
def persisted? = false
|
|
82
103
|
end
|
|
83
104
|
|
|
84
|
-
def
|
|
85
|
-
ActionView::Helpers::FormBuilder.new(:holiday, record, vc_test_controller.view_context, {})
|
|
86
|
-
end
|
|
105
|
+
def builder(record) = ActionView::Helpers::FormBuilder.new(:holiday, record, vc_test_controller.view_context, {})
|
|
87
106
|
|
|
88
|
-
def
|
|
89
|
-
|
|
90
|
-
assert_equal "
|
|
91
|
-
|
|
92
|
-
assert_equal "15/08/2026", typed[:value]
|
|
107
|
+
def test_form_binding_names_the_hidden_field_reads_the_value_and_derives_the_label
|
|
108
|
+
render_picker(form: builder(Holiday.new(Date.new(2026, 8, 15))), field: :starts_on)
|
|
109
|
+
assert_equal "2026-08-15", hidden("holiday[starts_on]").value
|
|
110
|
+
assert_selector "label[for='#{typed.first[:id]}']", text: "Starts on"
|
|
93
111
|
end
|
|
94
112
|
|
|
95
|
-
def
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
113
|
+
def test_required_marks_the_field_and_the_label
|
|
114
|
+
render_picker(name: "d", label: "Date", required: true)
|
|
115
|
+
assert typed.first[:required]
|
|
116
|
+
assert_selector "label span", text: "*"
|
|
99
117
|
end
|
|
100
118
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
def test_the_hint_explains_the_format_and_can_be_turned_off
|
|
120
|
+
render_picker(name: "d")
|
|
121
|
+
assert_text "Type the date as dd/mm/yyyy"
|
|
122
|
+
assert_includes typed.first["aria-describedby"], "-hint"
|
|
123
|
+
render_picker(name: "d", hint: false)
|
|
124
|
+
assert_no_text "Type the date as"
|
|
106
125
|
end
|
|
107
126
|
|
|
108
|
-
def
|
|
109
|
-
render_picker(
|
|
110
|
-
|
|
127
|
+
def test_error_message_shows_and_describes_the_field
|
|
128
|
+
render_picker(name: "d", error: "Too early")
|
|
129
|
+
assert_text "Too early"
|
|
130
|
+
assert_equal "true", typed.first["aria-invalid"]
|
|
131
|
+
assert_includes typed.first["aria-describedby"], page.find("p", text: "Too early")[:id]
|
|
111
132
|
end
|
|
112
133
|
|
|
113
|
-
|
|
114
|
-
render_picker(min: "2026-04-01", max: "2027-03-31")
|
|
115
|
-
calendar = page.find("calendar-date", visible: :all)
|
|
116
|
-
assert_equal "2026-04-01", calendar[:min]
|
|
117
|
-
assert_equal "2027-03-31", calendar[:max]
|
|
118
|
-
end
|
|
134
|
+
# ── A range ───────────────────────────────────────────────────────────────
|
|
119
135
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
136
|
+
def test_a_range_submits_from_and_to_as_iso
|
|
137
|
+
render_picker(range: true, from: Date.new(2026, 11, 1), to: "2026-11-30")
|
|
138
|
+
assert_equal "2026-11-01", hidden("from").value
|
|
139
|
+
assert_equal "2026-11-30", hidden("to").value
|
|
140
|
+
assert_equal %w[01/11/2026 30/11/2026], typed.map(&:value)
|
|
141
|
+
assert_equal [ "Start date", "End date" ], typed.map { _1["aria-label"] }
|
|
142
|
+
assert_equal "true", root["data-ui--date-picker-range-value"]
|
|
126
143
|
end
|
|
127
144
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
assert_selector "p", text: "DD/MM/YYYY"
|
|
134
|
-
assert_equal "#{typed[:id]}-hint", typed["aria-describedby"]
|
|
145
|
+
def test_a_range_can_rename_its_fields
|
|
146
|
+
render_picker(range: true, from_name: "period[start]", to_name: "period[end]")
|
|
147
|
+
assert hidden("period[start]")
|
|
148
|
+
assert hidden("period[end]")
|
|
149
|
+
end
|
|
135
150
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
151
|
+
Report = Struct.new(:starts_on, :ends_on) do
|
|
152
|
+
def to_model = self
|
|
153
|
+
def model_name = ActiveModel::Name.new(self.class, nil, "Report")
|
|
154
|
+
def persisted? = false
|
|
139
155
|
end
|
|
140
156
|
|
|
141
|
-
def
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
assert_equal "
|
|
145
|
-
assert_equal
|
|
157
|
+
def test_a_range_binds_to_a_form
|
|
158
|
+
form = ActionView::Helpers::FormBuilder.new(:report, Report.new(Date.new(2026, 4, 1), Date.new(2027, 3, 31)), vc_test_controller.view_context, {})
|
|
159
|
+
render_picker(range: true, form: form, from_field: :starts_on, to_field: :ends_on)
|
|
160
|
+
assert_equal "2026-04-01", hidden("report[starts_on]").value
|
|
161
|
+
assert_equal "2027-03-31", hidden("report[ends_on]").value
|
|
146
162
|
end
|
|
147
163
|
|
|
148
|
-
|
|
164
|
+
def test_a_range_says_to_pick_an_end_date_after_the_first
|
|
165
|
+
render_picker(range: true)
|
|
166
|
+
assert_selector "[data-ui--date-picker-target='status'][role='status']", visible: :all
|
|
167
|
+
assert_includes JSON.parse(root["data-ui--date-picker-labels-value"])["pickEnd"], "end date"
|
|
168
|
+
end
|
|
149
169
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
def test_range_presets_are_worked_out_from_today
|
|
171
|
+
travel_to(Date.new(2026, 11, 6)) do
|
|
172
|
+
render_picker(range: true)
|
|
173
|
+
by_label = presets.to_h { |b| [ b.text, [ b["data-ui--date-picker-from-param"], b["data-ui--date-picker-to-param"] ] ] }
|
|
174
|
+
assert_equal %w[2026-11-06 2026-11-06], by_label["Today"]
|
|
175
|
+
assert_equal %w[2026-10-31 2026-11-06], by_label["Last 7 days"]
|
|
176
|
+
assert_equal %w[2026-11-01 2026-11-06], by_label["This month"]
|
|
177
|
+
assert_equal %w[2026-10-01 2026-10-31], by_label["Last month"]
|
|
178
|
+
assert_equal %w[2026-01-01 2026-11-06], by_label["This year"]
|
|
179
|
+
end
|
|
157
180
|
end
|
|
158
181
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
arrow = page.find("calendar-date [slot='#{slot}']", visible: :all)
|
|
164
|
-
refute_equal "button", arrow.tag_name
|
|
165
|
-
assert_includes arrow.text(:all), I18n.t(key)
|
|
182
|
+
def test_the_preset_matching_the_range_is_pressed
|
|
183
|
+
travel_to(Date.new(2026, 11, 6)) do
|
|
184
|
+
render_picker(range: true, from: "2026-11-01", to: "2026-11-06")
|
|
185
|
+
assert_equal [ "This month" ], presets.select { _1["aria-pressed"] == "true" }.map(&:text)
|
|
166
186
|
end
|
|
167
187
|
end
|
|
168
188
|
|
|
169
|
-
def
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
def test_range_presets_can_be_replaced_or_left_out
|
|
190
|
+
render_picker(range: true, presets: [ [ "Q1", "2026-01-01", "2026-03-31" ] ])
|
|
191
|
+
assert_equal [ "Q1" ], presets.map(&:text)
|
|
192
|
+
render_picker(range: true, presets: false)
|
|
193
|
+
assert_empty presets
|
|
174
194
|
end
|
|
175
195
|
|
|
176
|
-
def
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
assert_equal "#{input[:id]}-hint", input["aria-describedby"]
|
|
180
|
-
refute input["aria-invalid"]
|
|
196
|
+
def test_class_and_attributes_pass_through
|
|
197
|
+
render_picker(name: "d", class: "max-w-xs", id: "when", data: { foo: "bar" })
|
|
198
|
+
assert_selector "#when.max-w-xs[data-foo='bar'][data-controller='ui--date-picker']"
|
|
181
199
|
end
|
|
182
200
|
end
|
|
@@ -25,19 +25,20 @@ class UI::FileFieldTest < ViewComponent::TestCase
|
|
|
25
25
|
assert_equal input[:id], label[:for]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def
|
|
28
|
+
def root = page.find("[data-controller='ui--file-field']")
|
|
29
|
+
|
|
30
|
+
def test_controller_wraps_the_dropzone_and_takes_drops
|
|
29
31
|
render_inline(UI::FileField.new)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
assert_includes
|
|
33
|
-
assert_includes
|
|
34
|
-
assert_includes label["data-action"], "drop->ui--file-field#drop"
|
|
32
|
+
assert_selector "[data-controller='ui--file-field'] > label[data-ui--file-field-target='dropzone']"
|
|
33
|
+
assert_includes root["data-action"], "dragover->ui--file-field#dragOver"
|
|
34
|
+
assert_includes root["data-action"], "dragleave->ui--file-field#dragLeave"
|
|
35
|
+
assert_includes root["data-action"], "drop->ui--file-field#drop"
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
def
|
|
38
|
+
def test_input_wired_to_the_controller_on_change
|
|
38
39
|
render_inline(UI::FileField.new)
|
|
39
|
-
input = page.find("input", visible: :all)
|
|
40
|
-
assert_includes input["data-action"], "change->ui--file-field#
|
|
40
|
+
input = page.find("input[type='file']", visible: :all)
|
|
41
|
+
assert_includes input["data-action"], "change->ui--file-field#chosen"
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def test_not_multiple_by_default
|
|
@@ -98,4 +99,99 @@ class UI::FileFieldTest < ViewComponent::TestCase
|
|
|
98
99
|
render_inline(UI::FileField.new(id: "my-id", data: { test_id: "f" }))
|
|
99
100
|
assert_selector "input#my-id[data-test-id='f']", visible: :all
|
|
100
101
|
end
|
|
102
|
+
|
|
103
|
+
# ── Previews ────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
def test_previews_by_default_with_a_list_and_a_tile_template
|
|
106
|
+
render_inline(UI::FileField.new(name: "photos"))
|
|
107
|
+
assert_equal "true", root["data-ui--file-field-preview-value"]
|
|
108
|
+
assert_selector "ul[data-ui--file-field-target='list']", visible: :all
|
|
109
|
+
template = rendered_content[%r{<template data-ui--file-field-target="template">.*?</template>}m]
|
|
110
|
+
assert template, "no tile template"
|
|
111
|
+
%w[thumb icon remove progress bar name meta retry].each { |role| assert_includes template, %(data-role="#{role}") }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_preview_false_lists_names_instead
|
|
115
|
+
render_inline(UI::FileField.new(preview: false))
|
|
116
|
+
assert_equal "false", root["data-ui--file-field-preview-value"]
|
|
117
|
+
assert_selector "[data-ui--file-field-target='filenames']", visible: :all
|
|
118
|
+
assert_no_selector "ul[data-ui--file-field-target='list']", visible: :all
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_checks_accept_and_max_size_and_says_the_limit
|
|
122
|
+
render_inline(UI::FileField.new(accept: "image/*", max_size: 5.megabytes))
|
|
123
|
+
assert_equal "image/*", root["data-ui--file-field-accept-value"]
|
|
124
|
+
assert_equal 5.megabytes.to_s, root["data-ui--file-field-max-size-value"]
|
|
125
|
+
assert_equal "5 MB", JSON.parse(root["data-ui--file-field-labels-value"])["max"]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# ── Direct upload ───────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
def test_direct_upload_points_at_active_storage
|
|
131
|
+
render_inline(UI::FileField.new(name: "photos", direct_upload: true))
|
|
132
|
+
assert_equal "true", root["data-ui--file-field-direct-upload-value"]
|
|
133
|
+
assert_match %r{/rails/active_storage/direct_uploads\z}, root["data-ui--file-field-url-value"]
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_without_direct_upload_there_is_no_upload_url
|
|
137
|
+
render_inline(UI::FileField.new(name: "photos"))
|
|
138
|
+
assert_nil root["data-ui--file-field-url-value"]
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_signed_ids_post_under_the_fields_name
|
|
142
|
+
render_inline(UI::FileField.new(name: "product[photos]", multiple: true, direct_upload: true))
|
|
143
|
+
assert_equal "product[photos][]", root["data-ui--file-field-name-value"]
|
|
144
|
+
render_inline(UI::FileField.new(name: "store[logo]", direct_upload: true))
|
|
145
|
+
assert_equal "store[logo]", root["data-ui--file-field-name-value"]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# ── Files already kept ──────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
Kept = Struct.new(:signed_id, :filename, :byte_size, :content_type, :url, keyword_init: true)
|
|
151
|
+
|
|
152
|
+
def kept
|
|
153
|
+
[ Kept.new(signed_id: "abc", filename: "front.jpg", byte_size: 2_097_152, content_type: "image/jpeg", url: "/front.jpg"),
|
|
154
|
+
Kept.new(signed_id: "def", filename: "manual.pdf", byte_size: 51_200, content_type: "application/pdf", url: "/manual.pdf") ]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_kept_files_show_as_tiles_kept_by_their_signed_ids
|
|
158
|
+
render_inline(UI::FileField.new(name: "product[photos][]", multiple: true, existing: kept))
|
|
159
|
+
tiles = page.all("ul li[data-ui--file-field-target='item'][data-state='kept']")
|
|
160
|
+
assert_equal 2, tiles.size
|
|
161
|
+
assert_selector "li input[type='hidden'][name='product[photos][]'][value='abc']", visible: :all
|
|
162
|
+
assert_selector "li img[data-role='thumb'][src='/front.jpg']"
|
|
163
|
+
assert_selector "li", text: "front.jpg"
|
|
164
|
+
assert_selector "li", text: "2 MB"
|
|
165
|
+
assert_selector "li button[aria-label='Remove manual.pdf']"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_a_kept_file_that_isnt_an_image_shows_an_icon
|
|
169
|
+
render_inline(UI::FileField.new(name: "docs[]", multiple: true, existing: kept))
|
|
170
|
+
pdf = page.all("li[data-ui--file-field-target='item']").last
|
|
171
|
+
assert pdf.has_css?("img[data-role='thumb'][hidden]", visible: :all)
|
|
172
|
+
assert pdf.has_css?("svg[data-icon='file']")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_a_kept_file_fills_a_required_field
|
|
176
|
+
render_inline(UI::FileField.new(name: "photos[]", multiple: true, required: true, existing: kept))
|
|
177
|
+
assert_nil page.find("input[type='file']", visible: :all)[:required]
|
|
178
|
+
assert_equal "true", root["data-ui--file-field-required-value"]
|
|
179
|
+
render_inline(UI::FileField.new(name: "photos[]", multiple: true, required: true))
|
|
180
|
+
assert page.find("input[type='file']", visible: :all)[:required]
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
Product = Struct.new(:photos) do
|
|
184
|
+
def to_model = self
|
|
185
|
+
def model_name = ActiveModel::Name.new(self.class, nil, "Product")
|
|
186
|
+
def persisted? = true
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
Many = Struct.new(:attachments)
|
|
190
|
+
|
|
191
|
+
def test_bound_to_a_form_it_shows_the_records_attachments
|
|
192
|
+
builder = ActionView::Helpers::FormBuilder.new(:product, Product.new(Many.new(kept)), vc_test_controller.view_context, {})
|
|
193
|
+
render_inline(UI::FileField.new(form: builder, field: :photos, multiple: true))
|
|
194
|
+
assert_selector "li input[type='hidden'][name='product[photos][]'][value='def']", visible: :all
|
|
195
|
+
assert_equal "product[photos][]", root["data-ui--file-field-name-value"]
|
|
196
|
+
end
|
|
101
197
|
end
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::GalleryTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_gallery(count: 3, **opts)
|
|
10
|
+
render_inline(UI::Gallery.new(**opts)) do |gallery|
|
|
11
|
+
count.times { |i| gallery.with_image(src: "/photo-#{i}.jpg", alt: "Photo #{i}") }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_renders_nothing_without_images
|
|
16
|
+
render_gallery(count: 0)
|
|
17
|
+
assert_no_selector "[data-slot='gallery']"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_renders_a_labelled_group_with_the_controller
|
|
21
|
+
render_gallery(label: "Mug photos")
|
|
22
|
+
assert_selector "[data-slot='gallery'][role='group'][aria-label='Mug photos'][data-controller='ui--gallery']"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_each_image_gets_a_slide_a_thumbnail_and_its_alt
|
|
26
|
+
render_gallery
|
|
27
|
+
assert_selector "[data-ui--gallery-target='slide']", count: 3
|
|
28
|
+
assert_selector "[data-ui--gallery-target='thumbnail']", count: 3
|
|
29
|
+
assert_selector "[data-ui--gallery-target='slide'] img[alt='Photo 1'][src='/photo-1.jpg']"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_only_the_first_slide_loads_with_the_page
|
|
33
|
+
render_gallery
|
|
34
|
+
slides = page.all("[data-ui--gallery-target='slide'] img").map { |img| img[:loading] }
|
|
35
|
+
assert_equal %w[eager lazy lazy], slides
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_thumbnails_are_decorative_images_in_named_buttons
|
|
39
|
+
render_gallery
|
|
40
|
+
assert_selector "button[aria-label='Show image 2'] img[alt='']"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_only_the_first_thumbnail_starts_current
|
|
44
|
+
render_gallery
|
|
45
|
+
assert_selector "[data-ui--gallery-target='thumbnail'][aria-current='true']", count: 1
|
|
46
|
+
assert_selector "button[aria-label='Show image 1'][aria-current='true']"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_thumbnail_src_and_zoom_src_are_used_where_given
|
|
50
|
+
render_inline(UI::Gallery.new) do |gallery|
|
|
51
|
+
gallery.with_image(src: "/m.jpg", alt: "A", zoom_src: "/large.jpg", thumbnail_src: "/small.jpg")
|
|
52
|
+
gallery.with_image(src: "/n.jpg", alt: "B")
|
|
53
|
+
end
|
|
54
|
+
assert_selector "button[aria-label='Show image 1'] img[src='/small.jpg']"
|
|
55
|
+
assert_selector "[data-ui--gallery-target='slide'][data-zoom-src='/large.jpg']"
|
|
56
|
+
assert_selector "button[aria-label='Show image 2'] img[src='/n.jpg']"
|
|
57
|
+
assert_selector "[data-ui--gallery-target='slide'][data-zoom-src='/n.jpg']"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_the_large_image_is_not_asked_for_until_opened
|
|
61
|
+
render_inline(UI::Gallery.new) { |gallery| gallery.with_image(src: "/m.jpg", alt: "A", zoom_src: "/large.jpg") }
|
|
62
|
+
assert_no_selector "img[src='/large.jpg']", visible: :all
|
|
63
|
+
assert_no_selector "dialog img[src]", visible: :all
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_clicking_a_slide_opens_it_at_its_index
|
|
67
|
+
render_gallery
|
|
68
|
+
button = page.find("button[aria-label='Zoom image 2: Photo 1']")
|
|
69
|
+
assert_equal "ui--gallery#open", button["data-action"]
|
|
70
|
+
assert_equal "1", button["data-ui--gallery-index-param"]
|
|
71
|
+
assert_equal "button", button[:type]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_only_the_image_showing_is_a_tab_stop
|
|
75
|
+
render_gallery
|
|
76
|
+
stops = page.all("[data-ui--gallery-target='slide'] button").map { |button| button[:tabindex] }
|
|
77
|
+
assert_equal %w[0 -1 -1], stops
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_overlay_is_just_the_image_on_a_transparent_backdrop
|
|
81
|
+
render_gallery
|
|
82
|
+
dialog = page.find("dialog", visible: :all)
|
|
83
|
+
assert_includes dialog[:class], "bg-transparent"
|
|
84
|
+
assert_includes dialog[:class], "backdrop:bg-black/80"
|
|
85
|
+
assert_selector "dialog img", count: 1, visible: :all
|
|
86
|
+
assert_no_selector "dialog [data-ui--gallery-target='thumbnail']", visible: :all
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def test_escape_goes_through_the_closing_animation
|
|
90
|
+
render_gallery
|
|
91
|
+
assert_includes page.find("dialog", visible: :all)["data-action"], "cancel->ui--gallery#cancel"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_overlay_buttons_sit_in_the_top_corners_and_at_the_ends
|
|
95
|
+
render_gallery
|
|
96
|
+
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom in']", visible: :all
|
|
97
|
+
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom out']", visible: :all
|
|
98
|
+
assert_selector "dialog button.end-4.top-4[aria-label='Close']", visible: :all
|
|
99
|
+
assert_selector "dialog button.start-4.top-1\\/2[aria-label='Previous image']", visible: :all
|
|
100
|
+
assert_selector "dialog button.end-4.top-1\\/2[aria-label='Next image']", visible: :all
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_overlay_is_the_default_with_no_hover_zoom
|
|
104
|
+
render_gallery
|
|
105
|
+
assert_selector "[data-slot='gallery'][data-zoom='overlay']"
|
|
106
|
+
assert_no_selector "[data-ui--gallery-target='lens']", visible: :all
|
|
107
|
+
assert_no_selector "[data-ui--gallery-target='pane']", visible: :all
|
|
108
|
+
assert_equal "ui--gallery#open", page.find("button[aria-label='Zoom image 1: Photo 0']")["data-action"]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_hover_zoom_adds_a_lens_and_pane_and_still_opens_the_overlay_on_click
|
|
112
|
+
render_gallery(zoom: :hover)
|
|
113
|
+
assert_selector "[data-slot='gallery'][data-zoom='hover'][data-ui--gallery-zoom-scale-value='2.5']"
|
|
114
|
+
assert_selector "[data-ui--gallery-target='lens'].invisible[aria-hidden='true']", visible: :all
|
|
115
|
+
assert_selector "[data-ui--gallery-target='pane'].invisible[aria-hidden='true']", visible: :all
|
|
116
|
+
assert_no_selector "[data-ui--gallery-target='pane'][data-shown]", visible: :all
|
|
117
|
+
action = page.find("button[aria-label='Zoom image 1: Photo 0']")["data-action"]
|
|
118
|
+
assert_includes action, "ui--gallery#open"
|
|
119
|
+
assert_includes action, "pointermove->ui--gallery#hover"
|
|
120
|
+
assert_includes action, "pointerleave->ui--gallery#hoverEnd"
|
|
121
|
+
assert_selector "dialog", visible: :all
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_zoom_scale_can_be_set
|
|
125
|
+
render_gallery(zoom: :hover, zoom_scale: 4)
|
|
126
|
+
assert_selector "[data-ui--gallery-zoom-scale-value='4']"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_unknown_zoom_falls_back_to_overlay
|
|
130
|
+
render_gallery(zoom: :spin)
|
|
131
|
+
assert_selector "[data-slot='gallery'][data-zoom='overlay']"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_overlay_is_a_named_dialog_with_its_controls
|
|
135
|
+
render_gallery
|
|
136
|
+
assert_selector "dialog[aria-label='Zoomed image'][data-ui--gallery-target='dialog']", visible: :all
|
|
137
|
+
assert_selector "dialog button[aria-label='Zoom in'][data-action='ui--gallery#zoomIn']", visible: :all
|
|
138
|
+
assert_selector "dialog button[aria-label='Zoom out'][data-action='ui--gallery#zoomOut']", visible: :all
|
|
139
|
+
assert_selector "dialog button[aria-label='Close'][data-action='ui--gallery#close']", visible: :all
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_arrows_in_both_views
|
|
143
|
+
render_gallery
|
|
144
|
+
assert_selector "button[aria-label='Previous image'][data-action='ui--gallery#previous']", count: 2, visible: :all
|
|
145
|
+
assert_selector "button[aria-label='Next image'][data-action='ui--gallery#next']", count: 2, visible: :all
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_a_single_image_has_no_thumbnails_or_arrows_but_still_zooms
|
|
149
|
+
render_gallery(count: 1)
|
|
150
|
+
assert_no_selector "[data-ui--gallery-target='thumbnail']"
|
|
151
|
+
assert_no_selector "button[aria-label='Next image']", visible: :all
|
|
152
|
+
assert_selector "button[aria-label='Zoom image 1: Photo 0']"
|
|
153
|
+
assert_selector "dialog", visible: :all
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_status_says_where_you_are
|
|
157
|
+
render_gallery
|
|
158
|
+
assert_selector "[data-ui--gallery-target='status'][aria-live='polite']", text: "Image 1 of 3"
|
|
159
|
+
assert_equal "Image %{current} of %{total}", page.find("[data-slot='gallery']")["data-ui--gallery-position-value"]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def test_aspect_and_fit
|
|
163
|
+
{ square: "aspect-square", landscape: "aspect-video" }.each do |aspect, css|
|
|
164
|
+
render_gallery(aspect: aspect)
|
|
165
|
+
assert_selector "[data-ui--gallery-target='slide'].#{css}", count: 3
|
|
166
|
+
end
|
|
167
|
+
render_gallery(fit: :cover)
|
|
168
|
+
assert_selector "[data-ui--gallery-target='slide'] img.object-cover", count: 3
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_unknown_aspect_and_fit_fall_back
|
|
172
|
+
render_gallery(aspect: :round, fit: :stretch)
|
|
173
|
+
assert_selector "[data-ui--gallery-target='slide'].aspect-square img.object-contain", count: 3
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_buttons_keep_the_kits_focus_ring
|
|
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
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_overlay_buttons_ring_in_white_to_show_on_the_dark_backdrop
|
|
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
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def test_class_and_html_attributes_pass_through
|
|
189
|
+
render_gallery(class: "max-w-md", id: "photos", data: { foo: "bar" })
|
|
190
|
+
assert_selector "#photos.max-w-md[data-foo='bar'][data-controller='ui--gallery']"
|
|
191
|
+
end
|
|
192
|
+
end
|