DashboardsTest updated and Widget factory added.
This commit is contained in:
parent
a0a776350c
commit
c0df9c930e
@ -4,10 +4,11 @@ namespace App\Models\Common;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use Bkwld\Cloner\Cloneable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Widget extends Model
|
||||
{
|
||||
use Cloneable;
|
||||
use Cloneable, HasFactory;
|
||||
|
||||
protected $table = 'widgets';
|
||||
|
||||
@ -36,4 +37,14 @@ class Widget extends Model
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Auth\User', 'App\Models\Common\Dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
protected static function newFactory()
|
||||
{
|
||||
return \Database\Factories\Widget::new();
|
||||
}
|
||||
}
|
||||
|
47
database/factories/Widget.php
Normal file
47
database/factories/Widget.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Common\Dashboard;
|
||||
use App\Models\Common\Widget as Model;
|
||||
|
||||
class Widget extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
public $classes = [
|
||||
'App\Widgets\TotalIncome',
|
||||
'App\Widgets\TotalExpenses',
|
||||
'App\Widgets\TotalProfit',
|
||||
'App\Widgets\CashFlow',
|
||||
'App\Widgets\IncomeByCategory',
|
||||
'App\Widgets\ExpensesByCategory',
|
||||
'App\Widgets\AccountBalance',
|
||||
'App\Widgets\LatestIncome',
|
||||
'App\Widgets\LatestExpenses',
|
||||
'App\Widgets\Currencies',
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$dashboard = Dashboard::first();
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'dashboard_id' => $dashboard->id,
|
||||
'name' => $this->faker->text(15),
|
||||
'class' => $this->faker->randomElement($this->classes),
|
||||
];
|
||||
}
|
||||
}
|
@ -2,9 +2,10 @@
|
||||
|
||||
namespace Tests\Feature\Common;
|
||||
|
||||
use App\Jobs\Common\CreateDashboard;
|
||||
use App\Models\Common\Widget;
|
||||
use App\Models\Common\Dashboard;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
use App\Jobs\Common\CreateDashboard;
|
||||
|
||||
class DashboardsTest extends FeatureTestCase
|
||||
{
|
||||
@ -12,7 +13,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboard'))
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertSeeText(trans_choice('general.dashboards', 1));
|
||||
}
|
||||
|
||||
@ -20,7 +21,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.index'))
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertSeeText(trans_choice('general.dashboards', 2));
|
||||
}
|
||||
|
||||
@ -28,7 +29,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.create'))
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)]));
|
||||
}
|
||||
|
||||
@ -38,7 +39,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('dashboards.store'), $request)
|
||||
->assertStatus(200);
|
||||
->assertOk();
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
@ -53,7 +54,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.edit', $dashboard->id))
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertSee($dashboard->name);
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ class DashboardsTest extends FeatureTestCase
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('dashboards.update', $dashboard->id), $request)
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertSee($request['name']);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
@ -84,18 +85,83 @@ class DashboardsTest extends FeatureTestCase
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('dashboards.destroy', $dashboard->id))
|
||||
->assertStatus(200);
|
||||
->assertOk();
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertSoftDeleted('dashboards', $this->getAssertRequest($request));
|
||||
}
|
||||
|
||||
public function testItShouldSeeWidgetCreate()
|
||||
{
|
||||
$classes = Widget::factory()->classes;
|
||||
$class = $classes[rand(0, 9)];
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('widgets.index'))
|
||||
->assertOk()
|
||||
->assertSeeText((new $class())->getDefaultName());
|
||||
}
|
||||
|
||||
public function testItShouldSeeWidgetEdit()
|
||||
{
|
||||
$widget = Widget::create($this->getWidget());
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('widgets.edit', $widget->id))
|
||||
->assertOk()
|
||||
->assertSee($widget->name);
|
||||
}
|
||||
|
||||
public function testItShouldCreateWidget()
|
||||
{
|
||||
$request = $this->getWidget();
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('widgets.store'), $request)
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('widgets', $this->getAssertRequest($request));
|
||||
}
|
||||
|
||||
public function testItShouldUpdateWidget()
|
||||
{
|
||||
$request = $this->getWidget();
|
||||
|
||||
$widget = Widget::create($request);
|
||||
|
||||
$request['name'] = $this->faker->name;
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('widgets.update', $widget->id), $request)
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('widgets', $this->getAssertRequest($request));
|
||||
}
|
||||
|
||||
public function testItShouldDeleteWidget()
|
||||
{
|
||||
$request = $this->getWidget();
|
||||
|
||||
$widget = Widget::create($request);
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('widgets.destroy', $widget->id))
|
||||
->assertOk();
|
||||
|
||||
$this->assertSoftDeleted('widgets', $this->getAssertRequest($request));
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return Dashboard::factory()->enabled()->users()->raw();
|
||||
}
|
||||
|
||||
public function getWidget()
|
||||
{
|
||||
return Widget::factory()->raw();
|
||||
}
|
||||
|
||||
public function getAssertRequest($request)
|
||||
{
|
||||
unset($request['users']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user