|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test_helper' |
| 4 | + |
| 5 | +class RubyUI::SidebarTest < ComponentTest |
| 6 | + def test_render_with_all_items |
| 7 | + output = phlex do |
| 8 | + RubyUI.SidebarWrapper do |
| 9 | + RubyUI.Sidebar do |
| 10 | + RubyUI.SidebarHeader do |
| 11 | + RubyUI.SidebarGroup do |
| 12 | + RubyUI.SidebarGroupContent do |
| 13 | + RubyUI.SidebarInput(id: 'search', placeholder: 'Search the docs') |
| 14 | + end |
| 15 | + end |
| 16 | + end |
| 17 | + RubyUI.SidebarContent do |
| 18 | + RubyUI.SidebarGroup do |
| 19 | + RubyUI.SidebarGroupLabel { 'Application' } |
| 20 | + RubyUI.SidebarGroupAction { 'Group Action' } |
| 21 | + RubyUI.SidebarGroupContent do |
| 22 | + RubyUI.SidebarMenu do |
| 23 | + RubyUI.SidebarMenuItem do |
| 24 | + RubyUI.SidebarMenuSub do |
| 25 | + RubyUI.SidebarMenuSubItem do |
| 26 | + RubyUI.SidebarMenuSubButton(as: 'a', href: '#') { 'Sub Item 1' } |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | + RubyUI.SidebarMenuItem do |
| 31 | + RubyUI.SidebarMenuButton(as: 'a', href: '#') { 'Settings' } |
| 32 | + RubyUI.SidebarMenuAction { 'Settings' } |
| 33 | + end |
| 34 | + RubyUI.SidebarMenuItem do |
| 35 | + RubyUI.SidebarMenuButton { 'Dashboard' } |
| 36 | + RubyUI.SidebarMenuAction { 'Dashboard' } |
| 37 | + RubyUI.SidebarMenuBadge { 'Dashboard Badge' } |
| 38 | + end |
| 39 | + RubyUI.SidebarMenuItem do |
| 40 | + RubyUI.SidebarMenuSkeleton() |
| 41 | + end |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + RubyUI.SidebarFooter { 'Footer' } |
| 47 | + RubyUI.SidebarRail() |
| 48 | + end |
| 49 | + RubyUI.SidebarInset do |
| 50 | + RubyUI.SidebarTrigger() |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + assert_match(/Search the docs/, output) |
| 56 | + assert_match(/Application/, output) |
| 57 | + assert_match(/Group Action/, output) |
| 58 | + assert_match(/Sub Item 1/, output) |
| 59 | + assert_match(/Settings/, output) |
| 60 | + assert_match(/Dashboard/, output) |
| 61 | + assert_match(/Dashboard Badge/, output) |
| 62 | + assert_match(/Footer/, output) |
| 63 | + end |
| 64 | + |
| 65 | + def test_with_side_right |
| 66 | + output = phlex do |
| 67 | + RubyUI.Sidebar(side: :right) |
| 68 | + end |
| 69 | + |
| 70 | + assert_match(/data-side="right"/, output) |
| 71 | + end |
| 72 | + |
| 73 | + def test_with_variant_floating |
| 74 | + output = phlex do |
| 75 | + RubyUI.Sidebar(variant: :floating) |
| 76 | + end |
| 77 | + |
| 78 | + assert_match(/data-variant="floating"/, output) |
| 79 | + end |
| 80 | + |
| 81 | + def test_with_collapsible_icon |
| 82 | + output = phlex do |
| 83 | + RubyUI.Sidebar(collapsible: :icon) |
| 84 | + end |
| 85 | + |
| 86 | + assert_match(/data-collapsible-kind="icon"/, output) |
| 87 | + end |
| 88 | + |
| 89 | + def test_with_open_false |
| 90 | + output = phlex do |
| 91 | + RubyUI.Sidebar(open: false) |
| 92 | + end |
| 93 | + |
| 94 | + assert_match(/data-state="collapsed"/, output) |
| 95 | + end |
| 96 | + |
| 97 | + def test_with_collapsible_offcanvas |
| 98 | + output = phlex do |
| 99 | + RubyUI.Sidebar(collapsible: :offcanvas) |
| 100 | + end |
| 101 | + |
| 102 | + assert_match(/data-collapsible-kind="offcanvas"/, output) |
| 103 | + end |
| 104 | +end |
0 commit comments