test: make tests more structural, less dependend on specific values
This commit is contained in:
parent
3381fd88db
commit
d6173571b5
1 changed files with 84 additions and 69 deletions
|
|
@ -122,35 +122,33 @@ defmodule MvWeb.Layouts.SidebarTest do
|
|||
test "T2.2: does not render menu items when current_user is nil" do
|
||||
html = render_sidebar(guest_assigns())
|
||||
|
||||
# Navigation links should not be rendered
|
||||
refute html =~ ~s(href="/members")
|
||||
refute html =~ ~s(href="/users")
|
||||
refute html =~ ~s(href="/settings")
|
||||
refute html =~ ~s(href="/contribution_types")
|
||||
# Navigation menu should not be rendered
|
||||
refute html =~ ~s(role="menubar")
|
||||
refute html =~ ~s(role="menuitem")
|
||||
|
||||
# Footer section should not be rendered
|
||||
refute html =~ "locale-select"
|
||||
refute html =~ "theme-controller"
|
||||
refute html =~ "locale-select"
|
||||
end
|
||||
|
||||
test "T2.3: renders menu items when current_user is present" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Check for Members link
|
||||
assert html =~ ~s(href="/members")
|
||||
# Check that menu structure exists
|
||||
assert html =~ ~s(role="menubar")
|
||||
assert html =~ ~s(role="menuitem")
|
||||
|
||||
# Check for Users link
|
||||
assert html =~ ~s(href="/users")
|
||||
# Check that top-level menu items exist (at least one)
|
||||
# Count menu items with tooltips (top-level items have tooltips)
|
||||
menu_item_count = html |> String.split("data-tip=") |> length() |> Kernel.-(1)
|
||||
assert menu_item_count > 0, "Should have at least one top-level menu item"
|
||||
|
||||
# Check for Custom Fields link
|
||||
assert html =~ ~s(href="/custom_field_values")
|
||||
# Check that nested menu groups exist
|
||||
assert html =~ "<details"
|
||||
assert has_class?(html, "expanded-menu-group")
|
||||
|
||||
# Check for Contributions section
|
||||
assert html =~ ~s(href="/contribution_types")
|
||||
assert html =~ ~s(href="/membership_fee_settings")
|
||||
|
||||
# Check for Settings link (placeholder)
|
||||
assert html =~ ~s(href="/settings")
|
||||
# Check that nested menu items exist
|
||||
assert html =~ ~s(role="menu")
|
||||
end
|
||||
|
||||
test "T2.4: renders sidebar with main-sidebar ID" do
|
||||
|
|
@ -174,51 +172,58 @@ defmodule MvWeb.Layouts.SidebarTest do
|
|||
test "T3.1: renders flat menu items with icons and labels" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Check for Members link with icon
|
||||
assert html =~ ~s(href="/members")
|
||||
assert html =~ "hero-users"
|
||||
|
||||
# Check for Users link with icon
|
||||
assert html =~ ~s(href="/users")
|
||||
assert html =~ "hero-user-circle"
|
||||
|
||||
# Check for Custom Fields link with icon
|
||||
assert html =~ ~s(href="/custom_field_values")
|
||||
assert html =~ "hero-rectangle-group"
|
||||
|
||||
# Check for Settings link with icon
|
||||
assert html =~ ~s(href="/settings")
|
||||
assert html =~ "hero-cog-6-tooth"
|
||||
|
||||
# Check for tooltips (data-tip attribute)
|
||||
# Check that top-level menu items have structure
|
||||
# Top-level items have tooltips
|
||||
assert html =~ "data-tip="
|
||||
assert has_class?(html, "tooltip")
|
||||
assert has_class?(html, "tooltip-right")
|
||||
|
||||
# Check that menu items have icons (hero-* classes)
|
||||
assert html =~ ~r/hero-\w+/
|
||||
|
||||
# Check that menu items have labels
|
||||
assert has_class?(html, "menu-label")
|
||||
|
||||
# Check that menu items have links
|
||||
assert html =~ ~s(role="menuitem")
|
||||
end
|
||||
|
||||
test "T3.2: renders nested menu with details element for expanded state" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Check for Contributions section structure with details
|
||||
# Check for nested menu structure
|
||||
assert html =~ "<details"
|
||||
assert html =~ "<summary"
|
||||
assert has_class?(html, "expanded-menu-group")
|
||||
|
||||
# Check for contribution links
|
||||
assert html =~ ~s(href="/contribution_types")
|
||||
assert html =~ ~s(href="/membership_fee_settings")
|
||||
# Check that nested menu has subitems
|
||||
assert html =~ ~s(role="menu")
|
||||
|
||||
# Check that subitems exist (at least one link in nested menu)
|
||||
# Submenu items have role="menuitem" but no data-tip attribute
|
||||
# (Top-level items have data-tip, nested items don't)
|
||||
# Count menuitems vs data-tips - nested items don't have data-tip
|
||||
menuitem_count = html |> String.split(~s(role="menuitem")) |> length() |> Kernel.-(1)
|
||||
data_tip_count = html |> String.split("data-tip=") |> length() |> Kernel.-(1)
|
||||
|
||||
# There should be more menuitems than data-tips (nested items don't have data-tip)
|
||||
assert menuitem_count > data_tip_count,
|
||||
"Should have nested menu items (menuitems without data-tip)"
|
||||
end
|
||||
|
||||
test "T3.3: renders nested menu with dropdown for collapsed state" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Check for collapsed dropdown container
|
||||
# Check for collapsed dropdown structure
|
||||
assert has_class?(html, "collapsed-menu-group")
|
||||
assert has_class?(html, "dropdown")
|
||||
assert has_class?(html, "dropdown-right")
|
||||
|
||||
# Check for dropdown-content
|
||||
assert has_class?(html, "dropdown-content")
|
||||
|
||||
# Check for icon button
|
||||
assert html =~ "hero-currency-dollar"
|
||||
# Check that dropdown button has icon (any hero icon)
|
||||
assert html =~ ~r/hero-\w+/
|
||||
|
||||
# Check ARIA attributes
|
||||
assert html =~ ~s(aria-haspopup="menu")
|
||||
end
|
||||
end
|
||||
|
|
@ -414,17 +419,17 @@ defmodule MvWeb.Layouts.SidebarTest do
|
|||
test "T7.1: renders hero icons for menu items" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Check for hero icons
|
||||
assert html =~ "hero-users"
|
||||
assert html =~ "hero-user-circle"
|
||||
assert html =~ "hero-rectangle-group"
|
||||
assert html =~ "hero-currency-dollar"
|
||||
assert html =~ "hero-cog-6-tooth"
|
||||
# Check that hero icons are present (pattern matching)
|
||||
assert html =~ ~r/hero-\w+/
|
||||
|
||||
# Check that icons have aria-hidden
|
||||
assert html =~ ~s(aria-hidden="true")
|
||||
|
||||
# Check for specific structural icons (toggle, theme) that should always exist
|
||||
assert html =~ "hero-chevron-left"
|
||||
assert html =~ "hero-chevron-right"
|
||||
|
||||
# Icons should have aria-hidden
|
||||
assert html =~ ~s(aria-hidden="true")
|
||||
assert html =~ "hero-sun"
|
||||
assert html =~ "hero-moon"
|
||||
end
|
||||
|
||||
test "T7.2: renders icons for theme toggle" do
|
||||
|
|
@ -503,26 +508,24 @@ defmodule MvWeb.Layouts.SidebarTest do
|
|||
|
||||
# Header section
|
||||
assert html =~ "Mila Logo"
|
||||
assert html =~ ~s(src="/images/mila.svg")
|
||||
|
||||
# Navigation section
|
||||
assert html =~ ~s(role="menubar")
|
||||
assert html =~ ~s(id="main-sidebar")
|
||||
|
||||
# Check that menu has items (at least one top-level item)
|
||||
assert html =~ ~s(role="menuitem")
|
||||
|
||||
# Check that nested menus exist
|
||||
assert html =~ "<details"
|
||||
|
||||
# Footer section
|
||||
assert html =~ "theme-controller"
|
||||
assert html =~ ~s(action="/set_locale")
|
||||
|
||||
# All expected links
|
||||
expected_links = [
|
||||
"/members",
|
||||
"/users",
|
||||
"/custom_field_values",
|
||||
"/contribution_types",
|
||||
"/membership_fee_settings",
|
||||
"/sign-out"
|
||||
]
|
||||
|
||||
for link <- expected_links do
|
||||
assert html =~ ~s(href="#{link}"), "Missing link: #{link}"
|
||||
end
|
||||
# Check that critical navigation exists (at least /members)
|
||||
assert html =~ ~s(href="/members"), "Critical /members route should exist"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -639,9 +642,21 @@ defmodule MvWeb.Layouts.SidebarTest do
|
|||
test "renders submenu items" do
|
||||
html = render_sidebar(authenticated_assigns())
|
||||
|
||||
# Inner_block items rendered
|
||||
assert html =~ ~s(href="/contribution_types")
|
||||
assert html =~ ~s(href="/membership_fee_settings")
|
||||
# Check that nested menu structure exists
|
||||
assert html =~ ~s(role="menu")
|
||||
|
||||
# Check that subitems are rendered (links within nested menu)
|
||||
# Submenu items have role="menuitem" but no data-tip attribute
|
||||
# (Top-level items have data-tip, nested items don't)
|
||||
# Count menuitems vs data-tips - nested items don't have data-tip
|
||||
menuitem_count = html |> String.split(~s(role="menuitem")) |> length() |> Kernel.-(1)
|
||||
data_tip_count = html |> String.split("data-tip=") |> length() |> Kernel.-(1)
|
||||
|
||||
# There should be more menuitems than data-tips (nested items don't have data-tip)
|
||||
assert menuitem_count > data_tip_count,
|
||||
"Should have nested menu items (menuitems without data-tip)"
|
||||
|
||||
# Verify nested menu structure exists
|
||||
assert html =~ ~s(role="menu")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue