|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Browser; |
| 4 | + |
| 5 | +use Tests\DuskTestCase; |
| 6 | +use Tests\Browser\Pages\DocumentPage; |
| 7 | +use Tests\FactoryHelpers; |
| 8 | + |
| 9 | +use App\Models\Doc as Document; |
| 10 | +use App\Models\DocContent; |
| 11 | +use App\Models\User; |
| 12 | + |
| 13 | +class DocumentPageTest extends DuskTestCase |
| 14 | +{ |
| 15 | + |
| 16 | + public function setUp() |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + |
| 20 | + $this->user = factory(User::class)->create(); |
| 21 | + $this->sponsor = FactoryHelpers::createActiveSponsorWithUser($this->user); |
| 22 | + |
| 23 | + $this->document = factory(Document::class)->create([ |
| 24 | + 'publish_state' => Document::PUBLISH_STATE_PUBLISHED, |
| 25 | + ]); |
| 26 | + |
| 27 | + $this->document->content()->save(factory(DocContent::class)->make()); |
| 28 | + |
| 29 | + $this->document->sponsors()->save($this->sponsor); |
| 30 | + |
| 31 | + $firstWord = explode(' ', $this->document->content()->first()->content)[0]; |
| 32 | + $secondWord = explode(' ', $this->document->content()->first()->content)[1]; |
| 33 | + |
| 34 | + $this->note1 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $firstWord); |
| 35 | + $this->note2 = FactoryHelpers::addNoteToDocument($this->user, $this->document, $secondWord); |
| 36 | + |
| 37 | + $this->comment1 = FactoryHelpers::createComment($this->user, $this->document); |
| 38 | + $this->comment2 = FactoryHelpers::createComment($this->user, $this->document); |
| 39 | + |
| 40 | + $this->commentReply = FactoryHelpers::createComment($this->user, $this->comment1); |
| 41 | + } |
| 42 | + |
| 43 | + public function testCanSeeDocumentContent() |
| 44 | + { |
| 45 | + $this->browse(function ($browser) { |
| 46 | + $browser->visit(new DocumentPage($this->document)) |
| 47 | + ->assertTitleContains($this->document->title) |
| 48 | + ->assertSee($this->document->title) |
| 49 | + ->assertSeeIn('@sponsorList', $this->document->sponsors()->first()->display_name) |
| 50 | + ; |
| 51 | + |
| 52 | + foreach (explode("\n\n", $this->document->content()->first()->content) as $p) { |
| 53 | + $browser->assertSee($p); |
| 54 | + } |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + public function testCanSeeDocumentStats() |
| 59 | + { |
| 60 | + $this->browse(function ($browser) { |
| 61 | + $browser->visit(new DocumentPage($this->document)) |
| 62 | + ->assertSeeIn('@participantCount', '1') |
| 63 | + ->assertSeeIn('@notesCount', '2') |
| 64 | + ->assertSeeIn('@commentsCount', '3') |
| 65 | + ->assertSeeIn('@supportBtn', '0') |
| 66 | + ->assertSeeIn('@opposeBtn', '0') |
| 67 | + ; |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + public function testDiscussionHiddenHidesAllTheThings() |
| 72 | + { |
| 73 | + $this->document->update(['discussion_state' => Document::DISCUSSION_STATE_HIDDEN]); |
| 74 | + |
| 75 | + $this->browse(function ($browser) { |
| 76 | + $browser->visit(new DocumentPage($this->document)) |
| 77 | + ->assertDontSee('@participantCount') |
| 78 | + ->assertDontSee('@notesCount') |
| 79 | + ->assertDontSee('@commentsCount') |
| 80 | + ->assertDontSee('@supportBtn') |
| 81 | + ->assertDontSee('@opposeBtn') |
| 82 | + ->assertDontSee('@contentTab') |
| 83 | + ->assertDontSee('@commentsTab') |
| 84 | + ->assertDontSee('@annotationGroups') |
| 85 | + ; |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + public function testViewDocumentComments() |
| 90 | + { |
| 91 | + /** |
| 92 | + * Not testing for timestamps here because they end up off by a second or so |
| 93 | + */ |
| 94 | + $this->browse(function ($browser) { |
| 95 | + $browser->visit(new DocumentPage($this->document)) |
| 96 | + ->openCommentsTab() |
| 97 | + ->assertSeeComment($this->comment1) |
| 98 | + ->assertSeeComment($this->comment2) |
| 99 | + ->assertSeeReplyToComment($this->comment1, $this->commentReply) |
| 100 | + ; |
| 101 | + }); |
| 102 | + } |
| 103 | + |
| 104 | + public function testViewDocumentNotes() |
| 105 | + { |
| 106 | + /** |
| 107 | + * Not testing for timestamps here because they end up off by a second or so |
| 108 | + */ |
| 109 | + $this->browse(function ($browser) { |
| 110 | + $browser->visit(new DocumentPage($this->document)) |
| 111 | + ->openNotesPane() |
| 112 | + ->assertSeeNote($this->note1) |
| 113 | + ->assertSeeNote($this->note2) |
| 114 | + ; |
| 115 | + }); |
| 116 | + } |
| 117 | + |
| 118 | + public function testCantViewUnpublishedDocument() |
| 119 | + { |
| 120 | + $this->document->update([ |
| 121 | + 'publish_state' => Document::PUBLISH_STATE_UNPUBLISHED, |
| 122 | + ]); |
| 123 | + |
| 124 | + $this->browse(function ($browser) { |
| 125 | + $browser->visit(new DocumentPage($this->document)) |
| 126 | + ->assertSee('This action is unauthorized') |
| 127 | + ; |
| 128 | + }); |
| 129 | + } |
| 130 | + |
| 131 | + public function testLoginRedirectIfSupportWhenNotLoggedIn() |
| 132 | + { |
| 133 | + $this->browse(function ($browser) { |
| 134 | + $browser->visit(new DocumentPage($this->document)) |
| 135 | + ->click('@supportBtn') |
| 136 | + ->assertPathIs('/login') |
| 137 | + ; |
| 138 | + }); |
| 139 | + } |
| 140 | + |
| 141 | + public function testLoginRedirectIfOpposeWhenNotLoggedIn() |
| 142 | + { |
| 143 | + $this->browse(function ($browser) { |
| 144 | + $browser->visit(new DocumentPage($this->document)) |
| 145 | + ->click('@opposeBtn') |
| 146 | + ->assertPathIs('/login') |
| 147 | + ; |
| 148 | + }); |
| 149 | + } |
| 150 | + |
| 151 | + public function testLoginRedirectIfLikeCommentWhenNotLoggedIn() |
| 152 | + { |
| 153 | + $this->browse(function ($browser) { |
| 154 | + $browser->visit(new DocumentPage($this->document)) |
| 155 | + ->addActionToComment('like', $this->comment1) |
| 156 | + ->assertPathIs('/login') |
| 157 | + ; |
| 158 | + }); |
| 159 | + } |
| 160 | + |
| 161 | + public function testLoginRedirectIfFlagCommentWhenNotLoggedIn() |
| 162 | + { |
| 163 | + $this->browse(function ($browser) { |
| 164 | + $browser->visit(new DocumentPage($this->document)) |
| 165 | + ->addActionToComment('flag', $this->comment1) |
| 166 | + ->assertPathIs('/login') |
| 167 | + ; |
| 168 | + }); |
| 169 | + } |
| 170 | + |
| 171 | + public function testLoginRedirectIfLikeNoteWhenNotLoggedIn() |
| 172 | + { |
| 173 | + $this->browse(function ($browser) { |
| 174 | + $browser->visit(new DocumentPage($this->document)) |
| 175 | + ->addActionToNote('like', $this->note1) |
| 176 | + ->assertPathIs('/login') |
| 177 | + ; |
| 178 | + }); |
| 179 | + } |
| 180 | + |
| 181 | + public function testLoginRedirectIfFlagNoteWhenNotLoggedIn() |
| 182 | + { |
| 183 | + $this->browse(function ($browser) { |
| 184 | + $browser->visit(new DocumentPage($this->document)) |
| 185 | + ->addActionToNote('flag', $this->note1) |
| 186 | + ->assertPathIs('/login') |
| 187 | + ; |
| 188 | + }); |
| 189 | + } |
| 190 | + |
| 191 | + public function testCommentFormsHiddenIfNotLoggedIn() |
| 192 | + { |
| 193 | + $this->browse(function ($browser) { |
| 194 | + $browser->visit(new DocumentPage($this->document)) |
| 195 | + ->openCommentsTab() |
| 196 | + ->assertDontSee('@commentForm') |
| 197 | + ->with(DocumentPage::commentSelector($this->comment1), function($commentDiv) { |
| 198 | + $commentDiv->assertDontSee('@commentForm'); |
| 199 | + }) |
| 200 | + ; |
| 201 | + }); |
| 202 | + } |
| 203 | + |
| 204 | + public function testNoteReplyHiddenIfNotLoggedIn() |
| 205 | + { |
| 206 | + $this->browse(function ($browser) { |
| 207 | + $browser->visit(new DocumentPage($this->document)) |
| 208 | + ->openNotesPane() |
| 209 | + ->with(DocumentPage::noteSelector($this->note1), function($commentDiv) { |
| 210 | + $commentDiv |
| 211 | + ->assertDontSee('@noteReplyForm') |
| 212 | + ->clickLink('Add your reply') |
| 213 | + ->assertPathIs('/login') |
| 214 | + ; |
| 215 | + }) |
| 216 | + ; |
| 217 | + }); |
| 218 | + } |
| 219 | +} |
0 commit comments