summaryrefslogtreecommitdiff
path: root/spec/helpers/button_helper_spec.rb
diff options
context:
space:
mode:
authorkushalpandya <kushal@gitlab.com>2017-08-24 17:40:27 +0530
committerkushalpandya <kushal@gitlab.com>2017-08-24 17:40:27 +0530
commit80ebe9c5cf323b688fdfa74c3aa384e524af2a88 (patch)
tree897a4cc673fb5b5b5ca4694dca31e02f13f94e6a /spec/helpers/button_helper_spec.rb
parentd8b24db9bdfaa4f1c29010e7797bae35c91bb206 (diff)
downloadgitlab-ce-80ebe9c5cf323b688fdfa74c3aa384e524af2a88.tar.gz
Add tests for `clipboard_helper`
Diffstat (limited to 'spec/helpers/button_helper_spec.rb')
-rw-r--r--spec/helpers/button_helper_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/helpers/button_helper_spec.rb b/spec/helpers/button_helper_spec.rb
index 250ba239033..54724db5e0d 100644
--- a/spec/helpers/button_helper_spec.rb
+++ b/spec/helpers/button_helper_spec.rb
@@ -62,4 +62,67 @@ describe ButtonHelper do
end
end
end
+
+ describe 'clipboard_button' do
+ 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')
+ expect(element.attr('aria-label')).to eq('Copy to clipboard')
+ 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)
+ expect(element.inner_text).to eq("")
+
+ expect(element).to have_selector('.fa.fa-clipboard')
+ 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
+ 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
+ expect(element(hide_button_icon: true)).not_to have_selector('.fa.fa-clipboard')
+ end
+ end
+ end
end