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

5
  step 'I cancel the diff comment' do
6
    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
    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
23 24
    click_diff_line(sample_commit.line_code)
    within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do
25 26
      fill_in "note[note]", with: "Typo, please fix"
      find(".js-comment-button").trigger("click")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
27
      sleep 0.05
28 29 30
    end
  end

31
  step 'I preview a diff comment text like "Should fix it :smile:"' do
32 33
    click_diff_line(sample_commit.line_code)
    within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do
34
      fill_in "note[note]", with: "Should fix it :smile:"
35
      find('.js-md-preview-button').click
36 37 38
    end
  end

39
  step 'I preview another diff comment text like "DRY this up"' do
40
    click_diff_line(sample_commit.del_line_code)
41

42
    within("#{diff_file_selector} form[rel$='#{sample_commit.del_line_code}']") do
43
      fill_in "note[note]", with: "DRY this up"
44
      find('.js-md-preview-button').click
45 46 47
    end
  end

48
  step 'I open a diff comment form' do
49
    click_diff_line(sample_commit.line_code)
50 51
  end

52
  step 'I open another diff comment form' do
53
    click_diff_line(sample_commit.del_line_code)
54 55
  end

56
  step 'I write a diff comment like ":-1: I don\'t like this"' do
57
    within(diff_file_selector) do
58 59 60 61
      fill_in "note[note]", with: ":-1: I don\'t like this"
    end
  end

62
  step 'I submit the diff comment' do
63
    within(diff_file_selector) do
64 65 66 67
      click_button("Add Comment")
    end
  end

68
  step 'I should not see the diff comment form' do
69
    within(diff_file_selector) do
70 71 72 73
      page.should_not have_css("form.new_note")
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
74
  step 'The diff comment preview tab should say there is nothing to do' do
75
    within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
76 77
      find('.js-md-preview-button').click
      expect(find('.js-md-preview')).to have_content('Nothing to preview.')
78 79 80
    end
  end

81
  step 'I should not see the diff comment text field' do
82
    within(diff_file_selector) do
83
      expect(find('.js-note-text')).not_to be_visible
84 85 86
    end
  end

87
  step 'I should only see one diff form' do
88
    within(diff_file_selector) do
89 90 91 92
      page.should have_css("form.new_note", count: 1)
    end
  end

93
  step 'I should see a diff comment form with ":-1: I don\'t like this"' do
94
    within(diff_file_selector) do
95 96 97 98
      page.should have_field("note[note]", with: ":-1: I don\'t like this")
    end
  end

99
  step 'I should see a diff comment saying "Typo, please fix"' do
100
    within("#{diff_file_selector} .note") do
101 102 103 104
      page.should have_content("Typo, please fix")
    end
  end

105
  step 'I should see a discussion reply button' do
106
    within(diff_file_selector) do
107
      page.should have_button('Reply')
108 109 110
    end
  end

111
  step 'I should see a temporary diff comment form' do
112
    within(diff_file_selector) do
113 114 115 116
      page.should have_css(".js-temp-notes-holder form.new_note")
    end
  end

117
  step 'I should see add a diff comment button' do
118
    page.should have_css('.js-add-diff-note-button', visible: true)
119 120
  end

121
  step 'I should see an empty diff comment form' do
122
    within(diff_file_selector) do
123 124 125 126
      page.should have_field("note[note]", with: "")
    end
  end

127
  step 'I should see the cancel comment button' do
128
    within("#{diff_file_selector} form") do
129 130 131 132
      page.should have_css(".js-close-discussion-note-form", text: "Cancel")
    end
  end

133
  step 'I should see the diff comment preview' do
134
    within("#{diff_file_selector} form") do
Vinnie Okada's avatar
Vinnie Okada committed
135
      expect(page).to have_css('.js-md-preview', visible: true)
136 137 138
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
139
  step 'I should see the diff comment write tab' do
140
    within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
141
      expect(page).to have_css('.js-md-write-button', visible: true)
142 143 144
    end
  end

Vinnie Okada's avatar
Vinnie Okada committed
145
  step 'The diff comment preview tab should display rendered Markdown' do
146
    within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
147
      find('.js-md-preview-button').click
Vinnie Okada's avatar
Vinnie Okada committed
148
      expect(find('.js-md-preview')).to have_css('img.emoji', visible: true)
149 150 151
    end
  end

152
  step 'I should see two separate previews' do
153
    within(diff_file_selector) do
Vinnie Okada's avatar
Vinnie Okada committed
154
      expect(page).to have_css('.js-md-preview', visible: true, count: 2)
Vinnie Okada's avatar
Vinnie Okada committed
155 156
      expect(page).to have_content('Should fix it')
      expect(page).to have_content('DRY this up')
157 158
    end
  end
159 160

  def diff_file_selector
161 162 163 164
    ".diff-file:nth-of-type(1)"
  end

  def click_diff_line(code)
165
    find("button[data-line-code='#{code}']").click
166
  end
167
end