2023-02-16 04:07:14 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe "inbox/show.html.haml", type: :view do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:rendered) { render }
|
|
|
|
|
|
|
|
context "with an empty inbox" do
|
|
|
|
before do
|
|
|
|
assign :inbox, []
|
|
|
|
end
|
|
|
|
|
|
|
|
it "displays an 'inbox is empty' message" do
|
2023-02-16 12:50:12 -08:00
|
|
|
html = Nokogiri::HTML.parse(rendered)
|
2023-12-10 13:09:21 -08:00
|
|
|
selector = "div.card.empty"
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).to have_css(selector)
|
2023-12-10 13:09:21 -08:00
|
|
|
expect(html.css(selector).text.strip).to include "Your inbox is empty!"
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with some inbox entries" do
|
2024-01-27 04:02:58 -08:00
|
|
|
let(:inbox_entry1) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
|
|
|
|
let(:inbox_entry2) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
|
2023-02-16 04:07:14 -08:00
|
|
|
|
|
|
|
before do
|
|
|
|
assign :inbox, [inbox_entry2, inbox_entry1]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders inbox entries" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).to have_css("#inbox_#{inbox_entry1.id}")
|
|
|
|
expect(rendered).to have_css("#inbox_#{inbox_entry2.id}")
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not contain the empty inbox message" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).not_to have_css("p.empty")
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not render the paginator" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).not_to have_css("#paginator")
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when more data is available" do
|
|
|
|
before do
|
|
|
|
assign :more_data_available, true
|
|
|
|
assign :inbox_last_id, 1337
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the paginator" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).to have_css("#paginator")
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the correct params on the button" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).to have_css(%(input[type="hidden"][name="last_id"][value="1337"]))
|
|
|
|
expect(rendered).not_to have_css(%(input[type="hidden"][name="author"]))
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when passed an author" do
|
|
|
|
before do
|
|
|
|
assign :author, "jyrki"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the correct params on the button" do
|
2023-02-16 12:50:12 -08:00
|
|
|
expect(rendered).to have_css(%(input[type="hidden"][name="last_id"][value="1337"]))
|
|
|
|
expect(rendered).to have_css(%(input[type="hidden"][name="author"]))
|
2023-02-16 04:07:14 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|