Skip to content

Commit d0165e6

Browse files
committed
Test user interaction on document page
Summary: * Commenting on the document * Creating notes on the document * Replying to comments and notes * Like/flag comments, notes, and their replies * Supporting and opposing the document Resolves T206 Test Plan: * `make test` Reviewers: doshitan Reviewed By: doshitan Maniphest Tasks: T206 Differential Revision: https://phabricator.opengovfoundation.org/D123
1 parent ae145c8 commit d0165e6

File tree

5 files changed

+404
-23
lines changed

5 files changed

+404
-23
lines changed

app/Http/Requests/Document/PutSupport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function authorize()
2626
}
2727
}
2828

29-
return $document && $document->canUserEdit($this->user());
29+
return $document && $document->canUserView($this->user());
3030
}
3131

3232
/**

app/Notifications/CommentLiked.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function toMail($notifiable)
5454
->subject(trans(static::baseMessageLocation().'.subject', [
5555
'name' => $this->like->user->getDisplayName(),
5656
'comment_type' => $parentType,
57-
'document' => $this->comment->rootAnnotatable->title,
57+
'document' => $this->like->rootAnnotatable->title,
5858
]))
5959
->action(trans('messages.notifications.see_comment', ['comment_type' => $parentType]), $url)
6060
;

tests/Browser/DocumentPageTest.php

Lines changed: 250 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public function setUp()
1717
{
1818
parent::setUp();
1919

20+
$this->sponsorUser = factory(User::class)->create();
2021
$this->user = factory(User::class)->create();
21-
$this->sponsor = FactoryHelpers::createActiveSponsorWithUser($this->user);
22+
$this->sponsor = FactoryHelpers::createActiveSponsorWithUser($this->sponsorUser);
2223

2324
$this->document = factory(Document::class)->create([
2425
'publish_state' => Document::PUBLISH_STATE_PUBLISHED,
@@ -31,13 +32,13 @@ public function setUp()
3132
$firstWord = explode(' ', $this->document->content()->first()->content)[0];
3233
$secondWord = explode(' ', $this->document->content()->first()->content)[1];
3334

34-
$this->note1 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $firstWord);
35-
$this->note2 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $secondWord);
35+
$this->note1 = FactoryHelpers::addNoteToDocument($this->sponsorUser, $this->document, $firstWord);
36+
$this->note2 = FactoryHelpers::addNoteToDocument($this->sponsorUser, $this->document, $secondWord);
3637

37-
$this->comment1 = FactoryHelpers::createComment($this->user, $this->document);
38-
$this->comment2 = FactoryHelpers::createComment($this->user, $this->document);
38+
$this->comment1 = FactoryHelpers::createComment($this->sponsorUser, $this->document);
39+
$this->comment2 = FactoryHelpers::createComment($this->sponsorUser, $this->document);
3940

40-
$this->commentReply = FactoryHelpers::createComment($this->user, $this->comment1);
41+
$this->commentReply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
4142
}
4243

4344
public function testCanSeeDocumentContent()
@@ -152,6 +153,7 @@ public function testLoginRedirectIfLikeCommentWhenNotLoggedIn()
152153
{
153154
$this->browse(function ($browser) {
154155
$browser->visit(new DocumentPage($this->document))
156+
->openCommentsTab()
155157
->addActionToComment('like', $this->comment1)
156158
->assertPathIs('/login')
157159
;
@@ -162,6 +164,7 @@ public function testLoginRedirectIfFlagCommentWhenNotLoggedIn()
162164
{
163165
$this->browse(function ($browser) {
164166
$browser->visit(new DocumentPage($this->document))
167+
->openCommentsTab()
165168
->addActionToComment('flag', $this->comment1)
166169
->assertPathIs('/login')
167170
;
@@ -172,6 +175,7 @@ public function testLoginRedirectIfLikeNoteWhenNotLoggedIn()
172175
{
173176
$this->browse(function ($browser) {
174177
$browser->visit(new DocumentPage($this->document))
178+
->openNotesPane()
175179
->addActionToNote('like', $this->note1)
176180
->assertPathIs('/login')
177181
;
@@ -182,6 +186,7 @@ public function testLoginRedirectIfFlagNoteWhenNotLoggedIn()
182186
{
183187
$this->browse(function ($browser) {
184188
$browser->visit(new DocumentPage($this->document))
189+
->openNotesPane()
185190
->addActionToNote('flag', $this->note1)
186191
->assertPathIs('/login')
187192
;
@@ -216,4 +221,243 @@ public function testNoteReplyHiddenIfNotLoggedIn()
216221
;
217222
});
218223
}
224+
225+
public function testAddCommentToDocument()
226+
{
227+
$this->browse(function ($browser) {
228+
$browser
229+
->loginAs($this->user)
230+
->visit(new DocumentPage($this->document))
231+
->openCommentsTab()
232+
->fillAndSubmitCommentForm()
233+
;
234+
235+
$newComment = $this->document->allComments()
236+
->orderBy('created_at', 'desc')
237+
->first();
238+
239+
// Should jump to and highlight new comment
240+
$browser
241+
->waitFor('.comment#' . $newComment->str_id)
242+
->assertSeeComment($newComment)
243+
;
244+
});
245+
}
246+
247+
public function testAddReplyToComment()
248+
{
249+
$this->browse(function ($browser) {
250+
$browser
251+
->loginAs($this->user)
252+
->visit(new DocumentPage($this->document))
253+
->openCommentsTab()
254+
->fillAndSubmitCommentReplyForm($this->comment1)
255+
;
256+
257+
$newComment = $this->document->allComments()
258+
->orderBy('created_at', 'desc')
259+
->first();
260+
261+
// Should jump to and highlight new comment
262+
$browser
263+
->waitFor('.comment#' . $newComment->str_id)
264+
->assertSeeReplyToComment($this->comment1, $newComment)
265+
;
266+
});
267+
}
268+
269+
public function testAddNoteToDocument()
270+
{
271+
$this->browse(function ($browser) {
272+
$browser
273+
->loginAs($this->user)
274+
->visit(new DocumentPage($this->document))
275+
->addNoteToContent()
276+
;
277+
278+
$newNote = $this->document->allComments()
279+
->orderBy('created_at', 'desc')
280+
->first();
281+
282+
$browser
283+
->refresh()
284+
->openNotesPane()
285+
->assertSeeNote($newNote)
286+
;
287+
});
288+
}
289+
290+
public function testAddReplyToNote()
291+
{
292+
$this->browse(function ($browser) {
293+
$browser
294+
->loginAs($this->user)
295+
->visit(new DocumentPage($this->document))
296+
->openNotesPane()
297+
->addReplyToNote($this->note1)
298+
;
299+
300+
$newNote = $this->document->allComments()
301+
->orderBy('created_at', 'desc')
302+
->first();
303+
304+
$browser
305+
->refresh()
306+
->openNotesPane()
307+
->assertSeeReplyToNote($this->note1, $newNote)
308+
;
309+
});
310+
}
311+
312+
public function testLikeCommentOnDocument()
313+
{
314+
$commentLikes = $this->comment1->likes_count;
315+
316+
$this->browse(function ($browser) use ($commentLikes) {
317+
$browser
318+
->loginAs($this->user)
319+
->visit(new DocumentPage($this->document))
320+
->openCommentsTab()
321+
->addActionToComment('like', $this->comment1)
322+
->assertCommentHasActionCount('like', $this->comment1, $commentLikes + 1)
323+
;
324+
});
325+
}
326+
327+
public function testFlagCommentOnDocument()
328+
{
329+
$commentFlags = $this->comment1->flags_count;
330+
331+
$this->browse(function ($browser) use ($commentFlags) {
332+
$browser
333+
->loginAs($this->user)
334+
->visit(new DocumentPage($this->document))
335+
->openCommentsTab()
336+
->addActionToComment('flag', $this->comment1)
337+
->assertCommentHasActionCount('flag', $this->comment1, $commentFlags + 1)
338+
;
339+
});
340+
}
341+
342+
public function testLikeCommentReply()
343+
{
344+
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
345+
$replyLikes = $reply->likes_count;
346+
347+
$this->browse(function ($browser) use ($reply, $replyLikes) {
348+
$browser
349+
->loginAs($this->user)
350+
->visit(new DocumentPage($this->document))
351+
->openCommentsTab()
352+
->addActionToComment('like', $reply)
353+
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
354+
;
355+
});
356+
}
357+
358+
public function testFlagCommentReply()
359+
{
360+
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
361+
$replyFlags = $reply->flags_count;
362+
363+
$this->browse(function ($browser) use ($reply, $replyFlags) {
364+
$browser
365+
->loginAs($this->user)
366+
->visit(new DocumentPage($this->document))
367+
->openCommentsTab()
368+
->addActionToComment('flag', $reply)
369+
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
370+
;
371+
});
372+
}
373+
374+
public function testLikeNoteOnDocument()
375+
{
376+
$noteLikes = $this->note1->likes_count;
377+
378+
$this->browse(function ($browser) use ($noteLikes) {
379+
$browser
380+
->loginAs($this->user)
381+
->visit(new DocumentPage($this->document))
382+
->openNotesPane()
383+
->addActionToNote('like', $this->note1)
384+
->assertNoteHasActionCount('like', $this->note1, $noteLikes +1)
385+
;
386+
});
387+
}
388+
389+
public function testFlagNoteOnDocument()
390+
{
391+
$noteFlags = $this->note1->flags_count;
392+
393+
$this->browse(function ($browser) use ($noteFlags) {
394+
$browser
395+
->loginAs($this->user)
396+
->visit(new DocumentPage($this->document))
397+
->openNotesPane()
398+
->addActionToNote('flag', $this->note1)
399+
->assertNoteHasActionCount('flag', $this->note1, $noteFlags +1)
400+
;
401+
});
402+
}
403+
404+
public function testLikeNoteReply()
405+
{
406+
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->note1);
407+
$replyLikes = $reply->likes_count;
408+
409+
$this->browse(function ($browser) use ($reply, $replyLikes) {
410+
$browser
411+
->loginAs($this->user)
412+
->visit(new DocumentPage($this->document))
413+
->openNotesPane()
414+
->addActionToComment('like', $reply)
415+
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
416+
;
417+
});
418+
}
419+
420+
public function testFlagNoteReply()
421+
{
422+
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->note1);
423+
$replyFlags = $reply->flags_count;
424+
425+
$this->browse(function ($browser) use ($reply, $replyFlags) {
426+
$browser
427+
->loginAs($this->user)
428+
->visit(new DocumentPage($this->document))
429+
->openNotesPane()
430+
->addActionToComment('flag', $reply)
431+
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
432+
;
433+
});
434+
}
435+
436+
public function testSupportDocument()
437+
{
438+
$documentSupport = $this->document->support;
439+
440+
$this->browse(function ($browser) use ($documentSupport) {
441+
$browser
442+
->loginAs($this->user)
443+
->visit(new DocumentPage($this->document))
444+
->click('@supportBtn')
445+
->assertDocumentSupportCount($documentSupport + 1)
446+
;
447+
});
448+
}
449+
450+
public function testOpposeDocument()
451+
{
452+
$documentOppose = $this->document->oppose;
453+
454+
$this->browse(function ($browser) use ($documentOppose) {
455+
$browser
456+
->loginAs($this->user)
457+
->visit(new DocumentPage($this->document))
458+
->click('@opposeBtn')
459+
->assertDocumentOpposeCount($documentOppose + 1)
460+
;
461+
});
462+
}
219463
}

0 commit comments

Comments
 (0)