From b6f916ce4b9ab4431510e4ca5f498d800411d054 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Mon, 13 Jan 2020 10:53:53 +0300 Subject: [PATCH] added dashboard factory --- database/factories/Dashboard.php | 32 ++++++++++ tests/Feature/Common/DashboardTest.php | 16 ----- tests/Feature/Common/DashboardsTest.php | 85 +++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 database/factories/Dashboard.php delete mode 100644 tests/Feature/Common/DashboardTest.php create mode 100644 tests/Feature/Common/DashboardsTest.php diff --git a/database/factories/Dashboard.php b/database/factories/Dashboard.php new file mode 100644 index 000000000..0809a1776 --- /dev/null +++ b/database/factories/Dashboard.php @@ -0,0 +1,32 @@ +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()); +}); diff --git a/tests/Feature/Common/DashboardTest.php b/tests/Feature/Common/DashboardTest.php deleted file mode 100644 index 73a7a3446..000000000 --- a/tests/Feature/Common/DashboardTest.php +++ /dev/null @@ -1,16 +0,0 @@ -loginAs() - ->get(route('dashboard')) - ->assertStatus(200) - ->assertSeeText(trans_choice('general.dashboards', 1)); - } -} diff --git a/tests/Feature/Common/DashboardsTest.php b/tests/Feature/Common/DashboardsTest.php new file mode 100644 index 000000000..505c7a26f --- /dev/null +++ b/tests/Feature/Common/DashboardsTest.php @@ -0,0 +1,85 @@ +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(); + } +}