Commit 8ee5fce9d64b70d8981896457484fae622d142c9
1 parent
74e48f07
Exists in
master
and in
4 other branches
Add preliminary specs for notes on merge requests
Showing
1 changed file
with
235 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,235 @@ |
| 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, project: project) } | |
| 6 | + | |
| 7 | + before do | |
| 8 | + login_as :user | |
| 9 | + project.add_access(@user, :read, :write) | |
| 10 | + | |
| 11 | + visit project_merge_request_path(project, merge_request) | |
| 12 | + end | |
| 13 | + | |
| 14 | + subject { page } | |
| 15 | + | |
| 16 | + describe "the note form" do | |
| 17 | + # main target form creation | |
| 18 | + it { should have_css(".js-main-target-form", visible: true, count: 1) } | |
| 19 | + | |
| 20 | + # button initalization | |
| 21 | + it { within(".js-main-target-form") { should have_button("Add Comment") } } | |
| 22 | + it { within(".js-main-target-form") { should_not have_link("Cancel") } } | |
| 23 | + | |
| 24 | + # notifiactions | |
| 25 | + it { within(".js-main-target-form") { should have_checked_field("Project team") } } | |
| 26 | + it { within(".js-main-target-form") { should_not have_checked_field("Commit author") } } | |
| 27 | + it { within(".js-main-target-form") { should_not have_unchecked_field("Commit author") } } | |
| 28 | + | |
| 29 | + describe "without text" do | |
| 30 | + it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } } | |
| 31 | + end | |
| 32 | + | |
| 33 | + describe "with text" do | |
| 34 | + before do | |
| 35 | + within(".js-main-target-form") do | |
| 36 | + fill_in "note[note]", with: "This is awesome" | |
| 37 | + end | |
| 38 | + end | |
| 39 | + | |
| 40 | + it { within(".js-main-target-form") { should_not have_css(".js-comment-button[disabled]") } } | |
| 41 | + | |
| 42 | + it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: true) } } | |
| 43 | + end | |
| 44 | + | |
| 45 | + describe "with preview" do | |
| 46 | + before do | |
| 47 | + within(".js-main-target-form") do | |
| 48 | + fill_in "note[note]", with: "This is awesome" | |
| 49 | + find(".js-note-preview-button").trigger("click") | |
| 50 | + end | |
| 51 | + end | |
| 52 | + | |
| 53 | + it { within(".js-main-target-form") { should have_css(".js-note-preview", text: "This is awesome", visible: true) } } | |
| 54 | + | |
| 55 | + it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } } | |
| 56 | + it { within(".js-main-target-form") { should have_css(".js-note-edit-button", visible: true) } } | |
| 57 | + end | |
| 58 | + end | |
| 59 | + | |
| 60 | + describe "when posting a note" do | |
| 61 | + before do | |
| 62 | + within(".js-main-target-form") do | |
| 63 | + fill_in "note[note]", with: "This is awsome!" | |
| 64 | + find(".js-note-preview-button").trigger("click") | |
| 65 | + click_button "Add Comment" | |
| 66 | + end | |
| 67 | + end | |
| 68 | + | |
| 69 | + # note added | |
| 70 | + it { within(".js-main-target-form") { should have_content("This is awsome!") } } | |
| 71 | + | |
| 72 | + # reset form | |
| 73 | + it { within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") } } | |
| 74 | + | |
| 75 | + # return from preview | |
| 76 | + it { within(".js-main-target-form") { should have_css(".js-note-preview", visible: false) } } | |
| 77 | + it { within(".js-main-target-form") { should have_css(".js-note-text", visible: true) } } | |
| 78 | + | |
| 79 | + | |
| 80 | + it "should be removable" do | |
| 81 | + find(".js-note-delete").trigger("click") | |
| 82 | + | |
| 83 | + should_not have_css(".note") | |
| 84 | + end | |
| 85 | + end | |
| 86 | +end | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | +describe "On a merge request diff", js: true, focus: true do | |
| 91 | + let!(:project) { create(:project) } | |
| 92 | + let!(:merge_request) { create(:merge_request_with_diffs, project: project) } | |
| 93 | + | |
| 94 | + before(:all) do | |
| 95 | + login_as :user | |
| 96 | + project.add_access(@user, :read, :write) | |
| 97 | + | |
| 98 | + visit project_merge_request_diff_path(project, merge_request) | |
| 99 | + | |
| 100 | + save_and_open_page | |
| 101 | + | |
| 102 | + click_link("Diff") | |
| 103 | + end | |
| 104 | + | |
| 105 | + subject { page } | |
| 106 | + | |
| 107 | + describe "when adding a note" do | |
| 108 | + before do | |
| 109 | + find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click") | |
| 110 | + end | |
| 111 | + | |
| 112 | + describe "the notes holder" do | |
| 113 | + it { should have_css("#0_185_185.line_holder + .js-temp-notes-holder") } | |
| 114 | + | |
| 115 | + it { within(".js-temp-notes-holder") { should have_css(".new_note") } } | |
| 116 | + end | |
| 117 | + | |
| 118 | + describe "the note form" do | |
| 119 | + # set up hidden fields correctly | |
| 120 | + it { within(".js-temp-notes-holder") { find("#note_noteable_type").value.should == "Commit" } } | |
| 121 | + it { within(".js-temp-notes-holder") { find("#note_noteable_id").value.should == "" } } | |
| 122 | + it { within(".js-temp-notes-holder") { find("#note_commit_id").value.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" } } | |
| 123 | + it { within(".js-temp-notes-holder") { find("#note_line_code").value.should == "0_185_185" } } | |
| 124 | + | |
| 125 | + # buttons | |
| 126 | + it { should have_button("Add Comment") } | |
| 127 | + it { should have_css(".js-close-discussion-note-form", text: "Cancel") } | |
| 128 | + | |
| 129 | + # notification options | |
| 130 | + it { should have_unchecked_field("Project team") } | |
| 131 | + it { should have_checked_field("Commit author") } | |
| 132 | + | |
| 133 | + it "shouldn't add a second form for same row" do | |
| 134 | + find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click") | |
| 135 | + | |
| 136 | + should have_css("#0_185_185.line_holder + .js-temp-notes-holder form", count: 1) | |
| 137 | + end | |
| 138 | + | |
| 139 | + it "should be removed when canceled" do | |
| 140 | + find(".js-close-discussion-note-form").trigger("click") | |
| 141 | + | |
| 142 | + should have_no_css(".js-temp-notes-holder") | |
| 143 | + end | |
| 144 | + end | |
| 145 | + end | |
| 146 | + | |
| 147 | + describe "with muliple note forms" do | |
| 148 | + before do | |
| 149 | + find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click") | |
| 150 | + find("#1_18_17.line_holder .js-add-diff-note-button").trigger("click") | |
| 151 | + end | |
| 152 | + | |
| 153 | + # has two line forms | |
| 154 | + it { should have_css(".js-temp-notes-holder", count: 2) } | |
| 155 | + | |
| 156 | + describe "previewing them separately" do | |
| 157 | + before do | |
| 158 | + # add two separate texts and trigger previews on both | |
| 159 | + within("#0_185_185.line_holder + .js-temp-notes-holder") do | |
| 160 | + fill_in "note[note]", with: "One comment on line 185" | |
| 161 | + find(".js-note-preview-button").trigger("click") | |
| 162 | + end | |
| 163 | + within("#1_18_17.line_holder + .js-temp-notes-holder") do | |
| 164 | + fill_in "note[note]", with: "Another comment on line 17" | |
| 165 | + find(".js-note-preview-button").trigger("click") | |
| 166 | + end | |
| 167 | + end | |
| 168 | + | |
| 169 | + # check if previews were rendered separately | |
| 170 | + it { within("#0_185_185.line_holder + .js-temp-notes-holder") { should have_css(".js-note-preview", text: "One comment on line 185") } } | |
| 171 | + it { within("#1_18_17.line_holder + .js-temp-notes-holder") { should have_css(".js-note-preview", text: "Another comment on line 17") } } | |
| 172 | + end | |
| 173 | + | |
| 174 | + describe "posting a note" do | |
| 175 | + before do | |
| 176 | + within("#1_18_17.line_holder + .js-temp-notes-holder") do | |
| 177 | + fill_in "note[note]", with: "Another comment on line 17" | |
| 178 | + click_button("Add Comment") | |
| 179 | + end | |
| 180 | + end | |
| 181 | + | |
| 182 | + # removed form after submit | |
| 183 | + it { should have_no_css("#1_18_17.line_holder + .js-temp-notes-holder") } | |
| 184 | + | |
| 185 | + # added discussion | |
| 186 | + it { should have_content("Another comment on line 17") } | |
| 187 | + it { should have_css("#1_18_17.line_holder + .notes_holder") } | |
| 188 | + it { should have_css("#1_18_17.line_holder + .notes_holder .note", count: 1) } | |
| 189 | + it { should have_link("Reply") } | |
| 190 | + | |
| 191 | + it "should remove last note of a discussion" do | |
| 192 | + within("#1_18_17.line_holder + .notes_holder") do | |
| 193 | + find(".js-note-delete").trigger("click") | |
| 194 | + end | |
| 195 | + | |
| 196 | + # removed whole discussion | |
| 197 | + should_not have_css(".note_holder") | |
| 198 | + should have_css("#1_18_17.line_holder + #1_18_18.line_holder") | |
| 199 | + end | |
| 200 | + end | |
| 201 | + end | |
| 202 | + | |
| 203 | + describe "when replying to a note" do | |
| 204 | + before do | |
| 205 | + # create first note | |
| 206 | + find("#0_184_184.line_holder .js-add-diff-note-button").trigger("click") | |
| 207 | + within("#0_184_184.line_holder + .js-temp-notes-holder") do | |
| 208 | + fill_in "note[note]", with: "One comment on line 184" | |
| 209 | + click_button("Add Comment") | |
| 210 | + end | |
| 211 | + # create second note | |
| 212 | + within("#0_184_184.line_holder + .notes_holder") do | |
| 213 | + find(".js-discussion-reply-button").trigger("click") | |
| 214 | + fill_in "note[note]", with: "An additional comment in reply" | |
| 215 | + click_button("Add Comment") | |
| 216 | + end | |
| 217 | + end | |
| 218 | + | |
| 219 | + # inserted note | |
| 220 | + it { should have_content("An additional comment in reply") } | |
| 221 | + it { within("#0_184_184.line_holder + .notes_holder") { should have_css(".note", count: 2) } } | |
| 222 | + | |
| 223 | + # removed form after reply | |
| 224 | + it { within("#0_184_184.line_holder + .notes_holder") { should have_no_css("form") } } | |
| 225 | + it { within("#0_184_184.line_holder + .notes_holder") { should have_link("Reply") } } | |
| 226 | + end | |
| 227 | +end | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | +describe "On merge request discussion", js: true do | |
| 232 | + describe "with merge request diff note" | |
| 233 | + describe "with commit note" | |
| 234 | + describe "with commit diff note" | |
| 235 | +end | |
| 0 | 236 | \ No newline at end of file | ... | ... |