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:
authorRobert Speicher <rspeicher@gmail.com>2015-04-18 22:16:05 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-04-18 22:17:26 +0300
commit8e6fa2555ec37f010ac93b43816d8bcdb3ee835c (patch)
treeb7c76b01ac24ecc7fa84746cb873fabceef271d1 /spec/javascripts
parentca5d0c82509cedb94f9bfa4a40e77706a58faafe (diff)
Add JS specs for replyWithSelectedText
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/shortcuts_issueable_spec.js.coffee83
1 files changed, 83 insertions, 0 deletions
diff --git a/spec/javascripts/shortcuts_issueable_spec.js.coffee b/spec/javascripts/shortcuts_issueable_spec.js.coffee
new file mode 100644
index 00000000000..5f206ddfda6
--- /dev/null
+++ b/spec/javascripts/shortcuts_issueable_spec.js.coffee
@@ -0,0 +1,83 @@
+#= require jquery
+#= require jasmine-fixture
+
+#= require shortcuts_issueable
+
+describe 'ShortcutsIssueable', ->
+ beforeEach ->
+ @shortcut = new ShortcutsIssueable()
+
+ describe '#replyWithSelectedText', ->
+ # Stub window.getSelection to return the provided String.
+ stubSelection = (text) ->
+ window.getSelection = -> text
+
+ beforeEach ->
+ @selector = 'form.js-main-target-form textarea#note_note'
+ affix(@selector)
+
+ describe 'with empty selection', ->
+ it 'does nothing', ->
+ stubSelection('')
+ @shortcut.replyWithSelectedText()
+ expect($(@selector).val()).toBe('')
+
+ describe 'with any selection', ->
+ beforeEach ->
+ stubSelection('Selected text.')
+
+ it 'leaves existing input intact', ->
+ $(@selector).val('This text was already here.')
+ expect($(@selector).val()).toBe('This text was already here.')
+
+ @shortcut.replyWithSelectedText()
+ expect($(@selector).val()).
+ toBe("This text was already here.\n> Selected text.\n\n")
+
+ it 'triggers `input`', ->
+ triggered = false
+ $(@selector).on 'input', -> triggered = true
+ @shortcut.replyWithSelectedText()
+
+ expect(triggered).toBe(true)
+
+ it 'triggers `focus`', ->
+ focused = false
+ $(@selector).on 'focus', -> focused = true
+ @shortcut.replyWithSelectedText()
+
+ expect(focused).toBe(true)
+
+ describe 'with a one-line selection', ->
+ it 'quotes the selection', ->
+ stubSelection('This text has been selected.')
+
+ @shortcut.replyWithSelectedText()
+
+ expect($(@selector).val()).
+ toBe("> This text has been selected.\n\n")
+
+ describe 'with a multi-line selection', ->
+ it 'quotes the selected lines as a group', ->
+ stubSelection(
+ """
+ Selected line one.
+
+ Selected line two.
+ Selected line three.
+
+ """
+ )
+
+ @shortcut.replyWithSelectedText()
+
+ expect($(@selector).val()).
+ toBe(
+ """
+ > Selected line one.
+ > Selected line two.
+ > Selected line three.
+
+
+ """
+ )