|
101 | 101 | expect(Story.count).to eq 1 |
102 | 102 | end |
103 | 103 |
|
104 | | - it "shows a preview of the description while typing", js: true do |
105 | | - visit project_path(id: project.id) |
106 | | - click_link "Add a Story" |
107 | | - fill_in "story[title]", with: "As a user, I want to add stories" |
| 104 | + context "previews" do |
| 105 | + it "shows a preview of the description while typing", js: true do |
| 106 | + visit project_path(id: project.id) |
| 107 | + click_link "Add a Story" |
| 108 | + fill_in "story[title]", with: "As a user, I want to add stories" |
108 | 109 |
|
109 | | - desc = <<~DESC |
110 | | - This story allows users to add stories. |
| 110 | + desc = <<~DESC |
| 111 | + This story allows users to add stories. |
111 | 112 |
|
112 | | - some |
113 | | - code |
| 113 | + some |
| 114 | + code |
114 | 115 |
|
115 | | - DESC |
| 116 | + DESC |
116 | 117 |
|
117 | | - expect(page).to have_text("Description Preview") |
118 | | - fill_in "story[description]", with: desc |
119 | | - expect(find("#story_description").value).to have_text("This story allows users to add stories.\n\n some\n code\n\n") |
| 118 | + expect(page).to have_text("Description Preview") |
| 119 | + fill_in "story[description]", with: desc |
| 120 | + expect(find("#story_description").value).to have_text("This story allows users to add stories.\n\n some\n code\n\n") |
120 | 121 |
|
121 | | - within(".story_preview .content") do |
122 | | - expect(page).to have_text("This story allows users to add stories.") |
123 | | - expect(page).to have_selector("pre", text: "some\ncode") |
124 | | - end |
| 122 | + within(".story_preview .content") do |
| 123 | + expect(page).to have_text("This story allows users to add stories.") |
| 124 | + expect(page).to have_selector("pre", text: "some\ncode") |
| 125 | + end |
125 | 126 |
|
126 | | - click_button "Create" |
| 127 | + click_button "Create" |
127 | 128 |
|
128 | | - expect(page).to have_text(project.title) |
| 129 | + expect(page).to have_text(project.title) |
129 | 130 |
|
130 | | - story = Story.last |
131 | | - within_story_row(story) do |
132 | | - click_button "More actions" |
133 | | - click_link "Edit" |
134 | | - end |
| 131 | + story = Story.last |
| 132 | + within_story_row(story) do |
| 133 | + click_button "More actions" |
| 134 | + click_link "Edit" |
| 135 | + end |
135 | 136 |
|
136 | | - expect(page).to have_text("Edit Story") |
| 137 | + expect(page).to have_text("Edit Story") |
137 | 138 |
|
138 | | - within(".story_preview .content") do |
139 | | - expect(page).to have_text("This story allows users to add stories.") |
140 | | - expect(page).to have_selector("pre", text: "some\ncode") |
| 139 | + within(".story_preview .content") do |
| 140 | + expect(page).to have_text("This story allows users to add stories.") |
| 141 | + expect(page).to have_selector("pre", text: "some\ncode") |
| 142 | + end |
141 | 143 | end |
142 | | - end |
143 | 144 |
|
144 | | - it "shows a preview of the extra information while typing" do |
145 | | - visit project_path(id: project.id) |
146 | | - click_link "Add a Story" |
147 | | - fill_in "story[title]", with: "As a user, I want to add stories" |
| 145 | + it "shows a preview of the extra information while typing" do |
| 146 | + visit project_path(id: project.id) |
| 147 | + click_link "Add a Story" |
| 148 | + fill_in "story[title]", with: "As a user, I want to add stories" |
148 | 149 |
|
149 | | - desc = <<~DESC |
150 | | - This story allows users to add extra information. |
| 150 | + desc = <<~DESC |
| 151 | + This story allows users to add extra information. |
151 | 152 |
|
152 | | - some |
153 | | - codes |
| 153 | + some |
| 154 | + codes |
154 | 155 |
|
155 | | - DESC |
| 156 | + DESC |
156 | 157 |
|
157 | | - expect(page).to have_text("Extra Info Preview") |
158 | | - fill_in "story[extra_info]", with: desc |
| 158 | + expect(page).to have_text("Extra Info Preview") |
| 159 | + fill_in "story[extra_info]", with: desc |
159 | 160 |
|
160 | | - within(".extra_info_preview .content") do |
161 | | - expect(page).to have_selector("p", text: "This story allows users to add extra information.") |
162 | | - expect(page).to have_selector("pre", text: "some\ncodes") |
163 | | - end |
| 161 | + within(".extra_info_preview .content") do |
| 162 | + expect(page).to have_selector("p", text: "This story allows users to add extra information.") |
| 163 | + expect(page).to have_selector("pre", text: "some\ncodes") |
| 164 | + end |
164 | 165 |
|
165 | | - click_button "Create" |
| 166 | + click_button "Create" |
166 | 167 |
|
167 | | - expect(page).to have_text(project.title) |
| 168 | + expect(page).to have_text(project.title) |
168 | 169 |
|
169 | | - story = Story.last |
170 | | - within_story_row(story) do |
171 | | - click_button "More actions" |
172 | | - click_link "Edit" |
| 170 | + story = Story.last |
| 171 | + within_story_row(story) do |
| 172 | + click_button "More actions" |
| 173 | + click_link "Edit" |
| 174 | + end |
| 175 | + |
| 176 | + expect(page).to have_text("Edit Story") |
| 177 | + |
| 178 | + within(".extra_info_preview .content") do |
| 179 | + expect(page).to have_selector("p", text: "This story allows users to add extra information.") |
| 180 | + expect(page).to have_selector("pre", text: "some\ncodes") |
| 181 | + end |
173 | 182 | end |
174 | 183 |
|
175 | | - expect(page).to have_text("Edit Story") |
| 184 | + it "debounces the requests to update the preview to not flood the server" do |
| 185 | + renderer = double(:markdown_renderer) |
| 186 | + allow(renderer).to receive(:render).and_return("<span>preview</span>") |
| 187 | + allow(Redcarpet::Markdown).to receive(:new).and_return(renderer) |
| 188 | + |
| 189 | + visit project_path(id: project.id) |
| 190 | + click_link "Add a Story" |
| 191 | + fill_in "story[title]", with: "As a user, I want to add stories" |
| 192 | + |
| 193 | + fill_in "story[description]", with: "desc 1" |
| 194 | + fill_in "story[description]", with: "desc 2" |
| 195 | + fill_in "story[description]", with: "desc 3" |
| 196 | + |
| 197 | + # wait until requests are triggered |
| 198 | + sleep(0.5) |
| 199 | + |
| 200 | + fill_in "story[description]", with: "desc 4" |
| 201 | + sleep(0.5) |
176 | 202 |
|
177 | | - within(".extra_info_preview .content") do |
178 | | - expect(page).to have_selector("p", text: "This story allows users to add extra information.") |
179 | | - expect(page).to have_selector("pre", text: "some\ncodes") |
| 203 | + # twice for the initial render of the page (description and extra info) |
| 204 | + # once for the preview of the 3 consecutive inputs |
| 205 | + # once for the preview of the 4th input |
| 206 | + expect(renderer).to have_received(:render).exactly(4).times |
180 | 207 | end |
181 | 208 | end |
182 | 209 |
|
|
0 commit comments