OSDN Git Service

Make changes to tests
[wvm/gitlab.git] / spec / features / notes_on_merge_requests_spec.rb
1 require 'spec_helper'
2
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) }
7
8   before do
9     login_as :user
10     project.team << [@user, :master]
11
12     visit project_merge_request_path(project, merge_request)
13   end
14
15   subject { page }
16
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) }
23     end
24
25     describe "with text" do
26       before do
27         within(".js-main-target-form") do
28           fill_in "note[note]", with: "This is awesome"
29         end
30       end
31
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) }
35       end
36     end
37
38     describe "with preview" do
39       before 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")
43         end
44       end
45
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) }
50       end
51     end
52   end
53
54   describe "when posting a note" do
55     before 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"
60       end
61     end
62
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) }
68     end
69   end
70
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) }
74     end
75
76     describe "editing the note" do
77       before do
78         find('.note').hover
79         find(".js-note-edit").click
80       end
81
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
86         end
87       end
88
89       it "should reset the edit note form textarea with the original content of the note if cancelled" do
90         find('.note').hover
91         find(".js-note-edit").click
92
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
97         end
98       end
99
100       it "appends the edited at time to the note" do
101         find('.note').hover
102         find(".js-note-edit").click
103
104         within(".note-edit-form") do
105           fill_in "note[note]", with: "Some new content"
106           find(".btn-save").click
107         end
108
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/)
112         end
113       end
114     end
115
116     describe "deleting an attachment" do
117       before do
118         find('.note').hover
119         find(".js-note-edit").click
120       end
121
122       it "shows the delete link" do
123         within(".note-attachment") do
124           should have_css(".js-note-attachment-delete")
125         end
126       end
127
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
132       end
133     end
134   end
135 end
136
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) }
140
141   before do
142     login_as :user
143     project.team << [@user, :master]
144     visit diffs_project_merge_request_path(project, merge_request)
145   end
146
147
148   subject { page }
149
150   describe "when adding a note" do
151     before do
152       find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
153     end
154
155     describe "the notes holder" do
156       it { should have_css(".js-temp-notes-holder") }
157
158       it { within(".js-temp-notes-holder") { should have_css(".new_note") } }
159     end
160
161     describe "the note form" do
162       # FIXME
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")
169       #end
170
171       it "shouldn't add a second form for same row" do
172         find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
173
174         should have_css("tr[id='4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185'] + .js-temp-notes-holder form", count: 1)
175       end
176
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")
180         end
181
182         should have_no_css(".js-temp-notes-holder")
183       end
184     end
185   end
186
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) }
190
191     before do
192       find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
193       find('a[data-line-code="342e16cbbd482ac2047dc679b2749d248cc1428f_18_17"]').click
194     end
195
196     it { should have_css(".js-temp-notes-holder", count: 2) }
197
198     describe "previewing them separately" do
199       before 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")
204         end
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")
208         end
209       end
210     end
211
212     describe "posting a note" do
213       before 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")
217         end
218       end
219
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")
225       end
226     end
227   end
228 end
229
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"
234 end