test: add tdd tests for #170
This commit is contained in:
parent
52e76b1a99
commit
6033e33622
3 changed files with 232 additions and 0 deletions
76
test/mv_web/components/layouts/navbar_test.exs
Normal file
76
test/mv_web/components/layouts/navbar_test.exs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
defmodule MvWeb.Layouts.NavbarTest do
|
||||
use MvWeb.ConnCase, async: true
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
describe "navbar profile section" do
|
||||
test "renders profile button with correct attributes", %{conn: _conn} do
|
||||
# Setup: Create a user
|
||||
user = create_test_user(%{email: "test@example.com"})
|
||||
|
||||
html = render_component(&MvWeb.Layouts.Navbar.navbar/1, %{
|
||||
current_user: user
|
||||
})
|
||||
|
||||
# Test dropdown structure
|
||||
assert html =~ "dropdown-content"
|
||||
assert html =~ "dropdown-end"
|
||||
assert html =~ ~s(role="button")
|
||||
|
||||
# Test profile link
|
||||
assert html =~ ~s(href="/users/#{user.id}")
|
||||
assert html =~ "Profil"
|
||||
end
|
||||
|
||||
test "shows user initials in avatar", %{conn: _conn} do
|
||||
# Setup: Create a user with specific email for testing initials
|
||||
user = create_test_user(%{email: "test.user@example.com"})
|
||||
|
||||
html = render_component(&MvWeb.Layouts.Navbar.navbar/1, %{
|
||||
current_user: user
|
||||
})
|
||||
|
||||
assert html =~ "<span>TU</span>" # Initials from test.user@example.com
|
||||
end
|
||||
|
||||
test "shows different initials for OIDC user", %{conn: _conn} do
|
||||
# Setup: Create OIDC user
|
||||
user_info = %{
|
||||
"sub" => "oidc_123",
|
||||
"preferred_username" => "oidc.user@example.com"
|
||||
}
|
||||
oauth_tokens = %{
|
||||
"access_token" => "test_token",
|
||||
"id_token" => "test_id_token"
|
||||
}
|
||||
|
||||
user = Mv.Accounts.User
|
||||
|> Ash.Changeset.for_create(:register_with_rauthy, %{
|
||||
user_info: user_info,
|
||||
oauth_tokens: oauth_tokens
|
||||
})
|
||||
|> Ash.create!(domain: Mv.Accounts)
|
||||
|
||||
html = render_component(&MvWeb.Layouts.Navbar.navbar/1, %{
|
||||
current_user: user
|
||||
})
|
||||
|
||||
assert html =~ "<span>OU</span>" # Initials from oidc.user@example.com
|
||||
end
|
||||
|
||||
test "includes all required navigation items", %{conn: _conn} do
|
||||
user = create_test_user(%{email: "test@example.com"})
|
||||
|
||||
html = render_component(&MvWeb.Layouts.Navbar.navbar/1, %{
|
||||
current_user: user
|
||||
})
|
||||
|
||||
# Check for all required menu items
|
||||
assert html =~ "Profil"
|
||||
assert html =~ "Settings"
|
||||
assert html =~ "Logout"
|
||||
|
||||
# Check for correct logout path
|
||||
assert html =~ ~s(href="sign-out")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue