|
2 | 2 |
|
3 | 3 | class NavbarComponentTest < ViewComponent::TestCase
|
4 | 4 | include ActionView::Helpers::TranslationHelper
|
5 |
| - |
| 5 | + |
6 | 6 | # Mock the component's helpers method for testing
|
7 | 7 | class TestNavbarComponent < NavbarComponent
|
8 | 8 | def helpers
|
9 | 9 | MockHelpers.new
|
10 | 10 | end
|
11 | 11 | end
|
12 |
| - |
| 12 | + |
13 | 13 | # Simple mock for helpers
|
14 | 14 | class MockHelpers
|
15 | 15 | def url_for(options)
|
16 | 16 | "#"
|
17 | 17 | end
|
18 |
| - |
| 18 | + |
19 | 19 | def respond_to?(method_name)
|
20 | 20 | method_name == :url_for || super
|
21 | 21 | end
|
22 | 22 | end
|
23 |
| - |
| 23 | + |
24 | 24 | setup do
|
25 | 25 | # No setup needed
|
26 | 26 | end
|
27 | 27 |
|
28 | 28 | def test_renders_guest_menu_when_not_signed_in
|
29 | 29 | component = TestNavbarComponent.new(current_user: nil)
|
30 | 30 | render_inline(component)
|
31 |
| - |
| 31 | + |
32 | 32 | # Guest menu links should be present
|
33 | 33 | assert_link t("nav.sign_in")
|
34 | 34 | assert_link t("nav.sign_up")
|
35 |
| - |
| 35 | + |
36 | 36 | # User menu elements should not be present
|
37 | 37 | assert_no_link t("nav.dashboard")
|
38 | 38 | assert_no_text t("nav.signed_in_as")
|
39 | 39 | end
|
40 |
| - |
| 40 | + |
41 | 41 | def test_renders_user_menu_when_signed_in
|
42 | 42 | user = User.new(email: "[email protected]")
|
43 | 43 | component = TestNavbarComponent.new(current_user: user)
|
44 | 44 | render_inline(component)
|
45 |
| - |
| 45 | + |
46 | 46 | # User menu elements should be present
|
47 | 47 | assert_link t("nav.dashboard")
|
48 | 48 | assert_link t("nav.profile")
|
49 | 49 | assert_link t("nav.sign_out")
|
50 |
| - |
| 50 | + |
51 | 51 | # Should show user email
|
52 | 52 |
|
53 |
| - |
| 53 | + |
54 | 54 | # Guest elements should not be present
|
55 | 55 | assert_no_link t("nav.sign_up")
|
56 | 56 | end
|
57 |
| - |
| 57 | + |
58 | 58 | def test_language_dropdown_is_always_present
|
59 | 59 | # Test with user not signed in
|
60 | 60 | component = TestNavbarComponent.new(current_user: nil)
|
61 | 61 | render_inline(component)
|
62 |
| - |
| 62 | + |
63 | 63 | # Should show current locale and language options
|
64 | 64 | assert_text I18n.locale.to_s.upcase
|
65 | 65 | assert_text "English (EN)"
|
|
0 commit comments