PainterEditPage.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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->scrollToBottom();
  35. $browser->within(new HasMany('paintings'), function (Browser $browser) {
  36. $this->painter->paintings->each(function (Painting $painting, $key) use ($browser) {
  37. $browser->withFormGroup($key + 1, function (Browser $browser) use ($painting) {
  38. $browser->assertFormGroupInputValue('title', $painting->title, $painting->getKey());
  39. $browser->assertFormGroupInputValue('body', $painting->body, $painting->getKey());
  40. $browser->assertFormGroupInputValue('completed_at', $painting->completed_at, $painting->getKey());
  41. });
  42. });
  43. });
  44. });
  45. }
  46. }