Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/webpack_helper_spec.rb')
-rw-r--r--spec/helpers/webpack_helper_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/helpers/webpack_helper_spec.rb b/spec/helpers/webpack_helper_spec.rb
new file mode 100644
index 00000000000..f9386c99dc3
--- /dev/null
+++ b/spec/helpers/webpack_helper_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe WebpackHelper do
+ let(:source) { 'foo.js' }
+ let(:asset_path) { "/assets/webpack/#{source}" }
+
+ describe '#prefetch_link_tag' do
+ it 'returns prefetch link tag' do
+ expect(helper.prefetch_link_tag(source)).to eq("<link rel=\"prefetch\" href=\"/#{source}\">")
+ end
+ end
+
+ describe '#webpack_preload_asset_tag' do
+ before do
+ allow(Gitlab::Webpack::Manifest).to receive(:asset_paths).and_return([asset_path])
+ end
+
+ it 'preloads the resource by default' do
+ expect(helper).to receive(:preload_link_tag).with(asset_path, {}).and_call_original
+
+ output = helper.webpack_preload_asset_tag(source)
+
+ expect(output).to eq("<link rel=\"preload\" href=\"#{asset_path}\" as=\"script\" type=\"text/javascript\">")
+ end
+
+ it 'prefetches the resource if explicitly asked' do
+ expect(helper).to receive(:prefetch_link_tag).with(asset_path).and_call_original
+
+ output = helper.webpack_preload_asset_tag(source, prefetch: true)
+
+ expect(output).to eq("<link rel=\"prefetch\" href=\"#{asset_path}\">")
+ end
+ end
+end