Add render method to notification item component

This commit is contained in:
taitus
2024-06-25 17:08:03 +02:00
parent 1a8676f2d4
commit 1e6901ec34
3 changed files with 29 additions and 12 deletions

View File

@@ -1,4 +1,3 @@
<% if user %>
<li id="notifications"> <li id="notifications">
<%= link_to notifications_path, rel: "nofollow", <%= link_to notifications_path, rel: "nofollow",
title: text, title: text,
@@ -9,4 +8,3 @@
<span class="show-for-small-only"><%= text %></span> <span class="show-for-small-only"><%= text %></span>
<% end %> <% end %>
</li> </li>
<% end %>

View File

@@ -5,6 +5,10 @@ class Layout::NotificationItemComponent < ApplicationComponent
@user = user @user = user
end end
def render?
user.present?
end
private private
def text def text

View File

@@ -0,0 +1,15 @@
require "rails_helper"
describe Layout::NotificationItemComponent do
it "is not rendered for anonymous users" do
render_inline Layout::NotificationItemComponent.new(nil)
expect(page).not_to be_rendered
end
it "is rendered for identified users" do
render_inline Layout::NotificationItemComponent.new(create(:user))
expect(page).to be_rendered
end
end