2019-10-08 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 18:20:50 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe 'layouts/_head' do
|
2019-08-26 20:03:42 +00:00
|
|
|
include StubConfiguration
|
|
|
|
|
2017-08-31 09:47:03 +00:00
|
|
|
before do
|
|
|
|
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
|
2019-10-18 21:06:37 +00:00
|
|
|
allow(view).to receive(:experiment_enabled?).and_return(false)
|
2017-08-31 09:47:03 +00:00
|
|
|
end
|
|
|
|
|
2016-08-18 18:20:50 +00:00
|
|
|
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-03-19 15:09:41 +00:00
|
|
|
context 'when an asset_host is set' do
|
2018-07-26 15:00:18 +00:00
|
|
|
let(:asset_host) { 'http://assets' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
|
|
|
|
end
|
|
|
|
|
2020-03-19 15:09:41 +00:00
|
|
|
it 'adds a link dns-prefetch tag' do
|
2018-07-26 15:00:18 +00:00
|
|
|
render
|
|
|
|
|
2020-03-19 15:09:41 +00:00
|
|
|
expect(rendered).to match(%Q(<link href="#{asset_host}" rel="dns-prefetch">))
|
2018-07-26 15:00:18 +00:00
|
|
|
end
|
|
|
|
|
2020-03-19 15:09:41 +00:00
|
|
|
it 'adds a link preconnect tag' do
|
2018-07-26 15:00:18 +00:00
|
|
|
render
|
2020-03-19 15:09:41 +00:00
|
|
|
|
2020-05-28 12:08:10 +00:00
|
|
|
expect(rendered).to match(%Q(<link crossorigin="" href="#{asset_host}" rel="preconnect">))
|
2018-07-26 15:00:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-14 06:54:34 +00:00
|
|
|
it 'adds selected syntax highlight stylesheet' do
|
|
|
|
allow_any_instance_of(PreferencesHelper).to receive(:user_color_scheme).and_return("solarised-light")
|
|
|
|
|
|
|
|
render
|
|
|
|
|
2021-01-11 18:10:43 +00:00
|
|
|
expect(rendered).to match('<link rel="stylesheet" media="print" href="/stylesheets/highlight/themes/solarised-light.css" />')
|
2019-02-14 06:54:34 +00:00
|
|
|
end
|
|
|
|
|
2019-08-14 19:21:58 +00:00
|
|
|
context 'when an asset_host is set and snowplow url is set' do
|
|
|
|
let(:asset_host) { 'http://test.host' }
|
2020-06-05 21:08:27 +00:00
|
|
|
let(:snowplow_collector_hostname) { 'www.snow.plow' }
|
2019-08-14 19:21:58 +00:00
|
|
|
|
|
|
|
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-05 21:08:27 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:snowplow_collector_hostname).and_return(snowplow_collector_hostname)
|
2019-08-14 19:21:58 +00:00
|
|
|
end
|
|
|
|
|
2019-10-22 21:06:42 +00:00
|
|
|
it 'adds a snowplow script tag with asset host' do
|
2019-08-14 19:21:58 +00:00
|
|
|
render
|
|
|
|
expect(rendered).to match('http://test.host/assets/snowplow/')
|
|
|
|
expect(rendered).to match('window.snowplow')
|
2020-06-05 21:08:27 +00:00
|
|
|
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-08-14 19:21:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-25 18:09:53 +00:00
|
|
|
context 'when a Matomo config is set' do
|
|
|
|
let(:matomo_host) { 'matomo.example.com' }
|
2019-08-26 20:03:42 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_config(extra: {
|
2020-11-25 18:09:53 +00:00
|
|
|
matomo_url: matomo_host,
|
2021-02-10 21:09:24 +00:00
|
|
|
matomo_site_id: 12345,
|
|
|
|
matomo_disable_cookies: false
|
2019-08-26 20:03:42 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-11-25 18:09:53 +00:00
|
|
|
it 'add a Matomo Javascript' do
|
2019-08-26 20:03:42 +00:00
|
|
|
render
|
|
|
|
|
2021-07-08 18:09:32 +00:00
|
|
|
expect(rendered).to match(%r{<script.*>.*var u="//#{matomo_host}/".*</script>}m)
|
2020-11-25 18:09:53 +00:00
|
|
|
expect(rendered).to match(%r(<noscript>.*<img src="//#{matomo_host}/matomo.php.*</noscript>))
|
2021-02-10 21:09:24 +00:00
|
|
|
expect(rendered).not_to include('_paq.push(["disableCookies"])')
|
2019-08-26 20:03:42 +00:00
|
|
|
end
|
2021-02-02 12:10:15 +00:00
|
|
|
|
2021-02-10 21:09:24 +00:00
|
|
|
context 'when matomo_disable_cookies is true' do
|
|
|
|
before do
|
|
|
|
stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: true })
|
2021-02-02 12:10:15 +00:00
|
|
|
end
|
|
|
|
|
2021-02-10 21:09:24 +00:00
|
|
|
it 'disables cookies' do
|
|
|
|
render
|
2021-02-02 12:10:15 +00:00
|
|
|
|
2021-02-10 21:09:24 +00:00
|
|
|
expect(rendered).to include('_paq.push(["disableCookies"])')
|
2021-02-02 12:10:15 +00:00
|
|
|
end
|
|
|
|
end
|
2019-08-26 20:03:42 +00:00
|
|
|
end
|
|
|
|
|
2016-08-18 18:20:50 +00:00
|
|
|
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
|