PainterEditPage.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Tests\Browser\Pages;
  3. use Laravel\Dusk\Browser;
  4. use Tests\Browser\Components\Form\Field\HasMany;
  5. use Tests\Models\Painter;
  6. use Tests\Models\Painting;
  7. use Tests\PHPUnit;
  8. class PainterEditPage extends PainterCreatePage
  9. {
  10. /**
  11. * @var \Tests\Models\Painter
  12. */
  13. protected $painter;
  14. public function __construct($model)
  15. {
  16. $this->painter = $model instanceof Painter ? $model : Painter::findOrFail($model);
  17. PHPUnit::assertTrue($this->painter->getKey() > 0);
  18. }
  19. /**
  20. * Get the URL for the page.
  21. *
  22. * @return string
  23. */
  24. public function url()
  25. {
  26. return admin_base_path("tests/painters/{$this->painter->getKey()}/edit");
  27. }
  28. public function assert(Browser $browser)
  29. {
  30. parent::assert($browser);
  31. $browser->with('@form', function (Browser $browser) {
  32. $browser->assertInputValue('username', $this->painter->username);
  33. $browser->assertInputValue('bio', $this->painter->bio);
  34. $browser->within(new HasMany('paintings'), function (Browser $browser) {
  35. $this->painter->paintings->each(function (Painting $painting, $key) use ($browser) {
  36. $browser->withFormGroup($key + 1, function (Browser $browser) use ($painting) {
  37. $browser->assertFormGroupInputValue('title', $painting->title);
  38. $browser->assertFormGroupInputValue('body', $painting->body);
  39. $browser->assertFormGroupInputValue('completed_at', $painting->completed_at);
  40. });
  41. });
  42. });
  43. });
  44. }
  45. }