Commit 86e368a8af35fb0f09369630a226c80dc16ae5ec

Authored by Dmitriy Zaporozhets
1 parent c7a64311

Reduce notes_on_merge_requests_spec time from 3 min to 1min

Showing 1 changed file with 41 additions and 55 deletions   Show diff stats
spec/features/notes_on_merge_requests_spec.rb
... ... @@ -14,15 +14,11 @@ describe "On a merge request", js: true do
14 14 subject { page }
15 15  
16 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 { find(".js-main-target-form input[type=submit]").value.should == "Add Comment" }
22   - it { within(".js-main-target-form") { should_not have_link("Cancel") } }
23   -
24   - describe "without text" do
25   - it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } }
  17 + it 'should be valid' do
  18 + should have_css(".js-main-target-form", visible: true, count: 1)
  19 + find(".js-main-target-form input[type=submit]").value.should == "Add Comment"
  20 + within(".js-main-target-form") { should_not have_link("Cancel") }
  21 + within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) }
26 22 end
27 23  
28 24 describe "with text" do
... ... @@ -32,9 +28,10 @@ describe "On a merge request", js: true do
32 28 end
33 29 end
34 30  
35   - it { within(".js-main-target-form") { should_not have_css(".js-comment-button[disabled]") } }
36   -
37   - it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: true) } }
  31 + it 'should have enable submit button and preview button' do
  32 + within(".js-main-target-form") { should_not have_css(".js-comment-button[disabled]") }
  33 + within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: true) }
  34 + end
38 35 end
39 36  
40 37 describe "with preview" do
... ... @@ -45,10 +42,11 @@ describe "On a merge request", js: true do
45 42 end
46 43 end
47 44  
48   - it { within(".js-main-target-form") { should have_css(".js-note-preview", text: "This is awesome", visible: true) } }
49   -
50   - it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } }
51   - it { within(".js-main-target-form") { should have_css(".js-note-edit-button", visible: true) } }
  45 + it 'should have text and visible edit button' do
  46 + within(".js-main-target-form") { should have_css(".js-note-preview", text: "This is awesome", visible: true) }
  47 + within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) }
  48 + within(".js-main-target-form") { should have_css(".js-note-edit-button", visible: true) }
  49 + end
52 50 end
53 51 end
54 52  
... ... @@ -61,27 +59,20 @@ describe "On a merge request", js: true do
61 59 end
62 60 end
63 61  
64   - # note added
65   - it { should have_content("This is awsome!") }
66   -
67   - # reset form
68   - it { within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") } }
69   -
70   - # return from preview
71   - it { within(".js-main-target-form") { should have_css(".js-note-preview", visible: false) } }
72   - it { within(".js-main-target-form") { should have_css(".js-note-text", visible: true) } }
73   -
  62 + it 'should be added and form reset' do
  63 + should have_content("This is awsome!")
  64 + within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") }
  65 + within(".js-main-target-form") { should have_css(".js-note-preview", visible: false) }
  66 + within(".js-main-target-form") { should have_css(".js-note-text", visible: true) }
  67 + end
74 68  
75 69 it "should be removable" do
76 70 find(".js-note-delete").trigger("click")
77   -
78 71 should_not have_css(".note")
79 72 end
80 73 end
81 74 end
82 75  
83   -
84   -
85 76 describe "On a merge request diff", js: true, focus: true do
86 77 let!(:project) { create(:project_with_code) }
87 78 let!(:merge_request) { create(:merge_request_with_diffs, project: project) }
... ... @@ -89,12 +80,7 @@ describe "On a merge request diff", js: true, focus: true do
89 80 before do
90 81 login_as :user
91 82 project.team << [@user, :master]
92   -
93 83 visit diffs_project_merge_request_path(project, merge_request)
94   -
95   - within '.diffs-tab' do
96   - click_link("Diff")
97   - end
98 84 end
99 85  
100 86 subject { page }
... ... @@ -111,15 +97,15 @@ describe &quot;On a merge request diff&quot;, js: true, focus: true do
111 97 end
112 98  
113 99 describe "the note form" do
114   - # set up hidden fields correctly
115   - it { within(".js-temp-notes-holder") { find("#note_noteable_type").value.should == "MergeRequest" } }
116   - it { within(".js-temp-notes-holder") { find("#note_noteable_id").value.should == merge_request.id.to_s } }
117   - it { within(".js-temp-notes-holder") { find("#note_commit_id").value.should == "" } }
118   - it { within(".js-temp-notes-holder") { find("#note_line_code").value.should == "4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185" } }
119   -
120   - # buttons
121   - it { should have_button("Add Comment") }
122   - it { should have_css(".js-close-discussion-note-form", text: "Cancel") }
  100 + it 'should be valid' do
  101 + within(".js-temp-notes-holder") { find("#note_noteable_type").value.should == "MergeRequest" }
  102 + within(".js-temp-notes-holder") { find("#note_noteable_id").value.should == merge_request.id.to_s }
  103 + within(".js-temp-notes-holder") { find("#note_commit_id").value.should == "" }
  104 + within(".js-temp-notes-holder") { find("#note_line_code").value.should == "4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185" }
  105 +
  106 + should have_button("Add Comment")
  107 + should have_css(".js-close-discussion-note-form", text: "Cancel")
  108 + end
123 109  
124 110 it "shouldn't add a second form for same row" do
125 111 find("#4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185.line_holder .js-add-diff-note-button").trigger("click")
... ... @@ -175,11 +161,12 @@ describe &quot;On a merge request diff&quot;, js: true, focus: true do
175 161 # removed form after submit
176 162 it { should have_no_css("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .js-temp-notes-holder") }
177 163  
178   - # added discussion
179   - it { should have_content("Another comment on line 17") }
180   - it { should have_css("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .notes_holder") }
181   - it { should have_css("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .notes_holder .note", count: 1) }
182   - it { should have_link("Reply") }
  164 + it 'should be added as discussion' do
  165 + should have_content("Another comment on line 17")
  166 + should have_css("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .notes_holder")
  167 + should have_css("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .notes_holder .note", count: 1)
  168 + should have_link("Reply")
  169 + end
183 170  
184 171 it "should remove last note of a discussion" do
185 172 within("#342e16cbbd482ac2047dc679b2749d248cc1428f_18_17.line_holder + .notes_holder") do
... ... @@ -209,13 +196,12 @@ describe &quot;On a merge request diff&quot;, js: true, focus: true do
209 196 end
210 197 end
211 198  
212   - # inserted note
213   - it { should have_content("An additional comment in reply") }
214   - it { within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_css(".note", count: 2) } }
215   -
216   - # removed form after reply
217   - it { within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_no_css("form") } }
218   - it { within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_link("Reply") } }
  199 + it 'should be inserted and form removed from reply' do
  200 + should have_content("An additional comment in reply")
  201 + within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_css(".note", count: 2) }
  202 + within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_no_css("form") }
  203 + within("#4735dfc552ad7bf15ca468adc3cad9d05b624490_184_184.line_holder + .notes_holder") { should have_link("Reply") }
  204 + end
219 205 end
220 206 end
221 207  
... ...