diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index b4609b4..ce132e2 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -1,6 +1,8 @@ image = UploadedFile::fake()->image('plan.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::factory()->make(); + + } + public function test_show_form_create_plan() { - $user = User::factory()->create(); - - $response = $this->actingAs($user) + $response = $this->actingAs($this->user) ->get('/plan/create'); $response @@ -31,83 +47,88 @@ class CreateTest extends TestCase public function test_publish_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(['is_consultant' => true]); + $countPlanBeforeCreated = $this->plan->count(); - $count = $plan->count(); - - - $this->actingAs($user); + $this->actingAs($this->user); Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) ->call('publish') // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); - $this->assertEquals($plan->count(), $count + 1); + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } // public function test_to_draft_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(); -// - $this->actingAs($user); -// + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) ->call('addToDrafts') + // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); + + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } // public function test_to_preview_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(); -// - $this->actingAs($user); -// + + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) - ->call('addToDrafts') + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) + ->call('showPreview') + // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + $countPlanAfterCreated = $this->plan->count(); - // ->assertRedirect('/plan/'. $plan->id); + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } + }