Skip to content

Commit

Permalink
Notification tests ready and waiting
Browse files Browse the repository at this point in the history
Summary:
Commented out until [the dusk issue with mocking](laravel/dusk#152) is resolved

Resolves T211

Test Plan: * `make test`

Reviewers: doshitan

Reviewed By: doshitan

Maniphest Tasks: T206, T211

Differential Revision: https://phabricator.opengovfoundation.org/D124
  • Loading branch information
sethetter committed Mar 8, 2017
1 parent d0165e6 commit bde26a2
Showing 1 changed file with 184 additions and 1 deletion.
185 changes: 184 additions & 1 deletion tests/Browser/DocumentPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
use Tests\DuskTestCase;
use Tests\Browser\Pages\DocumentPage;
use Tests\FactoryHelpers;

use Illuminate\Support\Facades\Notification;
use App\Models\Annotation;
use App\Models\Doc as Document;
use App\Models\DocContent;
use App\Models\User;
use App\Notifications\CommentCreatedOnSponsoredDocument;
use App\Notifications\CommentReplied;
use App\Notifications\CommentLiked;
use App\Notifications\CommentFlagged;
use App\Notifications\SupportVoteChanged;


class DocumentPageTest extends DuskTestCase
{
Expand Down Expand Up @@ -39,6 +46,12 @@ public function setUp()
$this->comment2 = FactoryHelpers::createComment($this->sponsorUser, $this->document);

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

// TODO: Mocking does not work with Dusk yet!
// -- ref: https://github.com/laravel/dusk/issues/152

//FactoryHelpers::subscribeUsersToAllNotifications();
//Notification::fake();
}

public function testCanSeeDocumentContent()
Expand Down Expand Up @@ -241,6 +254,14 @@ public function testAddCommentToDocument()
->waitFor('.comment#' . $newComment->str_id)
->assertSeeComment($newComment)
;

//Notification::assertSentTo(
// $this->user,
// CommentCreatedOnSponsoredDocument::class,
// function ($notification, $channels) use ($newComment) {
// $notification->comment->id === $newComment->id;
// }
//);
});
}

Expand All @@ -263,6 +284,22 @@ public function testAddReplyToComment()
->waitFor('.comment#' . $newComment->str_id)
->assertSeeReplyToComment($this->comment1, $newComment)
;

//Notification::assertSentTo(
// $this->user,
// CommentCreatedOnSponsoredDocument::class,
// function ($notification, $channels) use ($newComment) {
// $notification->comment->id === $newComment->id;
// }
//);

//Notification::assertSentTo(
// $this->user,
// CommentReplied::class,
// function ($notification, $channels) use ($newComment) {
// $notification->comment->id === $newComment->id;
// }
//);
});
}

Expand All @@ -284,6 +321,14 @@ public function testAddNoteToDocument()
->openNotesPane()
->assertSeeNote($newNote)
;

//Notification::assertSentTo(
// $this->user,
// CommentCreatedOnSponsoredDocument::class,
// function ($notification, $channels) use ($newNote) {
// $notification->comment->id === $newNote->id;
// }
//);
});
}

Expand All @@ -306,6 +351,22 @@ public function testAddReplyToNote()
->openNotesPane()
->assertSeeReplyToNote($this->note1, $newNote)
;

//Notification::assertSentTo(
// $this->user,
// CommentCreatedOnSponsoredDocument::class,
// function ($notification, $channels) use ($newNote) {
// $notification->comment->id === $newNote->id;
// }
//);

//Notification::assertSentTo(
// $this->user,
// CommentReplied::class,
// function ($notification, $channels) use ($newNote) {
// $notification->comment->id === $newNote->id;
// }
//);
});
}

Expand All @@ -321,6 +382,18 @@ public function testLikeCommentOnDocument()
->addActionToComment('like', $this->comment1)
->assertCommentHasActionCount('like', $this->comment1, $commentLikes + 1)
;

//$newLike = Annotation::where('annotation_type_type', Annotation::TYPE_LIKE)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentLiked::class,
// function ($notification, $channels) use ($newLike) {
// $notification->like->id === $newLike->id;
// }
//);
});
}

Expand All @@ -336,6 +409,18 @@ public function testFlagCommentOnDocument()
->addActionToComment('flag', $this->comment1)
->assertCommentHasActionCount('flag', $this->comment1, $commentFlags + 1)
;

//$newFlag = Annotation::where('annotation_type_type', Annotation::TYPE_FLAG)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentFlagged::class,
// function ($notification, $channels) use ($newFlag) {
// $notification->flag->id === $newFlag->id;
// }
//);
});
}

Expand All @@ -352,6 +437,18 @@ public function testLikeCommentReply()
->addActionToComment('like', $reply)
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
;

//$newLike = Annotation::where('annotation_type_type', Annotation::TYPE_COMMENT)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentLiked::class,
// function ($notification, $channels) use ($newLike) {
// $notification->like->id === $newLike->id;
// }
//);
});
}

Expand All @@ -368,6 +465,18 @@ public function testFlagCommentReply()
->addActionToComment('flag', $reply)
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
;

//$newFlag = Annotation::where('annotation_type_type', Annotation::TYPE_FLAG)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentFlagged::class,
// function ($notification, $channels) use ($newFlag) {
// $notification->flag->id === $newFlag->id;
// }
//);
});
}

Expand All @@ -383,6 +492,18 @@ public function testLikeNoteOnDocument()
->addActionToNote('like', $this->note1)
->assertNoteHasActionCount('like', $this->note1, $noteLikes +1)
;

//$newLike = Annotation::where('annotation_type_type', Annotation::TYPE_LIKE)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentLiked::class,
// function ($notification, $channels) use ($newLike) {
// $notification->like->id === $newLike->id;
// }
//);
});
}

Expand All @@ -398,6 +519,18 @@ public function testFlagNoteOnDocument()
->addActionToNote('flag', $this->note1)
->assertNoteHasActionCount('flag', $this->note1, $noteFlags +1)
;

//$newFlag = Annotation::where('annotation_type_type', Annotation::TYPE_FLAG)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentFlagged::class,
// function ($notification, $channels) use ($newFlag) {
// $notification->flag->id === $newFlag->id;
// }
//);
});
}

Expand All @@ -414,6 +547,18 @@ public function testLikeNoteReply()
->addActionToComment('like', $reply)
->assertCommentHasActionCount('like', $reply, $replyLikes + 1)
;

//$newLike = Annotation::where('annotation_type_type', Annotation::TYPE_LIKE)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentLiked::class,
// function ($notification, $channels) use ($newLike) {
// $notification->like->id === $newLike->id;
// }
//);
});
}

Expand All @@ -430,6 +575,18 @@ public function testFlagNoteReply()
->addActionToComment('flag', $reply)
->assertCommentHasActionCount('flag', $reply, $replyFlags + 1)
;

//$newFlag = Annotation::where('annotation_type_type', Annotation::TYPE_FLAG)
// ->orderBy('created_at', 'desc')
// ->first();

//Notification::assertSentTo(
// $this->user,
// CommentFlagged::class,
// function ($notification, $channels) use ($newFlag) {
// return $notification->flag->id === $newFlag->id;
// }
//);
});
}

Expand All @@ -444,6 +601,19 @@ public function testSupportDocument()
->click('@supportBtn')
->assertDocumentSupportCount($documentSupport + 1)
;

//Notification::assertSentTo(
// $this->user,
// SupportVoteChanged::class,
// function ($notification, $channels) {
// return
// $notification->document->id === $this->document->id &&
// $notification->user->id === $this->user2->id &&
// $notification->oldValue === null &&
// $notification->newValue === 'support'
// ;
// }
//);
});
}

Expand All @@ -458,6 +628,19 @@ public function testOpposeDocument()
->click('@opposeBtn')
->assertDocumentOpposeCount($documentOppose + 1)
;

//Notification::assertSentTo(
// $this->user,
// SupportVoteChanged::class,
// function ($notification, $channels) {
// return
// $notification->document->id === $this->document->id &&
// $notification->user->id === $this->user2->id &&
// $notification->oldValue === null &&
// $notification->newValue === 'oppose'
// ;
// }
//);
});
}
}

0 comments on commit bde26a2

Please sign in to comment.