2019-09-30 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2015-12-23 21:56:27 +00:00
|
|
|
|
|
|
|
describe PageLayoutHelper do
|
|
|
|
describe 'page_description' do
|
2016-01-06 12:02:51 +00:00
|
|
|
it 'defaults to nil' do
|
|
|
|
expect(helper.page_description).to eq nil
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the last-pushed description' do
|
|
|
|
helper.page_description('Foo')
|
|
|
|
helper.page_description('Bar')
|
|
|
|
helper.page_description('Baz')
|
|
|
|
|
|
|
|
expect(helper.page_description).to eq 'Baz'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'squishes multiple newlines' do
|
|
|
|
helper.page_description("Foo\nBar\nBaz")
|
|
|
|
|
|
|
|
expect(helper.page_description).to eq 'Foo Bar Baz'
|
|
|
|
end
|
|
|
|
|
2015-12-24 21:26:52 +00:00
|
|
|
it 'truncates' do
|
|
|
|
helper.page_description <<-LOREM.strip_heredoc
|
|
|
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
|
|
|
|
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis
|
|
|
|
dis parturient montes, nascetur ridiculus mus. Donec quam felis,
|
|
|
|
ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa
|
|
|
|
quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget,
|
|
|
|
arcu.
|
|
|
|
LOREM
|
|
|
|
|
|
|
|
expect(helper.page_description).to end_with 'quam felis,...'
|
|
|
|
end
|
|
|
|
|
2015-12-23 21:56:27 +00:00
|
|
|
it 'sanitizes all HTML' do
|
|
|
|
helper.page_description("<b>Bold</b> <h1>Header</h1>")
|
|
|
|
|
|
|
|
expect(helper.page_description).to eq 'Bold Header'
|
|
|
|
end
|
2019-05-22 14:30:10 +00:00
|
|
|
|
|
|
|
it 'truncates before sanitizing' do
|
|
|
|
helper.page_description('<b>Bold</b> <img> <img> <img> <h1>Header</h1> ' * 10)
|
|
|
|
|
|
|
|
# 12 words because <img> was counted as a word
|
|
|
|
expect(helper.page_description)
|
|
|
|
.to eq('Bold Header Bold Header Bold Header Bold Header Bold Header Bold Header...')
|
|
|
|
end
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'page_image' do
|
|
|
|
it 'defaults to the GitLab logo' do
|
2017-10-03 14:47:56 +00:00
|
|
|
expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png'
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
|
|
|
|
2016-01-05 19:50:52 +00:00
|
|
|
%w(project user group).each do |type|
|
|
|
|
context "with @#{type} assigned" do
|
|
|
|
it "uses #{type.titlecase} avatar if available" do
|
2017-07-17 13:46:59 +00:00
|
|
|
object = double(avatar_url: 'http://example.com/uploads/-/system/avatar.png')
|
2016-01-05 19:50:52 +00:00
|
|
|
assign(type, object)
|
2015-12-23 21:56:27 +00:00
|
|
|
|
2016-01-05 19:50:52 +00:00
|
|
|
expect(helper.page_image).to eq object.avatar_url
|
|
|
|
end
|
2015-12-23 21:56:27 +00:00
|
|
|
|
2016-01-05 19:50:52 +00:00
|
|
|
it 'falls back to the default when avatar_url is nil' do
|
|
|
|
object = double(avatar_url: nil)
|
|
|
|
assign(type, object)
|
2015-12-23 21:56:27 +00:00
|
|
|
|
2017-10-03 14:47:56 +00:00
|
|
|
expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png'
|
2016-01-05 19:50:52 +00:00
|
|
|
end
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
2015-12-28 00:49:48 +00:00
|
|
|
|
2016-01-05 19:50:52 +00:00
|
|
|
context "with no assignments" do
|
|
|
|
it 'falls back to the default' do
|
2017-10-03 14:47:56 +00:00
|
|
|
expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png'
|
2016-01-05 19:50:52 +00:00
|
|
|
end
|
2015-12-28 00:49:48 +00:00
|
|
|
end
|
|
|
|
end
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
2015-12-24 22:03:54 +00:00
|
|
|
|
|
|
|
describe 'page_card_attributes' do
|
|
|
|
it 'raises ArgumentError when given more than two attributes' do
|
|
|
|
map = { foo: 'foo', bar: 'bar', baz: 'baz' }
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect { helper.page_card_attributes(map) }
|
|
|
|
.to raise_error(ArgumentError, /more than two attributes/)
|
2015-12-24 22:03:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects blank values' do
|
|
|
|
map = { foo: 'foo', bar: '' }
|
|
|
|
helper.page_card_attributes(map)
|
|
|
|
|
|
|
|
expect(helper.page_card_attributes).to eq({ foo: 'foo' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'page_card_meta_tags' do
|
|
|
|
it 'returns the twitter:label and twitter:data tags' do
|
|
|
|
allow(helper).to receive(:page_card_attributes).and_return(foo: 'bar')
|
|
|
|
|
|
|
|
tags = helper.page_card_meta_tags
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(tags).to include %q(<meta property="twitter:label1" content="foo" />)
|
|
|
|
expect(tags).to include %q(<meta property="twitter:data1" content="bar" />)
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 18:20:50 +00:00
|
|
|
|
|
|
|
it 'escapes content' do
|
|
|
|
allow(helper).to receive(:page_card_attributes)
|
|
|
|
.and_return(foo: %q{foo" http-equiv="refresh}.html_safe)
|
|
|
|
|
|
|
|
tags = helper.page_card_meta_tags
|
|
|
|
|
|
|
|
expect(tags).to include(%q{content="foo" http-equiv="refresh"})
|
|
|
|
end
|
2015-12-24 22:03:54 +00:00
|
|
|
end
|
2020-06-02 00:08:07 +00:00
|
|
|
|
|
|
|
describe '#search_context' do
|
|
|
|
subject(:search_context) { helper.search_context }
|
|
|
|
|
|
|
|
describe 'a bare controller' do
|
|
|
|
it 'returns an empty context' do
|
|
|
|
expect(search_context).to have_attributes(project: nil,
|
|
|
|
group: nil,
|
|
|
|
snippets: [],
|
|
|
|
project_metadata: {},
|
|
|
|
group_metadata: {},
|
|
|
|
search_url: '/search')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|