Commit d28176b132bdc74055f31e2d62665d5d74ebacb4

Authored by Riyad Preukschas
1 parent f8e1f4a7

Replace commit diff note request specs with spinach features

features/project/commits/commit_diff_comments.feature 0 → 100644
... ... @@ -0,0 +1,91 @@
  1 +Feature: Comments on commit diffs
  2 + Background:
  3 + Given I sign in as a user
  4 + And I own project "Shop"
  5 + And I visit project commit page
  6 +
  7 + @javascript
  8 + Scenario: I can access add diff comment buttons
  9 + Then I should see add a diff comment button
  10 +
  11 + @javascript
  12 + Scenario: I can comment on a commit diff
  13 + Given I leave a diff comment like "Typo, please fix"
  14 + Then I should see a diff comment saying "Typo, please fix"
  15 +
  16 + @javascript
  17 + Scenario: I get a temporary form for the first comment on a diff line
  18 + Given I open a diff comment form
  19 + Then I should see a temporary diff comment form
  20 +
  21 + @javascript
  22 + Scenario: I have a cancel button on the diff form
  23 + Given I open a diff comment form
  24 + Then I should see the cancel comment button
  25 +
  26 + @javascript
  27 + Scenario: I can cancel a diff form
  28 + Given I open a diff comment form
  29 + And I cancel the diff comment
  30 + Then I should not see the diff comment form
  31 +
  32 + @javascript
  33 + Scenario: I can't open a second form for a diff line
  34 + Given I open a diff comment form
  35 + And I open a diff comment form
  36 + Then I should only see one diff form
  37 +
  38 + @javascript
  39 + Scenario: I can have multiple forms
  40 + Given I open a diff comment form
  41 + And I write a diff comment like ":-1: I don't like this"
  42 + And I open another diff comment form
  43 + Then I should see a diff comment form with ":-1: I don't like this"
  44 + And I should see an empty diff comment form
  45 +
  46 + @javascript
  47 + Scenario: I can preview multiple forms separately
  48 + Given I preview a diff comment text like "Should fix it :smile:"
  49 + And I preview another diff comment text like "DRY this up"
  50 + Then I should see two separate previews
  51 +
  52 + @javascript
  53 + Scenario: I have a reply button in discussions
  54 + Given I leave a diff comment like "Typo, please fix"
  55 + Then I should see a discussion reply button
  56 +
  57 + @javascript
  58 + Scenario: I can't preview without text
  59 + Given I open a diff comment form
  60 + And I haven't written any diff comment text
  61 + Then I should not see the diff comment preview button
  62 +
  63 + @javascript
  64 + Scenario: I can preview with text
  65 + Given I open a diff comment form
  66 + And I write a diff comment like ":-1: I don't like this"
  67 + Then I should see the diff comment preview button
  68 +
  69 + @javascript
  70 + Scenario: I preview a diff comment
  71 + Given I preview a diff comment text like "Should fix it :smile:"
  72 + Then I should see the diff comment preview
  73 + And I should not see the diff comment text field
  74 +
  75 + @javascript
  76 + Scenario: I can edit after preview
  77 + Given I preview a diff comment text like "Should fix it :smile:"
  78 + Then I should see the diff comment edit button
  79 +
  80 + @javascript
  81 + Scenario: The form gets removed after posting
  82 + Given I preview a diff comment text like "Should fix it :smile:"
  83 + And I submit the diff comment
  84 + Then I should not see the diff comment form
  85 + And I should see a discussion reply button
  86 +
  87 + @javascript
  88 + Scenario: I can delete a discussion comment
  89 + Given I leave a diff comment like "Typo, please fix"
  90 + And I delete a diff comment
  91 + Then I should not see a diff comment saying "Typo, please fix"
... ...
features/steps/project/comments_on_commit_diffs.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class CommentsOnCommitDiffs < Spinach::FeatureSteps
  2 + include SharedAuthentication
  3 + include SharedDiffNote
  4 + include SharedPaths
  5 + include SharedProject
  6 +end
... ...
features/steps/shared/diff_note.rb 0 → 100644
... ... @@ -0,0 +1,158 @@
  1 +module SharedDiffNote
  2 + include Spinach::DSL
  3 +
  4 + Given 'I cancel the diff comment' do
  5 + within(".diff_file") do
  6 + find(".js-close-discussion-note-form").trigger("click")
  7 + end
  8 + end
  9 +
  10 + Given 'I delete a diff comment' do
  11 + within(".diff_file") do
  12 + first(".js-note-delete").trigger("click")
  13 + end
  14 + end
  15 +
  16 + Given 'I haven\'t written any diff comment text' do
  17 + within(".diff_file") do
  18 + fill_in "note[note]", with: ""
  19 + end
  20 + end
  21 +
  22 + Given 'I leave a diff comment like "Typo, please fix"' do
  23 + find("#0_29_14.line_holder .js-add-diff-note-button").trigger("click")
  24 + within(".diff_file") do
  25 + fill_in "note[note]", with: "Typo, please fix"
  26 + #click_button("Add Comment")
  27 + find(".js-comment-button").trigger("click")
  28 + end
  29 + end
  30 +
  31 + Given 'I preview a diff comment text like "Should fix it :smile:"' do
  32 + find("#0_29_14.line_holder .js-add-diff-note-button").trigger("click")
  33 + within(".diff_file") do
  34 + fill_in "note[note]", with: "Should fix it :smile:"
  35 + find(".js-note-preview-button").trigger("click")
  36 + end
  37 + end
  38 +
  39 + Given 'I preview another diff comment text like "DRY this up"' do
  40 + find("#0_57_41.line_holder .js-add-diff-note-button").trigger("click")
  41 + within(".diff_file") do
  42 + fill_in "note[note]", with: "DRY this up"
  43 + find(".js-note-preview-button").trigger("click")
  44 + end
  45 + end
  46 +
  47 + Given 'I open a diff comment form' do
  48 + find("#0_29_14.line_holder .js-add-diff-note-button").trigger("click")
  49 + end
  50 +
  51 + Given 'I open another diff comment form' do
  52 + find("#0_57_41.line_holder .js-add-diff-note-button").trigger("click")
  53 + end
  54 +
  55 + Given 'I write a diff comment like ":-1: I don\'t like this"' do
  56 + within(".diff_file") do
  57 + fill_in "note[note]", with: ":-1: I don\'t like this"
  58 + end
  59 + end
  60 +
  61 + Given 'I submit the diff comment' do
  62 + within(".diff_file") do
  63 + click_button("Add Comment")
  64 + end
  65 + end
  66 +
  67 +
  68 +
  69 + Then 'I should not see the diff comment form' do
  70 + within(".diff_file") do
  71 + page.should_not have_css("form.new_note")
  72 + end
  73 + end
  74 +
  75 + Then 'I should not see the diff comment preview button' do
  76 + within(".diff_file") do
  77 + page.should have_css(".js-note-preview-button", visible: false)
  78 + end
  79 + end
  80 +
  81 + Then 'I should not see the diff comment text field' do
  82 + within(".diff_file") do
  83 + page.should have_css(".js-note-text", visible: false)
  84 + end
  85 + end
  86 +
  87 + Then 'I should only see one diff form' do
  88 + within(".diff_file") do
  89 + page.should have_css("form.new_note", count: 1)
  90 + end
  91 + end
  92 +
  93 + Then 'I should see a diff comment form with ":-1: I don\'t like this"' do
  94 + within(".diff_file") do
  95 + page.should have_field("note[note]", with: ":-1: I don\'t like this")
  96 + end
  97 + end
  98 +
  99 + Then 'I should see a diff comment saying "Typo, please fix"' do
  100 + within(".diff_file .note") do
  101 + page.should have_content("Typo, please fix")
  102 + end
  103 + end
  104 +
  105 + Then 'I should see a discussion reply button' do
  106 + within(".diff_file") do
  107 + page.should have_link("Reply")
  108 + end
  109 + end
  110 +
  111 + Then 'I should see a temporary diff comment form' do
  112 + within(".diff_file") do
  113 + page.should have_css(".js-temp-notes-holder form.new_note")
  114 + end
  115 + end
  116 +
  117 + Then 'I should see add a diff comment button' do
  118 + page.should have_css(".js-add-diff-note-button", visible: false)
  119 + end
  120 +
  121 + Then 'I should see an empty diff comment form' do
  122 + within(".diff_file") do
  123 + page.should have_field("note[note]", with: "")
  124 + end
  125 + end
  126 +
  127 + Then 'I should see the cancel comment button' do
  128 + within(".diff_file form") do
  129 + page.should have_css(".js-close-discussion-note-form", text: "Cancel")
  130 + end
  131 + end
  132 +
  133 + Then 'I should see the diff comment preview' do
  134 + within(".diff_file form") do
  135 + page.should have_css(".js-note-preview", visible: false)
  136 + end
  137 + end
  138 +
  139 + Then 'I should see the diff comment edit button' do
  140 + within(".diff_file") do
  141 + page.should have_css(".js-note-edit-button", visible: true)
  142 + end
  143 + end
  144 +
  145 + Then 'I should see the diff comment preview button' do
  146 + within(".diff_file") do
  147 + page.should have_css(".js-note-preview-button", visible: true)
  148 + end
  149 + end
  150 +
  151 + Then 'I should see two separate previews' do
  152 + within(".diff_file") do
  153 + page.should have_css(".js-note-preview", visible: true, count: 2)
  154 + page.should have_content("Should fix it")
  155 + page.should have_content("DRY this up")
  156 + end
  157 + end
  158 +end
... ...
spec/requests/notes_on_commits_spec.rb
... ... @@ -1,137 +0,0 @@
1   -require 'spec_helper'
2   -
3   -describe "On a commit diff", js: true do
4   - let!(:project) { create(:project) }
5   - let!(:commit) { project.repository.commit("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
6   -
7   - before do
8   - login_as :user
9   - project.team << [@user, :reporter]
10   -
11   - visit project_commit_path(project, commit)
12   - end
13   -
14   - subject { page }
15   -
16   - describe "when adding a note" do
17   - before do
18   - find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click")
19   - end
20   -
21   - describe "the notes holder" do
22   - it { should have_css("#0_185_185.line_holder + .js-temp-notes-holder") }
23   -
24   - it { within(".js-temp-notes-holder") { should have_css(".new_note") } }
25   - end
26   -
27   - describe "the note form" do
28   - # set up hidden fields correctly
29   - it { within(".js-temp-notes-holder") { find("#note_noteable_type").value.should == "Commit" } }
30   - it { within(".js-temp-notes-holder") { find("#note_noteable_id").value.should == "" } }
31   - it { within(".js-temp-notes-holder") { find("#note_commit_id").value.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" } }
32   - it { within(".js-temp-notes-holder") { find("#note_line_code").value.should == "0_185_185" } }
33   -
34   - # buttons
35   - it { should have_button("Add Comment") }
36   - it { should have_css(".js-close-discussion-note-form", text: "Cancel") }
37   -
38   - # notification options
39   - it { should have_unchecked_field("Project team") }
40   - it { should have_checked_field("Commit author") }
41   -
42   - it "shouldn't add a second form for same row" do
43   - find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click")
44   -
45   - should have_css("#0_185_185.line_holder + .js-temp-notes-holder form", count: 1)
46   - end
47   -
48   - it "should be removed when canceled" do
49   - find(".js-close-discussion-note-form").trigger("click")
50   -
51   - should have_no_css(".js-temp-notes-holder")
52   - end
53   - end
54   - end
55   -
56   - describe "with muliple note forms" do
57   - before do
58   - find("#0_185_185.line_holder .js-add-diff-note-button").trigger("click")
59   - find("#1_18_17.line_holder .js-add-diff-note-button").trigger("click")
60   - end
61   -
62   - # has two line forms
63   - it { should have_css(".js-temp-notes-holder", count: 2) }
64   -
65   - describe "previewing them separately" do
66   - before do
67   - # add two separate texts and trigger previews on both
68   - within("#0_185_185.line_holder + .js-temp-notes-holder") do
69   - fill_in "note[note]", with: "One comment on line 185"
70   - find(".js-note-preview-button").trigger("click")
71   - end
72   - within("#1_18_17.line_holder + .js-temp-notes-holder") do
73   - fill_in "note[note]", with: "Another comment on line 17"
74   - find(".js-note-preview-button").trigger("click")
75   - end
76   - end
77   -
78   - # check if previews were rendered separately
79   - it { within("#0_185_185.line_holder + .js-temp-notes-holder") { should have_css(".js-note-preview", text: "One comment on line 185") } }
80   - it { within("#1_18_17.line_holder + .js-temp-notes-holder") { should have_css(".js-note-preview", text: "Another comment on line 17") } }
81   - end
82   -
83   - describe "posting a note" do
84   - before do
85   - within("#1_18_17.line_holder + .js-temp-notes-holder") do
86   - fill_in "note[note]", with: "Another comment on line 17"
87   - click_button("Add Comment")
88   - end
89   - end
90   -
91   - # removed form after submit
92   - it { should have_no_css("#1_18_17.line_holder + .js-temp-notes-holder") }
93   -
94   - # added discussion
95   - it { should have_content("Another comment on line 17") }
96   - it { should have_css("#1_18_17.line_holder + .notes_holder") }
97   - it { should have_css("#1_18_17.line_holder + .notes_holder .note", count: 1) }
98   - it { should have_link("Reply") }
99   -
100   - it "should remove last note of a discussion" do
101   - within("#1_18_17.line_holder + .notes_holder") do
102   - find(".js-note-delete").trigger("click")
103   - end
104   -
105   - # removed whole discussion
106   - should_not have_css(".note_holder")
107   - should have_css("#1_18_17.line_holder + #1_18_18.line_holder")
108   - end
109   - end
110   - end
111   -
112   - describe "when replying to a note" do
113   - before do
114   - # create first note
115   - find("#0_184_184.line_holder .js-add-diff-note-button").trigger("click")
116   - within("#0_184_184.line_holder + .js-temp-notes-holder") do
117   - fill_in "note[note]", with: "One comment on line 184"
118   - click_button("Add Comment")
119   - end
120   - # create second note
121   - within("#0_184_184.line_holder + .notes_holder") do
122   - find(".js-discussion-reply-button").trigger("click")
123   - fill_in "note[note]", with: "An additional comment in reply"
124   - click_button("Add Comment")
125   - end
126   - end
127   -
128   - # inserted note
129   - it { should have_content("An additional comment in reply") }
130   - it { within("#0_184_184.line_holder + .notes_holder") { should have_css(".note", count: 2) } }
131   -
132   - # removed form after reply
133   - it { within("#0_184_184.line_holder + .notes_holder") { should have_no_css("form") } }
134   - it { within("#0_184_184.line_holder + .notes_holder") { should have_link("Reply") } }
135   - end
136   -end
137   -
138 0 \ No newline at end of file