Test title helpers for custom anon display names

This commit is contained in:
Karina Kwiatek 2022-06-21 15:22:54 +02:00 committed by Karina Kwiatek
parent d1ad34eb9c
commit 0196a9ea10
1 changed files with 43 additions and 29 deletions

View File

@ -1,81 +1,95 @@
# frozen_string_literal: true
require 'rails_helper'
require "rails_helper"
describe ApplicationHelper::TitleMethods, :type => :helper do
describe ApplicationHelper::TitleMethods, type: :helper do
let(:user) { FactoryBot.create(:user) }
before do
stub_const("APP_CONFIG", {
'site_name' => 'Waschmaschine',
'anonymous_name' => 'Anonymous',
'https' => true,
'items_per_page' => 5,
'sharing' => {}
})
"site_name" => "Waschmaschine",
"anonymous_name" => "Anonymous",
"https" => true,
"items_per_page" => 5,
"sharing" => {}
})
user.profile.display_name = 'Cool Man'
user.profile.display_name = "Cool Man"
user.profile.save!
end
describe "#generate_title" do
it 'should generate a proper title' do
expect(generate_title('Simon', 'says:', 'Nice!')).to eq('Simon says: Nice! | Waschmaschine')
it "should generate a proper title" do
expect(generate_title("Simon", "says:", "Nice!")).to eq("Simon says: Nice! | Waschmaschine")
end
it 'should only append a single quote to names that end with s' do
expect(generate_title('Andreas', 'says:', 'Cool!', true)).to eq('Andreas\' says: Cool! | Waschmaschine')
it "should only append a single quote to names that end with s" do
expect(generate_title("Andreas", "says:", "Cool!", true)).to eq("Andreas' says: Cool! | Waschmaschine")
end
it 'should cut content that is too long' do
expect(generate_title('A title', 'with', 'a' * 50)).to eq('A title with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa… | Waschmaschine')
it "should cut content that is too long" do
expect(generate_title("A title", "with", "a" * 50)).to eq("A title with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa… | Waschmaschine")
end
end
describe "#question_title" do
let(:question) { FactoryBot.create(:question) }
let(:question) { FactoryBot.create(:question, direct: true) }
it 'should generate a proper title for the question' do
it "should generate a proper title for the question" do
expect(question_title(question)).to eq("Anonymous asked #{question.content} | Waschmaschine")
end
context "user has custom anonymous display name" do
before do
FactoryBot.create(:answer, question: question, user: user)
user.profile.anon_display_name = "Amogus"
user.profile.save!
end
it "should generate a proper title for the question with a custom anonymous display name" do
expect(question_title(question)).to eq("Amogus asked #{question.content} | Waschmaschine")
end
end
end
describe "#answer_title" do
let(:answer) { FactoryBot.create(:answer, user: user,
content: 'a',
question_content: 'q') }
let(:answer) do
FactoryBot.create(:answer, user: user,
content: "a",
question_content: "q")
end
it 'should generate a proper title' do
expect(answer_title(answer)).to eq('Cool Man answered q | Waschmaschine')
it "should generate a proper title" do
expect(answer_title(answer)).to eq("Cool Man answered q | Waschmaschine")
end
end
describe "#user_title" do
it 'should generate a proper title' do
it "should generate a proper title" do
expect(user_title(user)).to eq("Cool Man | Waschmaschine")
end
end
describe "#questions_title" do
it 'should generate a proper title' do
it "should generate a proper title" do
expect(questions_title(user)).to eq("Cool Man's questions | Waschmaschine")
end
end
describe "#answers_title" do
it 'should generate a proper title' do
it "should generate a proper title" do
expect(answers_title(user)).to eq("Cool Man's answers | Waschmaschine")
end
end
describe "#smiles_title" do
it 'should generate a proper title' do
it "should generate a proper title" do
expect(smiles_title(user)).to eq("Cool Man's smiles | Waschmaschine")
end
end
describe "#comments_title" do
it 'should generate a proper title' do
it "should generate a proper title" do
expect(comments_title(user)).to eq("Cool Man's comments | Waschmaschine")
end
end
@ -83,8 +97,8 @@ describe ApplicationHelper::TitleMethods, :type => :helper do
describe "#list_title" do
let(:list) { FactoryBot.create(:list) }
it 'should generate a proper title' do
it "should generate a proper title" do
expect(list_title(list)).to eq("#{list.name} | Waschmaschine")
end
end
end
end