diff_note.rb 6.85 KB
Newer Older
1 2
module SharedDiffNote
  include Spinach::DSL
3
  include RepoHelpers
4

5
  step 'I cancel the diff comment' do
6
    page.within(diff_file_selector) do
7
      find(".js-close-discussion-note-form").click
8 9 10
    end
  end

11
  step 'I delete a diff comment' do
12 13
    find('.note').hover
    find(".js-note-delete").click
14 15
  end

16
  step 'I haven\'t written any diff comment text' do
17
    page.within(diff_file_selector) do
18 19 20 21
      fill_in "note[note]", with: ""
    end
  end

22
  step 'I leave a diff comment like "Typo, please fix"' do
Robert Speicher's avatar
Robert Speicher committed
23 24 25
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.line_code)

Rémy Coutable's avatar
Rémy Coutable committed
26
      page.within("form[id$='#{sample_commit.line_code}']") do
Robert Speicher's avatar
Robert Speicher committed
27 28 29 30
        fill_in "note[note]", with: "Typo, please fix"
        find(".js-comment-button").trigger("click")
        sleep 0.05
      end
31 32 33
    end
  end

34 35
  step 'I leave a diff comment in a parallel view on the left side like "Old comment"' do
    click_parallel_diff_line(sample_commit.line_code, 'old')
Rémy Coutable's avatar
Rémy Coutable committed
36
    page.within("#{diff_file_selector} form[id$='#{sample_commit.line_code}']") do
37 38 39 40 41 42 43
      fill_in "note[note]", with: "Old comment"
      find(".js-comment-button").trigger("click")
    end
  end

  step 'I leave a diff comment in a parallel view on the right side like "New comment"' do
    click_parallel_diff_line(sample_commit.line_code, 'new')
Rémy Coutable's avatar
Rémy Coutable committed
44
    page.within("#{diff_file_selector} form[id$='#{sample_commit.line_code}']") do
45 46 47 48 49
      fill_in "note[note]", with: "New comment"
      find(".js-comment-button").trigger("click")
    end
  end

50
  step 'I preview a diff comment text like "Should fix it :smile:"' do
Robert Speicher's avatar
Robert Speicher committed
51 52 53
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.line_code)

Rémy Coutable's avatar
Rémy Coutable committed
54
      page.within("form[id$='#{sample_commit.line_code}']") do
Robert Speicher's avatar
Robert Speicher committed
55 56 57
        fill_in "note[note]", with: "Should fix it :smile:"
        find('.js-md-preview-button').click
      end
58 59 60
    end
  end

61
  step 'I preview another diff comment text like "DRY this up"' do
Robert Speicher's avatar
Robert Speicher committed
62 63
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.del_line_code)
64

Rémy Coutable's avatar
Rémy Coutable committed
65
      page.within("form[id$='#{sample_commit.del_line_code}']") do
Robert Speicher's avatar
Robert Speicher committed
66 67 68
        fill_in "note[note]", with: "DRY this up"
        find('.js-md-preview-button').click
      end
69 70 71
    end
  end

72
  step 'I open a diff comment form' do
Robert Speicher's avatar
Robert Speicher committed
73 74 75
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.line_code)
    end
76 77
  end

78
  step 'I open another diff comment form' do
Robert Speicher's avatar
Robert Speicher committed
79 80 81
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.del_line_code)
    end
82 83
  end

84
  step 'I write a diff comment like ":-1: I don\'t like this"' do
85
    page.within(diff_file_selector) do
86 87 88 89
      fill_in "note[note]", with: ":-1: I don\'t like this"
    end
  end

90 91 92 93
  step 'I write a diff comment like ":smile:"' do
    page.within(diff_file_selector) do
      click_diff_line(sample_commit.line_code)

Rémy Coutable's avatar
Rémy Coutable committed
94
      page.within("form[id$='#{sample_commit.line_code}']") do
95
        fill_in 'note[note]', with: ':smile:'
Phil Hughes's avatar
Phil Hughes committed
96
        click_button('Comment')
97 98 99 100
      end
    end
  end

101
  step 'I submit the diff comment' do
102
    page.within(diff_file_selector) do
Phil Hughes's avatar
Phil Hughes committed
103
      click_button("Comment")
104 105 106
    end
  end

107
  step 'I should not see the diff comment form' do
108
    page.within(diff_file_selector) do
109
      expect(page).not_to have_css("form.new_note")
110 111 112
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
113
  step 'The diff comment preview tab should say there is nothing to do' do
114
    page.within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
115 116
      find('.js-md-preview-button').click
      expect(find('.js-md-preview')).to have_content('Nothing to preview.')
117 118 119
    end
  end

120
  step 'I should not see the diff comment text field' do
121
    page.within(diff_file_selector) do
122
      expect(find('.js-note-text')).not_to be_visible
123 124 125
    end
  end

126
  step 'I should only see one diff form' do
127
    page.within(diff_file_selector) do
Phil Hughes's avatar
Phil Hughes committed
128
      expect(page).to have_css("form.new-note", count: 1)
129 130 131
    end
  end

132
  step 'I should see a diff comment form with ":-1: I don\'t like this"' do
133
    page.within(diff_file_selector) do
134
      expect(page).to have_field("note[note]", with: ":-1: I don\'t like this")
135 136 137
    end
  end

138
  step 'I should see a diff comment saying "Typo, please fix"' do
139
    page.within("#{diff_file_selector} .note") do
140
      expect(page).to have_content("Typo, please fix")
141 142 143
    end
  end

144 145 146 147 148 149 150 151 152 153 154 155
  step 'I should see a diff comment on the left side saying "Old comment"' do
    page.within("#{diff_file_selector} .notes_content.parallel.old") do
      expect(page).to have_content("Old comment")
    end
  end

  step 'I should see a diff comment on the right side saying "New comment"' do
    page.within("#{diff_file_selector} .notes_content.parallel.new") do
      expect(page).to have_content("New comment")
    end
  end

Annabel Dunstone's avatar
Annabel Dunstone committed
156
  step 'I should see a discussion reply button' do
157
    page.within(diff_file_selector) do
Annabel Dunstone's avatar
Annabel Dunstone committed
158
      expect(page).to have_button('Reply...')
159 160 161
    end
  end

162
  step 'I should see a temporary diff comment form' do
163
    page.within(diff_file_selector) do
Phil Hughes's avatar
Phil Hughes committed
164
      expect(page).to have_css(".js-temp-notes-holder form.new-note")
165 166 167
    end
  end

168
  step 'I should see add a diff comment button' do
169
    expect(page).to have_css('.js-add-diff-note-button')
170 171
  end

172
  step 'I should see an empty diff comment form' do
173
    page.within(diff_file_selector) do
174
      expect(page).to have_field("note[note]", with: "")
175 176 177
    end
  end

178
  step 'I should see the cancel comment button' do
179
    page.within("#{diff_file_selector} form") do
180
      expect(page).to have_css(".js-close-discussion-note-form", text: "Cancel")
181 182 183
    end
  end

184
  step 'I should see the diff comment preview' do
185
    page.within("#{diff_file_selector} form") do
Vinnie Okada's avatar
Vinnie Okada committed
186
      expect(page).to have_css('.js-md-preview', visible: true)
187 188 189
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
190
  step 'I should see the diff comment write tab' do
191
    page.within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
192
      expect(page).to have_css('.js-md-write-button', visible: true)
193 194 195
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
196
  step 'The diff comment preview tab should display rendered Markdown' do
197
    page.within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
198
      find('.js-md-preview-button').click
Vinnie Okada's avatar
Vinnie Okada committed
199
      expect(find('.js-md-preview')).to have_css('img.emoji', visible: true)
200 201 202
    end
  end

203
  step 'I should see two separate previews' do
204
    page.within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
205
      expect(page).to have_css('.js-md-preview', visible: true, count: 2)
Vinnie Okada's avatar
Vinnie Okada committed
206 207
      expect(page).to have_content('Should fix it')
      expect(page).to have_content('DRY this up')
208 209
    end
  end
210

211 212 213 214 215 216
  step 'I should see a diff comment with an emoji image' do
    page.within("#{diff_file_selector} .note") do
      expect(page).to have_xpath("//img[@alt=':smile:']")
    end
  end

217
  step 'I click side-by-side diff button' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
218
    find('#parallel-diff-btn').trigger('click')
219 220 221 222 223 224
  end

  step 'I see side-by-side diff button' do
    expect(page).to have_content "Side-by-side"
  end

225
  def diff_file_selector
Robert Speicher's avatar
Robert Speicher committed
226
    '.diff-file:nth-of-type(1)'
227 228 229
  end

  def click_diff_line(code)
230
    find("button[data-line-code='#{code}']").click
231
  end
232 233 234 235

  def click_parallel_diff_line(code, line_type)
    find("button[data-line-code='#{code}'][data-line-type='#{line_type}']").trigger('click')
  end
236
end