debian-mirror-gitlab/spec/views/layouts/_head.html.haml_spec.rb

112 lines
3.2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'layouts/_head' do
2019-10-12 21:52:04 +05:30
include StubConfiguration
2018-03-17 18:26:18 +05:30
before do
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
2019-12-21 20:55:43 +05:30
allow(view).to receive(:experiment_enabled?).and_return(false)
2018-03-17 18:26:18 +05:30
end
2016-09-13 17:45:13 +05:30
it 'escapes HTML-safe strings in page_title' do
stub_helper_with_safe_string(:page_title)
render
expect(rendered).to match(%{content="foo" http-equiv="refresh"})
end
it 'escapes HTML-safe strings in page_description' do
stub_helper_with_safe_string(:page_description)
render
expect(rendered).to match(%{content="foo" http-equiv="refresh"})
end
it 'escapes HTML-safe strings in page_image' do
stub_helper_with_safe_string(:page_image)
render
expect(rendered).to match(%{content="foo" http-equiv="refresh"})
end
2020-04-22 19:07:51 +05:30
context 'when an asset_host is set' do
2018-11-18 11:00:15 +05:30
let(:asset_host) { 'http://assets' }
before do
allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
end
2020-04-22 19:07:51 +05:30
it 'adds a link dns-prefetch tag' do
2018-11-18 11:00:15 +05:30
render
2020-04-22 19:07:51 +05:30
expect(rendered).to match(%Q(<link href="#{asset_host}" rel="dns-prefetch">))
2018-11-18 11:00:15 +05:30
end
2020-04-22 19:07:51 +05:30
it 'adds a link preconnect tag' do
2018-11-18 11:00:15 +05:30
render
2020-04-22 19:07:51 +05:30
2020-06-23 00:09:42 +05:30
expect(rendered).to match(%Q(<link crossorigin="" href="#{asset_host}" rel="preconnect">))
2018-11-18 11:00:15 +05:30
end
end
2019-07-07 11:18:12 +05:30
it 'adds selected syntax highlight stylesheet' do
allow_any_instance_of(PreferencesHelper).to receive(:user_color_scheme).and_return("solarised-light")
render
expect(rendered).to match('<link rel="stylesheet" media="all" href="/stylesheets/highlight/themes/solarised-light.css" />')
end
2019-10-12 21:52:04 +05:30
context 'when an asset_host is set and snowplow url is set' do
let(:asset_host) { 'http://test.host' }
2020-06-23 00:09:42 +05:30
let(:snowplow_collector_hostname) { 'www.snow.plow' }
2019-10-12 21:52:04 +05:30
before do
allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
allow(Gitlab::CurrentSettings).to receive(:snowplow_enabled?).and_return(true)
2020-06-23 00:09:42 +05:30
allow(Gitlab::CurrentSettings).to receive(:snowplow_collector_hostname).and_return(snowplow_collector_hostname)
2019-10-12 21:52:04 +05:30
end
2019-12-26 22:10:19 +05:30
it 'adds a snowplow script tag with asset host' do
2019-10-12 21:52:04 +05:30
render
expect(rendered).to match('http://test.host/assets/snowplow/')
expect(rendered).to match('window.snowplow')
2020-06-23 00:09:42 +05:30
expect(rendered).to match(snowplow_collector_hostname)
end
it 'adds a link preconnect tag' do
render
expect(rendered).to match(%Q(<link crossorigin="" href="#{snowplow_collector_hostname}" rel="preconnect">))
2019-10-12 21:52:04 +05:30
end
end
2021-02-22 17:27:13 +05:30
context 'when a Matomo config is set' do
let(:matomo_host) { 'matomo.example.com' }
2019-10-12 21:52:04 +05:30
before do
stub_config(extra: {
2021-02-22 17:27:13 +05:30
matomo_url: matomo_host,
matomo_site_id: 12345
2019-10-12 21:52:04 +05:30
})
end
2021-02-22 17:27:13 +05:30
it 'add a Matomo Javascript' do
2019-10-12 21:52:04 +05:30
render
2021-02-22 17:27:13 +05:30
expect(rendered).to match(/<script.*>.*var u="\/\/#{matomo_host}\/".*<\/script>/m)
expect(rendered).to match(%r(<noscript>.*<img src="//#{matomo_host}/matomo.php.*</noscript>))
2019-10-12 21:52:04 +05:30
end
end
2016-09-13 17:45:13 +05:30
def stub_helper_with_safe_string(method)
allow_any_instance_of(PageLayoutHelper).to receive(method)
.and_return(%q{foo" http-equiv="refresh}.html_safe)
end
end