3 describe "On a merge request", js: true do
4 let!(:project) { create(:project) }
5 let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
6 let!(:note) { create(:note_on_merge_request_with_attachment, project: project) }
10 project.team << [@user, :master]
12 visit project_merge_request_path(project, merge_request)
17 describe "the note form" do
18 it 'should be valid' do
19 should have_css(".js-main-target-form", visible: true, count: 1)
20 find(".js-main-target-form input[type=submit]").value.should == "Add Comment"
21 within(".js-main-target-form") { should_not have_link("Cancel") }
22 within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) }
25 describe "with text" do
27 within(".js-main-target-form") do
28 fill_in "note[note]", with: "This is awesome"
32 it 'should have enable submit button and preview button' do
33 within(".js-main-target-form") { should_not have_css(".js-comment-button[disabled]") }
34 within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: true) }
38 describe "with preview" do
40 within(".js-main-target-form") do
41 fill_in "note[note]", with: "This is awesome"
42 find(".js-note-preview-button").trigger("click")
46 it 'should have text and visible edit button' do
47 within(".js-main-target-form") { should have_css(".js-note-preview", text: "This is awesome", visible: true) }
48 within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) }
49 within(".js-main-target-form") { should have_css(".js-note-edit-button", visible: true) }
54 describe "when posting a note" do
56 within(".js-main-target-form") do
57 fill_in "note[note]", with: "This is awsome!"
58 find(".js-note-preview-button").trigger("click")
59 click_button "Add Comment"
63 it 'should be added and form reset' do
64 should have_content("This is awsome!")
65 within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") }
66 within(".js-main-target-form") { should have_css(".js-note-preview", visible: false) }
67 within(".js-main-target-form") { should have_css(".js-note-text", visible: true) }
71 describe "when editing a note", js: true do
72 it "should contain the hidden edit form" do
73 within("#note_#{note.id}") { should have_css(".note-edit-form", visible: false) }
76 describe "editing the note" do
79 find(".js-note-edit").click
82 it "should show the note edit form and hide the note body" do
83 within("#note_#{note.id}") do
84 find(".note-edit-form", visible: true).should be_visible
85 find(".note-text", visible: false).should_not be_visible
89 it "should reset the edit note form textarea with the original content of the note if cancelled" do
91 find(".js-note-edit").click
93 within(".note-edit-form") do
94 fill_in "note[note]", with: "Some new content"
95 find(".btn-cancel").click
96 find(".js-note-text", visible: false).text.should == note.note
100 it "appends the edited at time to the note" do
102 find(".js-note-edit").click
104 within(".note-edit-form") do
105 fill_in "note[note]", with: "Some new content"
106 find(".btn-save").click
109 within("#note_#{note.id}") do
110 should have_css(".note-last-update small")
111 find(".note-last-update small").text.should match(/Edited less than a minute ago/)
116 describe "deleting an attachment" do
119 find(".js-note-edit").click
122 it "shows the delete link" do
123 within(".note-attachment") do
124 should have_css(".js-note-attachment-delete")
128 it "removes the attachment div and resets the edit form" do
129 find(".js-note-attachment-delete").click
130 should_not have_css(".note-attachment")
131 find(".note-edit-form", visible: false).should_not be_visible
137 describe "On a merge request diff", js: true, focus: true do
138 let!(:project) { create(:source_project) }
139 let!(:merge_request) { create(:merge_request_with_diffs, source_project: project, target_project: project) }
143 project.team << [@user, :master]
144 visit diffs_project_merge_request_path(project, merge_request)
150 describe "when adding a note" do
152 find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
155 describe "the notes holder" do
156 it { should have_css(".js-temp-notes-holder") }
158 it { within(".js-temp-notes-holder") { should have_css(".new_note") } }
161 describe "the note form" do
163 #it 'should be valid' do
164 #within(".js-temp-notes-holder") { find("#note_noteable_type").value.should == "MergeRequest" }
165 #within(".js-temp-notes-holder") { find("#note_noteable_id").value.should == merge_request.id.to_s }
166 #within(".js-temp-notes-holder") { find("#note_commit_id").value.should == "" }
167 #within(".js-temp-notes-holder") { find("#note_line_code").value.should == "4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185" }
168 #should have_css(".js-close-discussion-note-form", text: "Cancel")
171 it "shouldn't add a second form for same row" do
172 find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
174 should have_css("tr[id='4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185'] + .js-temp-notes-holder form", count: 1)
177 it "should be removed when canceled" do
178 within(".file form[rel$='4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185']") do
179 find(".js-close-discussion-note-form").trigger("click")
182 should have_no_css(".js-temp-notes-holder")
187 describe "with muliple note forms" do
188 let!(:project) { create(:source_project) }
189 let!(:merge_request) { create(:merge_request_with_diffs, source_project: project, target_project: project) }
192 find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
193 find('a[data-line-code="342e16cbbd482ac2047dc679b2749d248cc1428f_18_17"]').click
196 it { should have_css(".js-temp-notes-holder", count: 2) }
198 describe "previewing them separately" do
200 # add two separate texts and trigger previews on both
201 within("tr[id='4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185'] + .js-temp-notes-holder") do
202 fill_in "note[note]", with: "One comment on line 185"
203 find(".js-note-preview-button").trigger("click")
205 within("tr[id='342e16cbbd482ac2047dc679b2749d248cc1428f_18_17'] + .js-temp-notes-holder") do
206 fill_in "note[note]", with: "Another comment on line 17"
207 find(".js-note-preview-button").trigger("click")
212 describe "posting a note" do
214 within("tr[id='342e16cbbd482ac2047dc679b2749d248cc1428f_18_17'] + .js-temp-notes-holder") do
215 fill_in "note[note]", with: "Another comment on line 17"
216 click_button("Add Comment")
220 it 'should be added as discussion' do
221 should have_content("Another comment on line 17")
222 should have_css(".notes_holder")
223 should have_css(".notes_holder .note", count: 1)
224 should have_link("Reply")
230 describe "On merge request discussion", js: true do
231 describe "with merge request diff note"
232 describe "with commit note"
233 describe "with commit diff note"