From 9cf91dded538daf03f84f0424e82df496f3f9d74 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Tue, 19 Dec 2023 12:34:59 +0300 Subject: [PATCH] updated show and create test plan --- tests/Feature/Plan/CreateTest.php | 39 ++++++++++++++++++++++++------- tests/Feature/Plan/ShowTest.php | 10 ++++---- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index 11c7092..42ab833 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -32,16 +32,17 @@ class CreateTest extends TestCase $this->user = User::factory()->create(['is_consultant' => true]); $this->plan = Plan::factory()->make(); + + $this->refreshApplicationWithLocale('en'); } public function test_show_form_create_plan() { $response = $this ->actingAs($this->user) - ->get('/plan/create'); + ->get(route('plan.create')); - $response - ->assertStatus(302); + $response->assertSuccessful(); // ->assertRedirect(route('home')); } @@ -50,6 +51,7 @@ class CreateTest extends TestCase $this->actingAs($this->user); // $this->assertEquals($this->plan->count(), $count = Plan::count()); + $planCountAtStart = Plan::count(); Livewire::test(Create::class) ->set('name', $this->plan->name) @@ -72,11 +74,18 @@ class CreateTest extends TestCase ->set('packet3_options', $this->plan->packet3_options) ->assertSet('packet3_options', $this->plan->packet3_options) ->call('publish') - ->assertStatus(200) - ->assertHasNoErrors(['name', 'image', 'duration', 'details']); + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']); Storage::disk('public')->assertExists($this->plan->image); + $this->assertEquals($planCountAtStart + 1, Plan::count()); + + $response = $this->actingAs($this->user)->get(route('plan.index')); + + $response->assertSuccessful(); + + // $this->assertEquals($count + 1, Plan::count()); } @@ -85,7 +94,10 @@ class CreateTest extends TestCase { $this->actingAs($this->user); - $id = $this->plan->count(); + $planCountAtStart = Plan::count(); + + // $planLastId = $this->plan->latest()->first()->id; + // $expectedRedirectRoute = route('plan.show', ['plan' => $planLastId + 1]); Livewire::test(Create::class) ->set('name', $this->plan->name) @@ -108,11 +120,12 @@ class CreateTest extends TestCase ->set('packet3_options', $this->plan->packet3_options) ->assertSet('packet3_options', $this->plan->packet3_options) ->call('addToDrafts') - ->assertStatus(200) - ->assertRedirect('plan/' . $id + 1) + ->assertRedirect() ->assertHasNoErrors(['name', 'image', 'duration', 'details']); Storage::disk('public')->assertExists($this->plan->image); + + $this->assertEquals($planCountAtStart + 1, Plan::count()); } @@ -120,6 +133,8 @@ class CreateTest extends TestCase { $this->actingAs($this->user); + $planCountAtStart = Plan::count(); + Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) @@ -141,16 +156,20 @@ class CreateTest extends TestCase ->set('packet3_options', $this->plan->packet3_options) ->assertSet('packet3_options', $this->plan->packet3_options) ->call('showPreview') - ->assertStatus(200) + ->assertSuccessful() ->assertHasNoErrors(['name', 'image', 'duration', 'details']); Storage::disk('public')->assertExists($this->plan->image); + + $this->assertEquals($planCountAtStart + 1, Plan::count()); } public function test_set_empty_data(): void { $this->actingAs($this->user); + $planCountAtStart = Plan::count(); + Livewire::test(Create::class) ->set('name', null) ->set('image', null) @@ -164,5 +183,7 @@ class CreateTest extends TestCase ->set('packet3_options', null) ->call('publish') ->assertHasErrors(['name', 'image', 'duration', 'details']); + + $this->assertEquals($planCountAtStart, Plan::count()); } } diff --git a/tests/Feature/Plan/ShowTest.php b/tests/Feature/Plan/ShowTest.php index 375435a..9eb5ac6 100644 --- a/tests/Feature/Plan/ShowTest.php +++ b/tests/Feature/Plan/ShowTest.php @@ -31,19 +31,17 @@ class ShowTest extends TestCase $this->image = UploadedFile::fake()->image('plan.png'); $this->user = User::factory()->create(['is_consultant' => true]); - $this->plan = Plan::factory()->create(); - + $this->plan = Plan::inRandomOrder()->first(); + $this->refreshApplicationWithLocale('en'); } public function test_show_form_success() { $response = $this->actingAs($this->user) - ->get('/plan/'. $this->plan->id); + ->get(route('plan.show', ['plan' => $this->plan->id])); $response - ->assertStatus(302); - // ->assertRedirect(route('home')); - // ->assertRedirect('https://dev2.eatvio.com/ru'); + ->assertOk(); } // When appear role for user