2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-10-04 06:29:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe IconsHelper do
|
2017-11-09 11:35:12 -05:00
|
|
|
let(:icons_path) { ActionController::Base.helpers.image_path("icons.svg") }
|
|
|
|
|
2017-11-09 06:23:14 -05:00
|
|
|
describe 'sprite_icon_path' do
|
2017-11-09 04:38:00 -05:00
|
|
|
it 'returns relative path' do
|
2020-07-14 08:09:14 -04:00
|
|
|
expect(sprite_icon_path).to eq(icons_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only calls image_path once when called multiple times' do
|
|
|
|
expect(ActionController::Base.helpers).to receive(:image_path).once.and_call_original
|
|
|
|
|
|
|
|
2.times { sprite_icon_path }
|
2017-11-09 04:38:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an asset_host is set in the config it will return an absolute local URL' do
|
|
|
|
let(:asset_host) { 'http://assets' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an absolute URL on that asset host' do
|
2017-11-09 17:55:57 -05:00
|
|
|
expect(sprite_icon_path)
|
2017-11-09 10:15:07 -05:00
|
|
|
.to eq ActionController::Base.helpers.image_path("icons.svg", host: Gitlab.config.gitlab.url)
|
2017-11-09 04:38:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-22 04:39:47 -04:00
|
|
|
describe 'sprite_icon' do
|
|
|
|
icon_name = 'clock'
|
|
|
|
|
2020-08-03 11:09:44 -04:00
|
|
|
it 'returns svg icon html with DEFAULT_ICON_SIZE' do
|
2017-09-22 04:39:47 -04:00
|
|
|
expect(sprite_icon(icon_name).to_s)
|
2020-08-03 11:09:44 -04:00
|
|
|
.to eq "<svg class=\"s#{IconsHelper::DEFAULT_ICON_SIZE}\" data-testid=\"#{icon_name}-icon\"><use xlink:href=\"#{icons_path}##{icon_name}\"></use></svg>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns svg icon html without size class' do
|
|
|
|
expect(sprite_icon(icon_name, size: nil).to_s)
|
2020-07-22 20:09:43 -04:00
|
|
|
.to eq "<svg data-testid=\"#{icon_name}-icon\"><use xlink:href=\"#{icons_path}##{icon_name}\"></use></svg>"
|
2017-09-22 04:39:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns svg icon html + size classes' do
|
|
|
|
expect(sprite_icon(icon_name, size: 72).to_s)
|
2020-07-22 20:09:43 -04:00
|
|
|
.to eq "<svg class=\"s72\" data-testid=\"#{icon_name}-icon\"><use xlink:href=\"#{icons_path}##{icon_name}\"></use></svg>"
|
2017-09-22 04:39:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns svg icon html + size classes + additional class' do
|
|
|
|
expect(sprite_icon(icon_name, size: 72, css_class: 'icon-danger').to_s)
|
2020-07-22 20:09:43 -04:00
|
|
|
.to eq "<svg class=\"s72 icon-danger\" data-testid=\"#{icon_name}-icon\"><use xlink:href=\"#{icons_path}##{icon_name}\"></use></svg>"
|
2017-09-22 04:39:47 -04:00
|
|
|
end
|
2018-07-18 12:56:19 -04:00
|
|
|
|
|
|
|
describe 'non existing icon' do
|
|
|
|
non_existing = 'non_existing_icon_sprite'
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'raises in development mode' do
|
2019-09-03 21:57:25 -04:00
|
|
|
stub_rails_env('development')
|
2018-07-18 12:56:19 -04:00
|
|
|
|
|
|
|
expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'raises in test mode' do
|
2019-09-03 21:57:25 -04:00
|
|
|
stub_rails_env('test')
|
2018-07-18 12:56:19 -04:00
|
|
|
|
|
|
|
expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not raise in production mode' do
|
2019-09-03 21:57:25 -04:00
|
|
|
stub_rails_env('production')
|
2018-07-18 12:56:19 -04:00
|
|
|
|
2020-11-19 16:09:07 -05:00
|
|
|
expect_file_not_to_read(Rails.root.join('node_modules/@gitlab/svgs/dist/icons.json'))
|
2019-12-14 13:07:40 -05:00
|
|
|
|
2018-07-18 12:56:19 -04:00
|
|
|
expect { sprite_icon(non_existing) }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2017-09-22 04:39:47 -04:00
|
|
|
end
|
|
|
|
|
2018-08-14 15:12:07 -04:00
|
|
|
describe 'audit icon' do
|
|
|
|
it 'returns right icon name for standard auth' do
|
|
|
|
icon_name = 'standard'
|
|
|
|
expect(audit_icon(icon_name).to_s)
|
2020-10-20 14:08:54 -04:00
|
|
|
.to eq sprite_icon('key')
|
2018-08-14 16:55:32 -04:00
|
|
|
end
|
2018-08-14 15:12:07 -04:00
|
|
|
|
|
|
|
it 'returns right icon name for two-factor auth' do
|
|
|
|
icon_name = 'two-factor'
|
|
|
|
expect(audit_icon(icon_name).to_s)
|
2020-10-20 14:08:54 -04:00
|
|
|
.to eq sprite_icon('key')
|
2018-08-14 15:12:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns right icon name for google_oauth2 auth' do
|
|
|
|
icon_name = 'google_oauth2'
|
|
|
|
expect(audit_icon(icon_name).to_s)
|
2020-10-20 14:08:54 -04:00
|
|
|
.to eq sprite_icon('google')
|
2018-08-14 15:12:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-04 06:29:18 -04:00
|
|
|
describe 'file_type_icon_class' do
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns folder-o class' do
|
|
|
|
expect(file_type_icon_class('folder', 0, 'folder_name')).to eq 'folder-o'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns share class' do
|
2015-04-01 23:32:16 -04:00
|
|
|
expect(file_type_icon_class('file', '120000', 'link')).to eq 'share'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns document class with .pdf' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.pdf')).to eq 'document'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-image class with .jpg' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.jpg')).to eq 'doc-image'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-image class with .JPG' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.JPG')).to eq 'doc-image'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-image class with .png' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.png')).to eq 'doc-image'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-image class with .apng' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.apng')).to eq 'doc-image'
|
2019-07-14 22:53:02 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-image class with .webp' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.webp')).to eq 'doc-image'
|
2019-07-14 22:53:02 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-compressed class with .tar' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.tar')).to eq 'doc-compressed'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-compressed class with .TAR' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.TAR')).to eq 'doc-compressed'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-compressed class with .tar.gz' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.tar.gz')).to eq 'doc-compressed'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns volume-up class with .mp3' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.mp3')).to eq 'volume-up'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns volume-up class with .MP3' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.MP3')).to eq 'volume-up'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns volume-up class with .m4a' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.m4a')).to eq 'volume-up'
|
2019-07-14 22:53:02 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns volume-up class with .wav' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.wav')).to eq 'volume-up'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns live-preview class with .avi' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.avi')).to eq 'live-preview'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns live-preview class with .AVI' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.AVI')).to eq 'live-preview'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns live-preview class with .mp4' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.mp4')).to eq 'live-preview'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with .odt' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.odt')).to eq 'doc-text'
|
2019-07-14 22:53:02 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with .doc' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.doc')).to eq 'doc-text'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with .DOC' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.DOC')).to eq 'doc-text'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with .docx' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.docx')).to eq 'doc-text'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns document class with .xls' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.xls')).to eq 'document'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns document class with .XLS' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.XLS')).to eq 'document'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns document class with .xlsx' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.xlsx')).to eq 'document'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-chart class with .odp' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.odp')).to eq 'doc-chart'
|
2019-07-14 22:53:02 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-chart class with .ppt' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.ppt')).to eq 'doc-chart'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-chart class with .PPT' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.PPT')).to eq 'doc-chart'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-chart class with .pptx' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.pptx')).to eq 'doc-chart'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with .unknow' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'filename.unknow')).to eq 'doc-text'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
it 'returns doc-text class with no extension' do
|
|
|
|
expect(file_type_icon_class('file', 0, 'CHANGELOG')).to eq 'doc-text'
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|
|
|
|
end
|
2018-02-06 08:33:18 -05:00
|
|
|
|
|
|
|
describe '#external_snippet_icon' do
|
|
|
|
it 'returns external snippet icon' do
|
|
|
|
expect(external_snippet_icon('download').to_s)
|
2018-03-03 05:43:53 -05:00
|
|
|
.to eq("<span class=\"gl-snippet-icon gl-snippet-icon-download\"></span>")
|
2018-02-06 08:33:18 -05:00
|
|
|
end
|
|
|
|
end
|
2020-07-13 17:09:24 -04:00
|
|
|
|
|
|
|
describe 'loading_icon' do
|
|
|
|
it 'returns span with gl-spinner class and default configuration' do
|
|
|
|
expect(loading_icon.to_s)
|
|
|
|
.to eq '<span class="gl-spinner gl-spinner-orange gl-spinner-sm" aria-label="Loading"></span>'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when css_class is provided' do
|
|
|
|
it 'appends css_class to gl-spinner element' do
|
|
|
|
expect(loading_icon(css_class: 'gl-mr-2').to_s)
|
|
|
|
.to eq '<span class="gl-spinner gl-spinner-orange gl-spinner-sm gl-mr-2" aria-label="Loading"></span>'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when container is true' do
|
|
|
|
it 'creates a container that has the gl-spinner-container class selector' do
|
|
|
|
expect(loading_icon(container: true).to_s)
|
|
|
|
.to eq '<div class="gl-spinner-container"><span class="gl-spinner gl-spinner-orange gl-spinner-sm" aria-label="Loading"></span></div>'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-04 06:29:18 -04:00
|
|
|
end
|