summaryrefslogtreecommitdiff
path: root/spec/features/issuables/shortcuts_issuable_spec.rb
blob: 7e8f39c47a73964e0de091e56dd23d2ee2ab709e (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Blob shortcuts', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project, :public, :repository) }
  let(:issue) { create(:issue, project: project, author: user) }
  let(:merge_request) { create(:merge_request, source_project: project) }
  let(:note_text) { 'I got this!' }

  before do
    project.add_developer(user)
    sign_in(user)
  end

  shared_examples "quotes the selected text" do
    it "quotes the selected text", :quarantine do
      select_element('.note-text')
      find('body').native.send_key('r')

      expect(find('.js-main-target-form .js-vue-comment-form').value).to include(note_text)
    end
  end

  describe 'pressing "r"' do
    describe 'On an Issue' do
      before do
        create(:note, noteable: issue, project: project, note: note_text)
        visit project_issue_path(project, issue)
        wait_for_requests
      end

      include_examples 'quotes the selected text'
    end

    describe 'On a Merge Request' do
      before do
        create(:note, noteable: merge_request, project: project, note: note_text)
        visit project_merge_request_path(project, merge_request)
        wait_for_requests
      end

      include_examples 'quotes the selected text'
    end
  end

  shared_examples "opens assignee dropdown for editing" do
    it "opens assignee dropdown for editing" do
      find('body').native.send_key('a')

      expect(find('.block.assignee')).to have_selector('.js-sidebar-assignee-data')
    end
  end

  describe 'pressing "a"' do
    describe 'On an Issue' do
      before do
        stub_feature_flags(issue_assignees_widget: false)
        visit project_issue_path(project, issue)
        wait_for_requests
      end

      include_examples 'opens assignee dropdown for editing'
    end

    describe 'On a Merge Request' do
      before do
        stub_feature_flags(issue_assignees_widget: false)
        visit project_merge_request_path(project, merge_request)
        wait_for_requests
      end

      include_examples 'opens assignee dropdown for editing'
    end
  end

  shared_examples "opens milestones dropdown for editing" do
    it "opens milestones dropdown for editing" do
      find('body').native.send_key('m')

      expect(find('[data-testid="milestone-edit"]')).to have_selector('.gl-new-dropdown-inner')
    end
  end

  describe 'pressing "m"' do
    describe 'On an Issue' do
      before do
        visit project_issue_path(project, issue)
        wait_for_requests
      end

      include_examples 'opens milestones dropdown for editing'
    end

    describe 'On a Merge Request' do
      before do
        visit project_merge_request_path(project, merge_request)
        wait_for_requests
      end

      include_examples 'opens milestones dropdown for editing'
    end
  end

  shared_examples "opens labels dropdown for editing" do
    it "opens labels dropdown for editing" do
      find('body').native.send_key('l')

      expect(find('.js-labels-block')).to have_selector('[data-testid="labels-select-dropdown-contents"]')
    end
  end

  describe 'pressing "l"' do
    describe 'On an Issue' do
      before do
        visit project_issue_path(project, issue)
        wait_for_requests
      end

      include_examples 'opens labels dropdown for editing'
    end

    describe 'On a Merge Request' do
      before do
        visit project_merge_request_path(project, merge_request)
        wait_for_requests
      end

      include_examples 'opens labels dropdown for editing'
    end
  end
end