added dashboard factory
This commit is contained in:
parent
35c11c12ed
commit
b6f916ce4b
32
database/factories/Dashboard.php
Normal file
32
database/factories/Dashboard.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Common\Dashboard;
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$user = User::first();
|
||||
$company = $user->companies()->first();
|
||||
|
||||
$factory->define(Dashboard::class, function (Faker $faker) use ($company) {
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
return [
|
||||
'company_id' => $company->id,
|
||||
'name' => $faker->text(15),
|
||||
'enabled' => $faker->boolean ? 1 : 0,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(Dashboard::class, 'enabled', ['enabled' => 1]);
|
||||
|
||||
$factory->state(Dashboard::class, 'disabled', ['enabled' => 0]);
|
||||
|
||||
$factory->state(Dashboard::class, 'users', function (Faker $faker) use ($company) {
|
||||
return [
|
||||
'users' => $company->users()->enabled()->get()->pluck('id')->toArray(),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->afterCreating(Dashboard::class, function ($dashboard, $faker) use ($company) {
|
||||
$dashboard->users()->attach($company->users()->enabled()->get()->pluck('id')->toArray());
|
||||
});
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Common;
|
||||
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class DashboardTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldSeeDashboard()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboard'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.dashboards', 1));
|
||||
}
|
||||
}
|
85
tests/Feature/Common/DashboardsTest.php
Normal file
85
tests/Feature/Common/DashboardsTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Common;
|
||||
|
||||
use App\Jobs\Common\CreateDashboard;
|
||||
use App\Models\Common\Dashboard;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class DashboardsTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldSeeDashboard()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboard'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.dashboards', 1));
|
||||
}
|
||||
|
||||
public function testItShouldSeeDashboardListPage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.index'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.dashboards', 2));
|
||||
}
|
||||
|
||||
public function testItShouldSeeDashboardCreatePage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.create'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)]));
|
||||
}
|
||||
|
||||
public function testItShouldCreateDashboard()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('dashboards.store'), $this->getRequest())
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldSeeDashboardUpdatePage()
|
||||
{
|
||||
$dashboard = $this->dispatch(new CreateDashboard($this->getRequest()));
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('dashboards.edit', $dashboard->id))
|
||||
->assertStatus(200)
|
||||
->assertSee($dashboard->name);
|
||||
}
|
||||
|
||||
public function testItShouldUpdateDashboard()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$dashboard = $this->dispatch(new CreateDashboard($request));
|
||||
|
||||
$request['name'] = $this->faker->text(15);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('dashboards.update', $dashboard->id), $request)
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldDeleteDashboard()
|
||||
{
|
||||
$dashboard_1 = $this->dispatch(new CreateDashboard($this->getRequest()));
|
||||
$dashboard_2 = $this->dispatch(new CreateDashboard($this->getRequest()));
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('dashboards.destroy', $dashboard_2->id))
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return factory(Dashboard::class)->states('enabled', 'users')->raw();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user