velvetkit 0.3.0 → 0.4.1
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 +109 -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/money_input.html.erb +8 -0
- data/registry/app/components/ui/money_input.rb +153 -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/scan_input.html.erb +6 -0
- data/registry/app/components/ui/scan_input.rb +94 -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/slider.html.erb +23 -0
- data/registry/app/components/ui/slider.rb +254 -0
- 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/money_input_controller.ts +228 -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/scan_input_controller.ts +143 -0
- data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
- data/registry/app/javascript/controllers/ui/slider_controller.ts +216 -0
- data/registry/app/javascript/vanilla_calendar.ts +15 -0
- data/registry/components.yml +25 -3
- data/registry/config/locales/velvetkit.en.yml +79 -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/scan-barcode.svg +21 -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/volume-2.svg +17 -0
- data/registry/icons/lucide/volume-x.svg +17 -0
- data/registry/icons/lucide/zoom-in.svg +18 -0
- data/registry/icons/lucide/zoom-out.svg +17 -0
- data/registry/icons/phosphor/barcode.svg +2 -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/speaker-high.svg +2 -0
- data/registry/icons/phosphor/speaker-x.svg +2 -0
- data/registry/icons/phosphor/truck.svg +2 -0
- data/registry/icons/phosphor/user-plus.svg +2 -0
- data/registry/icons/tabler/barcode.svg +23 -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/volume-3.svg +17 -0
- data/registry/icons/tabler/volume.svg +18 -0
- data/registry/icons/tabler/zoom-in.svg +19 -0
- data/registry/icons/tabler/zoom-out.svg +18 -0
- data/registry/icons.yml +19 -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/money_input_preview/cash_tendered.html.erb +24 -0
- data/registry/test/components/previews/ui/money_input_preview/currencies.html.erb +7 -0
- data/registry/test/components/previews/ui/money_input_preview/invoice.html.erb +24 -0
- data/registry/test/components/previews/ui/money_input_preview/sizes_and_states.html.erb +9 -0
- data/registry/test/components/previews/ui/money_input_preview.rb +34 -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/scan_input_preview/_simulate.html.erb +20 -0
- data/registry/test/components/previews/ui/scan_input_preview/library_checkout.html.erb +30 -0
- data/registry/test/components/previews/ui/scan_input_preview/playground.html.erb +13 -0
- data/registry/test/components/previews/ui/scan_input_preview/stock_count.html.erb +24 -0
- data/registry/test/components/previews/ui/scan_input_preview/ticket_check_in.html.erb +34 -0
- data/registry/test/components/previews/ui/scan_input_preview/till.html.erb +9 -0
- data/registry/test/components/previews/ui/scan_input_preview.rb +33 -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/slider_preview/named_steps.html.erb +7 -0
- data/registry/test/components/previews/ui/slider_preview/opening_hours.html.erb +5 -0
- data/registry/test/components/previews/ui/slider_preview/price_range.html.erb +6 -0
- data/registry/test/components/previews/ui/slider_preview/sizes_and_states.html.erb +9 -0
- data/registry/test/components/previews/ui/slider_preview/text_size.html.erb +16 -0
- data/registry/test/components/previews/ui/slider_preview/tip.html.erb +22 -0
- data/registry/test/components/previews/ui/slider_preview/volume.html.erb +5 -0
- data/registry/test/components/previews/ui/slider_preview.rb +45 -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/money_input_test.rb +149 -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/scan_input_test.rb +110 -0
- data/registry/test/components/ui/select_test.rb +62 -0
- data/registry/test/components/ui/slider_test.rb +190 -0
- data/registry/test/components/ui/timeline_test.rb +175 -0
- metadata +188 -2
- data/registry/app/javascript/cally.ts +0 -8
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::ChartTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
LABELS = %w[Jan Feb Mar].freeze
|
|
10
|
+
|
|
11
|
+
def render_chart(series: [ { name: "Sales", data: [ 1200, 1500.5, 900 ] } ], **opts)
|
|
12
|
+
render_inline(UI::Chart.new(labels: LABELS, series: series, **opts))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def two_series = [ { name: "This year", data: [ 1, 2, 3 ] }, { name: "Last year", data: [ 3, 2, 1 ] } ]
|
|
16
|
+
|
|
17
|
+
def config = JSON.parse(page.find("[data-slot='chart']")["data-ui--chart-config-value"])
|
|
18
|
+
|
|
19
|
+
def test_renders_the_controller_with_its_module_and_a_named_canvas
|
|
20
|
+
render_chart(label: "Monthly sales")
|
|
21
|
+
root = page.find("[data-slot='chart'][data-controller='ui--chart'][data-type='line']")
|
|
22
|
+
assert_match(/chart_js.*\.js\z/, root["data-ui--chart-module-url-value"])
|
|
23
|
+
assert_selector "canvas[role='img'][tabindex='0'][data-ui--chart-target='canvas']"
|
|
24
|
+
assert_includes page.find("canvas")["aria-label"], "Monthly sales."
|
|
25
|
+
assert_includes page.find("canvas")["aria-label"], "arrow keys"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_config_carries_the_type_labels_and_series
|
|
29
|
+
render_chart(type: :bar, stacked: true, series: two_series)
|
|
30
|
+
assert_equal "bar", config["type"]
|
|
31
|
+
assert config["stacked"]
|
|
32
|
+
assert_equal LABELS, config["labels"]
|
|
33
|
+
assert_equal [ "This year", "Last year" ], config["series"].map { |s| s["name"] }
|
|
34
|
+
assert_equal [ 1, 2, 3 ], config["series"].first["data"]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_stacked_only_applies_to_bars
|
|
38
|
+
render_chart(type: :line, stacked: true)
|
|
39
|
+
assert_equal false, config["stacked"]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_unknown_type_and_format_fall_back
|
|
43
|
+
render_chart(type: :radar, format: :weird)
|
|
44
|
+
assert_equal "line", config["type"]
|
|
45
|
+
assert_equal "number", config["axis"]["style"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_series_take_the_colours_in_order_unless_given_one
|
|
49
|
+
render_chart(series: [ { name: "A", data: [ 1, 2, 3 ] }, { name: "B", data: [ 1, 2, 3 ], color: 5 }, { name: "C", data: [ 1, 2, 3 ], color: 9 } ])
|
|
50
|
+
assert_equal [ 1, 5, 3 ], config["series"].map { |s| s["color"] }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_more_than_five_series_is_refused
|
|
54
|
+
six = Array.new(6) { |i| { name: "S#{i}", data: [ 1, 2, 3 ] } }
|
|
55
|
+
error = assert_raises(ArgumentError) { render_chart(series: six) }
|
|
56
|
+
assert_includes error.message, "Other"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_a_series_must_have_a_value_for_each_label
|
|
60
|
+
error = assert_raises(ArgumentError) { render_chart(series: [ { name: "Short", data: [ 1, 2 ] } ]) }
|
|
61
|
+
assert_includes error.message, "Short"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_one_series_has_no_legend
|
|
65
|
+
render_chart
|
|
66
|
+
assert_no_selector "ul li"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_two_series_get_a_legend_with_swatches_shaped_like_the_marks
|
|
70
|
+
render_chart(series: two_series)
|
|
71
|
+
assert_selector "ul li", count: 2
|
|
72
|
+
assert_selector "ul li span.bg-chart-1.h-0\\.5"
|
|
73
|
+
assert_selector "ul li", text: "Last year"
|
|
74
|
+
render_chart(type: :bar, series: two_series)
|
|
75
|
+
assert_selector "ul li span.bg-chart-2.size-2\\.5"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_table_has_every_value_written_out
|
|
79
|
+
render_chart(label: "Monthly sales")
|
|
80
|
+
assert_selector "details summary", text: "Show the data"
|
|
81
|
+
assert_selector "table caption", text: "Monthly sales", visible: :all
|
|
82
|
+
assert_selector "th[scope='col']", text: "Sales", visible: :all
|
|
83
|
+
assert_selector "th[scope='row']", text: "Feb", visible: :all
|
|
84
|
+
assert_selector "td", text: "1,500.5", visible: :all
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_currency_and_percent_formats
|
|
88
|
+
render_chart(format: :currency)
|
|
89
|
+
assert_selector "td", text: "$1,200.00", visible: :all
|
|
90
|
+
assert_equal [ "$1,200.00", "$1,500.50", "$900.00" ], config["series"].first["text"]
|
|
91
|
+
render_chart(format: :currency, unit: "₹")
|
|
92
|
+
assert_selector "td", text: "₹1,200.00", visible: :all
|
|
93
|
+
assert_equal "₹", config["axis"]["unit"]
|
|
94
|
+
render_chart(format: :percent, series: [ { name: "Margin", data: [ 38.25, 40, 41.5 ] } ])
|
|
95
|
+
assert_selector "td", text: "40%", visible: :all
|
|
96
|
+
assert_selector "td", text: "41.5%", visible: :all
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_missing_values_leave_a_gap
|
|
100
|
+
render_chart(series: [ { name: "Sales", data: [ 1, nil, 3 ] } ])
|
|
101
|
+
assert_nil config["series"].first["data"][1]
|
|
102
|
+
assert_selector "td", text: "—", visible: :all
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def render_pie(type: :pie, labels: %w[Card Cash UPI], data: [ 600, 300, 100 ], **opts)
|
|
106
|
+
render_inline(UI::Chart.new(type: type, labels: labels, series: [ { name: "Takings", data: data } ], **opts))
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_pie_and_donut_are_types
|
|
110
|
+
render_pie
|
|
111
|
+
assert_equal "pie", config["type"]
|
|
112
|
+
render_pie(type: :donut)
|
|
113
|
+
assert_equal "donut", config["type"]
|
|
114
|
+
assert_selector "[data-slot='chart'][data-type='donut']"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_pie_slices_take_the_colours_in_order_and_carry_their_shares
|
|
118
|
+
render_pie
|
|
119
|
+
slice = config["series"].first
|
|
120
|
+
assert_equal [ 1, 2, 3 ], slice["colors"]
|
|
121
|
+
assert_equal %w[60% 30% 10%], slice["shares"]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_pie_legend_lists_each_slice_with_its_value_and_share
|
|
125
|
+
render_pie(format: :currency)
|
|
126
|
+
assert_selector "ul li", count: 3
|
|
127
|
+
assert_selector "ul li span.bg-chart-2.size-2\\.5"
|
|
128
|
+
assert_selector "ul li", text: /Cash\s*\$300\.00\s*30%/
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def test_a_single_slice_still_gets_a_legend
|
|
132
|
+
render_pie(labels: %w[Card], data: [ 5 ])
|
|
133
|
+
assert_selector "ul li", count: 1
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_pie_table_adds_a_share_column
|
|
137
|
+
render_pie
|
|
138
|
+
assert_selector "th[scope='col']", text: "Share", visible: :all
|
|
139
|
+
assert_selector "td", text: "60%", visible: :all
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_donut_carries_its_total
|
|
143
|
+
render_pie(type: :donut, format: :currency)
|
|
144
|
+
assert_equal "$1,000.00", config["total"]
|
|
145
|
+
assert_equal "Total", config["total_label"]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_line_and_bar_carry_no_slices
|
|
149
|
+
render_chart
|
|
150
|
+
assert_nil config["total"]
|
|
151
|
+
assert_nil config["series"].first["shares"]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_pie_takes_one_series
|
|
155
|
+
error = assert_raises(ArgumentError) do
|
|
156
|
+
render_inline(UI::Chart.new(type: :pie, labels: LABELS, series: [ { name: "A", data: [ 1, 2, 3 ] }, { name: "B", data: [ 1, 2, 3 ] } ]))
|
|
157
|
+
end
|
|
158
|
+
assert_includes error.message, "one series"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_pie_draws_up_to_five_slices
|
|
162
|
+
error = assert_raises(ArgumentError) { render_pie(labels: %w[a b c d e f], data: [ 1, 1, 1, 1, 1, 1 ]) }
|
|
163
|
+
assert_includes error.message, "Other"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_pie_refuses_values_below_zero
|
|
167
|
+
error = assert_raises(ArgumentError) { render_pie(data: [ 5, -1, 3 ]) }
|
|
168
|
+
assert_includes error.message, "below zero"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_pie_with_no_total_shows_no_shares
|
|
172
|
+
render_pie(data: [ 0, 0, nil ])
|
|
173
|
+
assert_equal %w[— — —], config["series"].first["shares"]
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_names_are_escaped
|
|
177
|
+
render_chart(series: [ { name: "<b>Sales</b>", data: [ 1, 2, 3 ] }, { name: "Other", data: [ 1, 2, 3 ] } ])
|
|
178
|
+
assert_no_selector "b"
|
|
179
|
+
assert_selector "li", text: "<b>Sales</b>"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_height_class_and_attributes
|
|
183
|
+
render_chart(height: 200, class: "max-w-xl", id: "sales", data: { foo: "bar" })
|
|
184
|
+
assert_selector "#sales.max-w-xl[data-foo='bar'][data-controller='ui--chart']"
|
|
185
|
+
assert_selector "div.relative[style='height: 200px'] canvas"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::Command::GroupTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_a_group_named_by_its_heading
|
|
10
|
+
render_inline(UI::Command::Group.new(heading: "Pages")) { |g| g.with_item(label: "Home", href: "/") }
|
|
11
|
+
heading = page.find("[role='group'] > div", text: "Pages")
|
|
12
|
+
assert_selector "[role='group'][data-ui--command-target='group'][aria-labelledby='#{heading[:id]}'] [role='option']", text: "Home"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_a_group_without_a_heading
|
|
16
|
+
render_inline(UI::Command::Group.new(class: "pt-0")) { |g| g.with_item(label: "Home") }
|
|
17
|
+
assert_selector "[role='group'].pt-0:not([aria-labelledby])"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::Command::ItemTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_an_option_carrying_what_the_controller_needs
|
|
10
|
+
render_inline(UI::Command::Item.new(label: "Settings", href: "/settings", id: "s"))
|
|
11
|
+
assert_selector "div#s[role='option'][aria-selected='false'][data-ui--command-target='item'][data-label='Settings'][data-href='/settings'][data-value='/settings']", text: "Settings"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_value_defaults_to_href_then_label
|
|
15
|
+
render_inline(UI::Command::Item.new(label: "New invoice", value: "new-invoice"))
|
|
16
|
+
assert_selector "[data-value='new-invoice']"
|
|
17
|
+
assert_no_selector "[data-href]"
|
|
18
|
+
render_inline(UI::Command::Item.new(label: "Log out"))
|
|
19
|
+
assert_selector "[data-value='Log out']"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_icon_description_and_keywords
|
|
23
|
+
render_inline(UI::Command::Item.new(label: "Invoices", icon: "receipt", description: "All bills, paid and unpaid", keywords: %w[bills money]))
|
|
24
|
+
assert_selector "span[aria-hidden='true'] svg[data-icon='receipt']"
|
|
25
|
+
assert_selector "span.text-xs.text-muted-foreground", text: "All bills, paid and unpaid"
|
|
26
|
+
assert_selector "[data-keywords='bills money']"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_a_shortcut_is_shown_and_bound_only_when_asked
|
|
30
|
+
render_inline(UI::Command::Item.new(label: "Settings", shortcut: "mod+,", id: "s"))
|
|
31
|
+
assert_selector "[role='option'] [data-slot='kbd'].ms-auto"
|
|
32
|
+
assert_no_selector "[data-ui--kbd-keys-value]"
|
|
33
|
+
render_inline(UI::Command::Item.new(label: "Settings", shortcut: "mod+,", bind: true, id: "s"))
|
|
34
|
+
assert_selector "[data-ui--kbd-keys-value='mod+,'][data-ui--kbd-target-value='#s']"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_disabled_items_say_so_and_do_not_bind
|
|
38
|
+
render_inline(UI::Command::Item.new(label: "Export", shortcut: "mod+e", bind: true, disabled: true))
|
|
39
|
+
assert_selector "[role='option'][aria-disabled='true']"
|
|
40
|
+
assert_no_selector "[data-ui--kbd-keys-value]"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_a_block_replaces_how_it_looks_but_not_its_label
|
|
44
|
+
render_inline(UI::Command::Item.new(label: "Ada Lovelace")) { "<strong>Ada</strong> Lovelace".html_safe }
|
|
45
|
+
assert_selector "[role='option'][data-label='Ada Lovelace'] strong", text: "Ada"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::CommandTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_command(**opts)
|
|
10
|
+
render_inline(UI::Command.new(id: "cmd", **opts)) do |command|
|
|
11
|
+
command.with_trigger if opts[:dialog]
|
|
12
|
+
command.with_group(heading: "Pages") do |group|
|
|
13
|
+
group.with_item(label: "Dashboard", href: "/dashboard", icon: "house")
|
|
14
|
+
group.with_item(label: "Settings", href: "/settings", shortcut: "mod+,")
|
|
15
|
+
end
|
|
16
|
+
command.with_group(heading: "Actions") do |group|
|
|
17
|
+
group.with_item(label: "New invoice", value: "new-invoice", keywords: %w[create bill])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_a_combobox_over_a_listbox
|
|
23
|
+
render_command
|
|
24
|
+
assert_selector "[data-controller='ui--command'] input#cmd-input[role='combobox'][aria-controls='cmd-list'][aria-expanded='true'][aria-autocomplete='list']"
|
|
25
|
+
assert_selector "#cmd-list[role='listbox'][aria-label='Command menu']"
|
|
26
|
+
assert_selector "input[placeholder='Type a command or search…'][aria-label='Command menu']"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_groups_and_items_are_listed_in_order
|
|
30
|
+
render_command
|
|
31
|
+
assert_equal %w[Pages Actions], page.all("[role='group'] > div:first-child").map(&:text)
|
|
32
|
+
assert_equal [ "Dashboard", "Settings", "New invoice" ], page.all("[role='option']").map { |o| o["data-label"] }
|
|
33
|
+
assert_selector "[role='group'][aria-labelledby]", count: 2
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_on_a_page_it_is_the_panel_with_no_dialog_or_footer
|
|
37
|
+
render_command
|
|
38
|
+
assert_no_selector "dialog"
|
|
39
|
+
assert_no_selector "button[data-action='ui--command#open']"
|
|
40
|
+
assert_selector "[data-ui--command-dialog-value='false'][data-ui--command-shortcut-value='']"
|
|
41
|
+
assert_no_text "to move"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_as_a_dialog_it_has_a_trigger_a_shortcut_and_a_footer
|
|
45
|
+
render_command(dialog: true)
|
|
46
|
+
assert_selector "dialog[aria-label='Command menu'][data-ui--command-target='dialog'] [data-ui--command-target='panel']"
|
|
47
|
+
assert_selector "button[data-action='ui--command#open'][aria-haspopup='dialog']", text: "Search…"
|
|
48
|
+
assert_selector "button[data-action='ui--command#open'] [data-slot='kbd']"
|
|
49
|
+
assert_selector "[data-ui--command-dialog-value='true'][data-ui--command-shortcut-value='mod+k']"
|
|
50
|
+
assert_text "to move"
|
|
51
|
+
assert_text "to close"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_the_shortcut_can_change_or_go
|
|
55
|
+
render_command(dialog: true, shortcut: "/")
|
|
56
|
+
assert_selector "[data-ui--command-shortcut-value='/']"
|
|
57
|
+
render_command(dialog: true, shortcut: nil)
|
|
58
|
+
assert_selector "[data-ui--command-shortcut-value='']"
|
|
59
|
+
assert_no_selector "button[data-action='ui--command#open'] [data-slot='kbd']"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_more_than_one_shortcut_the_trigger_showing_the_first
|
|
63
|
+
render_inline(UI::Command.new(dialog: true, shortcut: [ "mod+k", "/" ])) { |c| c.with_trigger }
|
|
64
|
+
assert_selector "[data-ui--command-shortcut-value='mod+k /']"
|
|
65
|
+
assert_selector "button[data-action='ui--command#open'] [data-slot='kbd']", count: 1
|
|
66
|
+
assert_selector "button [data-slot='kbd'] kbd", text: "K"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_the_trigger_keeps_its_own_aria_and_data
|
|
70
|
+
render_inline(UI::Command.new(dialog: true)) do |c|
|
|
71
|
+
c.with_trigger(aria: { label: "Search the docs" }, data: { testid: "open", action: "click->other#thing" })
|
|
72
|
+
end
|
|
73
|
+
assert_selector "button[aria-label='Search the docs'][aria-haspopup='dialog'][data-testid='open']"
|
|
74
|
+
assert_selector "button[data-action='ui--command#open click->other#thing']"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_sorting_groups_and_saying_what_empty_means
|
|
78
|
+
render_command(sort_groups: true, empty: "Nothing like that here.")
|
|
79
|
+
assert_selector "[data-ui--command-sort-groups-value='true'][data-ui--command-empty-value='Nothing like that here.']"
|
|
80
|
+
render_command
|
|
81
|
+
assert_selector "[data-ui--command-sort-groups-value='false'][data-ui--command-empty-value='No results found.']"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_a_trigger_with_its_own_label_or_content
|
|
85
|
+
render_inline(UI::Command.new(dialog: true)) { |c| c.with_trigger(label: "Jump to…", class: "w-64") }
|
|
86
|
+
assert_selector "button.w-64", text: "Jump to…"
|
|
87
|
+
render_inline(UI::Command.new(dialog: true)) { |c| c.with_trigger(variant: :ghost) { "Open" } }
|
|
88
|
+
assert_selector "button[data-action='ui--command#open']", exact_text: "Open"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_searching_the_server_is_set_up_only_with_a_url
|
|
92
|
+
render_command
|
|
93
|
+
assert_no_selector "[data-ui--command-url-value]"
|
|
94
|
+
render_command(url: "/search", param: "term", results_heading: "Customers")
|
|
95
|
+
assert_selector "[data-ui--command-url-value='/search'][data-ui--command-param-value='term'][data-ui--command-results-heading-value='Customers']"
|
|
96
|
+
assert_selector "template[data-ui--command-target='template']", visible: :all
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_messages_for_the_controller
|
|
100
|
+
render_command
|
|
101
|
+
assert_selector "[data-ui--command-empty-value='No results found.'][data-ui--command-searching-value='Searching…']"
|
|
102
|
+
assert_selector "[data-ui--command-target='empty'][hidden]", visible: :all
|
|
103
|
+
assert_selector "[data-ui--command-target='status'][role='status'][hidden]", visible: :all
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_custom_placeholder_label_and_attributes
|
|
107
|
+
render_inline(UI::Command.new(placeholder: "Find a page", label: "Site search", class: "max-w-md", data: { testid: "c" }))
|
|
108
|
+
assert_selector "[data-controller='ui--command'].max-w-md[data-testid='c'] input[placeholder='Find a page'][aria-label='Site search']"
|
|
109
|
+
end
|
|
110
|
+
end
|