2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-12 12:13:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe ButtonHelper do
|
2017-06-12 12:13:22 -04:00
|
|
|
describe 'http_clone_button' do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build_stubbed(:project) }
|
2017-06-12 12:13:22 -04:00
|
|
|
let(:has_tooltip_class) { 'has-tooltip' }
|
|
|
|
|
|
|
|
def element
|
|
|
|
element = helper.http_clone_button(project)
|
|
|
|
|
|
|
|
Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with internal auth enabled' do
|
|
|
|
context 'when user has a password' do
|
|
|
|
it 'shows no tooltip' do
|
|
|
|
expect(element.attr('class')).not_to include(has_tooltip_class)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has password automatically set' do
|
|
|
|
let(:user) { create(:user, password_automatically_set: true) }
|
|
|
|
|
2017-11-13 13:21:26 -05:00
|
|
|
it 'shows the password text on the dropdown' do
|
2017-11-15 14:47:22 -05:00
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
|
|
|
|
|
|
|
expect(description.inner_text).to eq 'Set a password on your account to pull or push via HTTP.'
|
2017-06-12 12:13:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with internal auth disabled' do
|
|
|
|
before do
|
2017-11-23 08:16:14 -05:00
|
|
|
stub_application_setting(password_authentication_enabled_for_git?: false)
|
2017-06-12 12:13:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has no personal access tokens' do
|
2018-08-27 11:05:38 -04:00
|
|
|
it 'has a personal access token text on the dropdown description' do
|
2017-11-15 14:47:22 -05:00
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
2017-06-12 12:13:22 -04:00
|
|
|
|
2017-11-15 14:47:22 -05:00
|
|
|
expect(description.inner_text).to eq 'Create a personal access token on your account to pull or push via HTTP.'
|
2017-06-12 12:13:22 -04:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:05:38 -04:00
|
|
|
|
|
|
|
context 'when user has personal access tokens' do
|
|
|
|
before do
|
|
|
|
create(:personal_access_token, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not have a personal access token text on the dropdown description' do
|
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
|
|
|
|
|
|
|
expect(description).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-06-12 12:13:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is ldap user' do
|
|
|
|
let(:user) { create(:omniauth_user, password_automatically_set: true) }
|
|
|
|
|
|
|
|
it 'shows no tooltip' do
|
|
|
|
expect(element.attr('class')).not_to include(has_tooltip_class)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-25 08:19:26 -04:00
|
|
|
|
2017-11-15 14:47:22 -05:00
|
|
|
describe 'ssh_button' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { build_stubbed(:project) }
|
|
|
|
|
|
|
|
def element
|
|
|
|
element = helper.ssh_clone_button(project)
|
|
|
|
|
|
|
|
Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without an ssh key on the user' do
|
|
|
|
it 'shows a warning on the dropdown description' do
|
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
|
|
|
|
2020-11-24 04:09:32 -05:00
|
|
|
expect(description.inner_text).to eq "You won't be able to pull or push repositories via SSH until you add an SSH key to your profile"
|
2017-11-15 14:47:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-03 16:52:01 -04:00
|
|
|
context 'without an ssh key on the user and user_show_add_ssh_key_message unset' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(user_show_add_ssh_key_message: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'there is no warning on the dropdown description' do
|
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
|
|
|
|
|
|
|
expect(description).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-15 14:47:22 -05:00
|
|
|
context 'with an ssh key on the user' do
|
|
|
|
before do
|
|
|
|
create(:key, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'there is no warning on the dropdown description' do
|
|
|
|
description = element.search('.dropdown-menu-inner-content').first
|
|
|
|
|
|
|
|
expect(description).to eq nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-05 17:40:04 -05:00
|
|
|
describe 'ssh and http clone buttons' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { build_stubbed(:project) }
|
|
|
|
|
|
|
|
def http_button_element
|
|
|
|
element = helper.http_clone_button(project, append_link: false)
|
|
|
|
|
|
|
|
Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
|
|
|
|
end
|
|
|
|
|
|
|
|
def ssh_button_element
|
|
|
|
element = helper.ssh_clone_button(project, append_link: false)
|
|
|
|
|
|
|
|
Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only shows the title of any of the clone buttons when append_link is false' do
|
|
|
|
expect(http_button_element.text).to eq('HTTP')
|
|
|
|
expect(http_button_element.search('.dropdown-menu-inner-content').first).to eq(nil)
|
|
|
|
expect(ssh_button_element.text).to eq('SSH')
|
|
|
|
expect(ssh_button_element.search('.dropdown-menu-inner-content').first).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 08:19:26 -04:00
|
|
|
describe 'clipboard_button' do
|
2018-07-23 10:58:21 -04:00
|
|
|
include IconsHelper
|
|
|
|
|
2017-08-25 08:19:26 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { build_stubbed(:project) }
|
|
|
|
|
|
|
|
def element(data = {})
|
|
|
|
element = helper.clipboard_button(data)
|
|
|
|
Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with default options' do
|
|
|
|
context 'when no `text` attribute is not provided' do
|
|
|
|
it 'shows copy to clipboard button with default configuration and no text set to copy' do
|
|
|
|
expect(element.attr('class')).to eq('btn btn-clipboard btn-transparent')
|
|
|
|
expect(element.attr('type')).to eq('button')
|
2019-10-09 08:06:13 -04:00
|
|
|
expect(element.attr('aria-label')).to eq('Copy')
|
2017-08-25 08:19:26 -04:00
|
|
|
expect(element.attr('data-toggle')).to eq('tooltip')
|
|
|
|
expect(element.attr('data-placement')).to eq('bottom')
|
|
|
|
expect(element.attr('data-container')).to eq('body')
|
|
|
|
expect(element.attr('data-clipboard-text')).to eq(nil)
|
2021-03-23 17:08:58 -04:00
|
|
|
expect(element.attr('itemprop')).to eq(nil)
|
2017-08-25 08:19:26 -04:00
|
|
|
expect(element.inner_text).to eq("")
|
|
|
|
|
2021-08-13 08:10:58 -04:00
|
|
|
expect(element.to_html).to include sprite_icon('copy-to-clipboard', css_class: 'gl-icon')
|
2017-08-25 08:19:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `text` attribute is provided' do
|
|
|
|
it 'shows copy to clipboard button with provided `text` to copy' do
|
|
|
|
expect(element(text: 'Hello World!').attr('data-clipboard-text')).to eq('Hello World!')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `title` attribute is provided' do
|
|
|
|
it 'shows copy to clipboard button with provided `title` as tooltip' do
|
|
|
|
expect(element(title: 'Copy to my clipboard!').attr('aria-label')).to eq('Copy to my clipboard!')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with `button_text` attribute provided' do
|
|
|
|
it 'shows copy to clipboard button with provided `button_text` as button label' do
|
|
|
|
expect(element(button_text: 'Copy text').inner_text).to eq('Copy text')
|
|
|
|
end
|
2021-08-13 08:10:58 -04:00
|
|
|
|
|
|
|
it 'adds `gl-button-icon` class to icon' do
|
|
|
|
expect(element(button_text: 'Copy text')).to have_css('svg.gl-button-icon')
|
|
|
|
end
|
2017-08-25 08:19:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with `hide_tooltip` attribute provided' do
|
|
|
|
it 'shows copy to clipboard button without tooltip support' do
|
|
|
|
expect(element(hide_tooltip: true).attr('data-placement')).to eq(nil)
|
|
|
|
expect(element(hide_tooltip: true).attr('data-toggle')).to eq(nil)
|
|
|
|
expect(element(hide_tooltip: true).attr('data-container')).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with `hide_button_icon` attribute provided' do
|
|
|
|
it 'shows copy to clipboard button without tooltip support' do
|
2018-07-23 10:58:21 -04:00
|
|
|
expect(element(hide_button_icon: true).to_html).not_to include sprite_icon('duplicate')
|
2017-08-25 08:19:26 -04:00
|
|
|
end
|
|
|
|
end
|
2021-03-23 17:08:58 -04:00
|
|
|
|
|
|
|
context 'with `itemprop` attribute provided' do
|
|
|
|
it 'shows copy to clipboard button with `itemprop` attribute' do
|
|
|
|
expect(element(itemprop: "identifier").attr('itemprop')).to eq("identifier")
|
|
|
|
end
|
|
|
|
end
|
2017-08-25 08:19:26 -04:00
|
|
|
end
|
2017-06-12 12:13:22 -04:00
|
|
|
end
|