updated show and create test plan

This commit is contained in:
2023-12-19 12:34:59 +03:00
parent 5698aa1b43
commit 9cf91dded5
2 changed files with 34 additions and 15 deletions

View File

@@ -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());
}
}

View File

@@ -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