Skip to content

Commit

Permalink
Add preview tests for browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin committed Aug 11, 2021
1 parent 8aa2ca6 commit 5451764
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/integration/BrowsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BrowsersTest extends TestCase
'{$stubs}/browsers/ArticleRequest.php' => '{$app}/Http/Requests/Admin/',
'{$stubs}/browsers/ArticleRevision.php' => '{$app}/Models/Revisions/',
'{$stubs}/browsers/articles-form.blade.php' => '{$resources}/views/admin/articles/',
'{$stubs}/browsers/articles-view.blade.php' => '{$resources}/views/site/article.blade.php',

'{$stubs}/browsers/2021_08_10_0004_create_bios_tables.php' => '{$database}/migrations/',
'{$stubs}/browsers/Bio.php' => '{$app}/Models/',
Expand All @@ -38,6 +39,7 @@ class BrowsersTest extends TestCase
'{$stubs}/browsers/BioRequest.php' => '{$app}/Http/Requests/Admin/',
'{$stubs}/browsers/BioRevision.php' => '{$app}/Models/Revisions/',
'{$stubs}/browsers/bios-form.blade.php' => '{$resources}/views/admin/bios/',
'{$stubs}/browsers/bios-view.blade.php' => '{$resources}/views/site/bio.blade.php',

'{$stubs}/browsers/2021_08_10_0005_create_books_tables.php' => '{$database}/migrations/',
'{$stubs}/browsers/Book.php' => '{$app}/Models/',
Expand All @@ -46,6 +48,7 @@ class BrowsersTest extends TestCase
'{$stubs}/browsers/BookRequest.php' => '{$app}/Http/Requests/Admin/',
'{$stubs}/browsers/BookRevision.php' => '{$app}/Models/Revisions/',
'{$stubs}/browsers/books-form.blade.php' => '{$resources}/views/admin/books/',
'{$stubs}/browsers/books-view.blade.php' => '{$resources}/views/site/book.blade.php',

'{$stubs}/browsers/twill-navigation.php' => '{$config}',
'{$stubs}/browsers/admin.php' => '{$base}/routes/admin.php',
Expand Down Expand Up @@ -128,6 +131,7 @@ public function testBrowserBelongsToMany()

$article = $this->createArticle();

// User can attach authors
$this->httpRequestAssert("/twill/articles/{$article->id}", 'PUT', [
'browsers' => [
'authors' => $authors->map(function ($author) {
Expand All @@ -141,6 +145,10 @@ public function testBrowserBelongsToMany()
$authors->pluck('id')->sort()->toArray(),
Article::first()->authors->pluck('id')->sort()->toArray()
);

// User can preview
$this->httpRequestAssert("/twill/articles/preview/{$article->id}", 'PUT', []);
$this->assertSee('This is an article');
}

public function testBrowserBelongsTo()
Expand All @@ -149,6 +157,7 @@ public function testBrowserBelongsTo()

$bio = $this->createBio();

// User can attach authors
$this->httpRequestAssert("/twill/bios/{$bio->id}", 'PUT', [
'browsers' => [
'author' => [
Expand All @@ -159,6 +168,10 @@ public function testBrowserBelongsTo()

$this->assertNotEmpty(Bio::first()->author);
$this->assertEquals($authors[0]->id, Bio::first()->author->id);

// User can preview
$this->httpRequestAssert("/twill/bios/preview/{$bio->id}", 'PUT', []);
$this->assertSee('This is a bio');
}

public function testBrowserRelated()
Expand All @@ -167,6 +180,7 @@ public function testBrowserRelated()

$book = $this->createBook();

// User can attach authors
$this->httpRequestAssert("/twill/books/{$book->id}", 'PUT', [
'browsers' => [
'authors' => $authors->map(function ($author) {
Expand All @@ -184,5 +198,9 @@ public function testBrowserRelated()
$authors->pluck('id')->sort()->toArray(),
Book::first()->getRelated('authors')->pluck('id')->sort()->toArray()
);

// User can preview
$this->httpRequestAssert("/twill/books/preview/{$book->id}", 'PUT', []);
$this->assertSee('This is a book');
}
}
1 change: 1 addition & 0 deletions tests/stubs/browsers/articles-view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>This is an article</div>
1 change: 1 addition & 0 deletions tests/stubs/browsers/bios-view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>This is a bio</div>
1 change: 1 addition & 0 deletions tests/stubs/browsers/books-view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>This is a book</div>

0 comments on commit 5451764

Please sign in to comment.