require "rails_helper"

RSpec.describe NotesHelper, type: :helper do
  describe "#notes_preview" do
    it "shows the content, timestamp, and author of the first note" do
      note = build(:note, 
                   content: "Note content", 
                   created_at: 1.minute.ago, 
                   user: build(:user, email: "author@example.org"),
                   email: "author@example.org"
                  )

      preview = helper.notes_preview([note])

      expect(preview).to include("Note content")
      expect(preview).to include("1 minute ago")
      expect(preview).to include("author@example.org")
    end

    context "when there are no notes" do
      it "returns nothing" do
        preview = helper.notes_preview([])

        expect(preview).to be_blank
      end
    end

    context "when there is more than one note" do
      it "includes a link to an action that shows all notes" do
        releasable = build_stubbed(:appearance_release)
        notes = build_list(:note, 2, created_at: 1.minute.ago, notable: releasable)

        preview = helper.notes_preview(notes)
        
        expect(preview).to have_link("1 more note", href: url_for([releasable, :notes, locale: I18n.locale]))
      end
    end
  end
end
