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

shortcuts_issuable_spec.js.coffee « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a01ad7140dd961128544a168c03182309a0d289f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#= require shortcuts_issuable

describe 'ShortcutsIssuable', ->
  fixture.preload('issuable.html')

  beforeEach ->
    fixture.load('issuable.html')
    @shortcut = new ShortcutsIssuable()

  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'

    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.


            """
          )