Skip to content

Commit

Permalink
Test user interaction on document page
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sethetter committed Mar 6, 2017
1 parent ae145c8 commit d0165e6
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/Http/Requests/Document/PutSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function authorize()
}
}

return $document && $document->canUserEdit($this->user());
return $document && $document->canUserView($this->user());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/CommentLiked.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function toMail($notifiable)
->subject(trans(static::baseMessageLocation().'.subject', [
'name' => $this->like->user->getDisplayName(),
'comment_type' => $parentType,
'document' => $this->comment->rootAnnotatable->title,
'document' => $this->like->rootAnnotatable->title,
]))
->action(trans('messages.notifications.see_comment', ['comment_type' => $parentType]), $url)
;
Expand Down
256 changes: 250 additions & 6 deletions tests/Browser/DocumentPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public function setUp()
{
parent::setUp();

$this->sponsorUser = factory(User::class)->create();
$this->user = factory(User::class)->create();
$this->sponsor = FactoryHelpers::createActiveSponsorWithUser($this->user);
$this->sponsor = FactoryHelpers::createActiveSponsorWithUser($this->sponsorUser);

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

$this->note1 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $firstWord);
$this->note2 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $secondWord);
$this->note1 = FactoryHelpers::addNoteToDocument($this->sponsorUser, $this->document, $firstWord);
$this->note2 = FactoryHelpers::addNoteToDocument($this->sponsorUser, $this->document, $secondWord);

$this->comment1 = FactoryHelpers::createComment($this->user, $this->document);
$this->comment2 = FactoryHelpers::createComment($this->user, $this->document);
$this->comment1 = FactoryHelpers::createComment($this->sponsorUser, $this->document);
$this->comment2 = FactoryHelpers::createComment($this->sponsorUser, $this->document);

$this->commentReply = FactoryHelpers::createComment($this->user, $this->comment1);
$this->commentReply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
}

public function testCanSeeDocumentContent()
Expand Down Expand Up @@ -152,6 +153,7 @@ public function testLoginRedirectIfLikeCommentWhenNotLoggedIn()
{
$this->browse(function ($browser) {
$browser->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('like', $this->comment1)
->assertPathIs('/login')
;
Expand All @@ -162,6 +164,7 @@ public function testLoginRedirectIfFlagCommentWhenNotLoggedIn()
{
$this->browse(function ($browser) {
$browser->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('flag', $this->comment1)
->assertPathIs('/login')
;
Expand All @@ -172,6 +175,7 @@ public function testLoginRedirectIfLikeNoteWhenNotLoggedIn()
{
$this->browse(function ($browser) {
$browser->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToNote('like', $this->note1)
->assertPathIs('/login')
;
Expand All @@ -182,6 +186,7 @@ public function testLoginRedirectIfFlagNoteWhenNotLoggedIn()
{
$this->browse(function ($browser) {
$browser->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToNote('flag', $this->note1)
->assertPathIs('/login')
;
Expand Down Expand Up @@ -216,4 +221,243 @@ public function testNoteReplyHiddenIfNotLoggedIn()
;
});
}

public function testAddCommentToDocument()
{
$this->browse(function ($browser) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->fillAndSubmitCommentForm()
;

$newComment = $this->document->allComments()
->orderBy('created_at', 'desc')
->first();

// Should jump to and highlight new comment
$browser
->waitFor('.comment#' . $newComment->str_id)
->assertSeeComment($newComment)
;
});
}

public function testAddReplyToComment()
{
$this->browse(function ($browser) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->fillAndSubmitCommentReplyForm($this->comment1)
;

$newComment = $this->document->allComments()
->orderBy('created_at', 'desc')
->first();

// Should jump to and highlight new comment
$browser
->waitFor('.comment#' . $newComment->str_id)
->assertSeeReplyToComment($this->comment1, $newComment)
;
});
}

public function testAddNoteToDocument()
{
$this->browse(function ($browser) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->addNoteToContent()
;

$newNote = $this->document->allComments()
->orderBy('created_at', 'desc')
->first();

$browser
->refresh()
->openNotesPane()
->assertSeeNote($newNote)
;
});
}

public function testAddReplyToNote()
{
$this->browse(function ($browser) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openNotesPane()
->addReplyToNote($this->note1)
;

$newNote = $this->document->allComments()
->orderBy('created_at', 'desc')
->first();

$browser
->refresh()
->openNotesPane()
->assertSeeReplyToNote($this->note1, $newNote)
;
});
}

public function testLikeCommentOnDocument()
{
$commentLikes = $this->comment1->likes_count;

$this->browse(function ($browser) use ($commentLikes) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('like', $this->comment1)
->assertCommentHasActionCount('like', $this->comment1, $commentLikes + 1)
;
});
}

public function testFlagCommentOnDocument()
{
$commentFlags = $this->comment1->flags_count;

$this->browse(function ($browser) use ($commentFlags) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('flag', $this->comment1)
->assertCommentHasActionCount('flag', $this->comment1, $commentFlags + 1)
;
});
}

public function testLikeCommentReply()
{
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
$replyLikes = $reply->likes_count;

$this->browse(function ($browser) use ($reply, $replyLikes) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('like', $reply)
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
;
});
}

public function testFlagCommentReply()
{
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->comment1);
$replyFlags = $reply->flags_count;

$this->browse(function ($browser) use ($reply, $replyFlags) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openCommentsTab()
->addActionToComment('flag', $reply)
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
;
});
}

public function testLikeNoteOnDocument()
{
$noteLikes = $this->note1->likes_count;

$this->browse(function ($browser) use ($noteLikes) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToNote('like', $this->note1)
->assertNoteHasActionCount('like', $this->note1, $noteLikes +1)
;
});
}

public function testFlagNoteOnDocument()
{
$noteFlags = $this->note1->flags_count;

$this->browse(function ($browser) use ($noteFlags) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToNote('flag', $this->note1)
->assertNoteHasActionCount('flag', $this->note1, $noteFlags +1)
;
});
}

public function testLikeNoteReply()
{
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->note1);
$replyLikes = $reply->likes_count;

$this->browse(function ($browser) use ($reply, $replyLikes) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToComment('like', $reply)
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
;
});
}

public function testFlagNoteReply()
{
$reply = FactoryHelpers::createComment($this->sponsorUser, $this->note1);
$replyFlags = $reply->flags_count;

$this->browse(function ($browser) use ($reply, $replyFlags) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->openNotesPane()
->addActionToComment('flag', $reply)
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
;
});
}

public function testSupportDocument()
{
$documentSupport = $this->document->support;

$this->browse(function ($browser) use ($documentSupport) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->click('@supportBtn')
->assertDocumentSupportCount($documentSupport + 1)
;
});
}

public function testOpposeDocument()
{
$documentOppose = $this->document->oppose;

$this->browse(function ($browser) use ($documentOppose) {
$browser
->loginAs($this->user)
->visit(new DocumentPage($this->document))
->click('@opposeBtn')
->assertDocumentOpposeCount($documentOppose + 1)
;
});
}
}
Loading

0 comments on commit d0165e6

Please sign in to comment.