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