Merge branch 'master' of github.com:akaunting/akaunting
This commit is contained in:
commit
57b7cc904c
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
@ -30,11 +30,11 @@
|
||||
<thead class="thead-light">
|
||||
<tr class="row table-head-line">
|
||||
<th class="col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block">{{ Form::bulkActionAllGroup() }}</th>
|
||||
<th class="col-xs-4 col-sm-4 col-md-3 col-lg-3 col-xl-2">@sortablelink('name', trans('general.name'), ['filter' => 'active, visible'], ['class' => 'col-aka', 'rel' => 'nofollow'])</th>
|
||||
<th class="col-md-2 col-lg-2 col-xl-3 d-none d-md-block text-left">@sortablelink('number', trans('accounts.number'))</th>
|
||||
<th class="col-sm-2 col-md-2 col-lg-3 col-xl-4 d-none d-sm-block text-right">@sortablelink('opening_balance', trans('accounts.current_balance'))</th>
|
||||
<th class="col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-3">@sortablelink('name', trans('general.name'), ['filter' => 'active, visible'], ['rel' => 'nofollow'])</th>
|
||||
<th class="col-md-2 col-lg-2 col-xl-2 d-none d-md-block text-left">@sortablelink('number', trans('accounts.number'))</th>
|
||||
<th class="col-sm-2 col-md-2 col-lg-2 col-xl-4 d-none d-sm-block text-right">@sortablelink('opening_balance', trans('accounts.current_balance'))</th>
|
||||
<th class="col-xs-4 col-sm-2 col-md-2 col-lg-2 col-xl-1">@sortablelink('enabled', trans('general.enabled'))</th>
|
||||
<th class="col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center">{{ trans('general.actions') }}</th>
|
||||
<th class="col-xs-4 col-sm-2 col-md-1 col-lg-1 col-xl-1 text-center">{{ trans('general.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@ -44,10 +44,10 @@
|
||||
<td class="col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block">
|
||||
{{ Form::bulkActionGroup($item->id, $item->name) }}
|
||||
</td>
|
||||
<td class="col-xs-4 col-sm-4 col-md-3 col-lg-3 col-xl-2"><a class="col-aka" href="{{ route('accounts.edit', $item->id) }}">{{ $item->name }}</a></td>
|
||||
<td class="col-md-2 col-lg-2 col-xl-3 d-none d-md-block text-left">{{ $item->number }}</td>
|
||||
<td class="col-sm-2 col-md-2 col-lg-3 col-xl-4 d-none d-sm-block text-right">@money($item->balance, $item->currency_code, true)</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-2 col-xl-1">
|
||||
<td class="col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-3 long-texts"><a href="{{ route('accounts.edit', $item->id) }}">{{ $item->name }}</a></td>
|
||||
<td class="col-md-2 col-lg-2 col-xl-2 d-none d-md-block text-left">{{ $item->number }}</td>
|
||||
<td class="col-sm-2 col-md-2 col-lg-2 col-xl-4 d-none d-sm-block text-right">@money($item->balance, $item->currency_code, true)</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-1 col-lg-2 col-xl-1">
|
||||
@if (user()->can('update-banking-accounts'))
|
||||
{{ Form::enabledGroup($item->id, $item->name, $item->enabled) }}
|
||||
@else
|
||||
|
@ -45,7 +45,7 @@
|
||||
<tr class="row align-items-center border-top-1">
|
||||
<td class="col-sm-2 col-md-1 col-lg-1 d-none d-sm-block">{{ Form::bulkActionGroup($item->id, $item->account->name) }}</td>
|
||||
<td class="col-sm-3 col-md-2 col-lg-2 d-none d-sm-block"><a class="col-aka" href="{{ route('reconciliations.edit', $item->id) }}">@date($item->created_at)</a></td>
|
||||
<td class="col-xs-3 col-sm-2 col-md-2 col-lg-2">{{ $item->account->name }}</td>
|
||||
<td class="col-xs-3 col-sm-2 col-md-2 col-lg-2 long-texts">{{ $item->account->name }}</td>
|
||||
<td class="col-md-2 col-lg-2 d-none d-lg-block border-0">@date($item->started_at) - @date($item->ended_at)</td>
|
||||
<td class="col-md-2 col-lg-2 d-none d-md-block text-right">@money($item->closing_balance, $item->account->currency_code, true)</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
|
||||
|
@ -56,7 +56,7 @@
|
||||
<td class="col-xs-4 col-sm-4 col-md-3 col-lg-2 col-xl-2 text-right">@money($item->amount, $item->currency_code, true)</td>
|
||||
<td class="col-md-2 col-lg-1 col-xl-1 d-none d-md-block text-left">{{ $item->type_title }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left">{{ $item->category->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left">{{ $item->account->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left long-texts">{{ $item->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-3 col-xl-3 d-none d-md-block long-texts">{{ $item->description }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
@ -53,9 +53,9 @@
|
||||
<tr class="row align-items-center border-top-1">
|
||||
<td class="col-sm-2 col-md-1 d-none d-sm-block">{{ Form::bulkActionGroup($item->id, $item->expense_transaction->account->name) }}</td>
|
||||
<td class="col-md-2 d-none d-md-block"><a class="col-aka" href="{{ route('transfers.edit', $item->id) }}">@date($item->expense_transaction->paid_at)</a></td>
|
||||
<td class="col-sm-2 col-md-3 d-none d-sm-block">{{ $item->expense_transaction->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-4 col-md-2">{{ $item->income_transaction->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 text-right">@money($item->expense_transaction->amount, $item->expense_transaction->currency_code, true)</td>
|
||||
<td class="col-sm-2 col-md-3 d-none d-sm-block long-texts">{{ $item->expense_transaction->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-4 col-md-2 long-texts">{{ $item->income_transaction->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 text-right long-texts">@money($item->expense_transaction->amount, $item->expense_transaction->currency_code, true)</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 text-center">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-neutral btn-sm text-light items-align-center py-2" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
|
@ -78,7 +78,7 @@
|
||||
@endif
|
||||
</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left long-texts">{{ $item->category->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left">{{ $item->account->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left long-texts">{{ $item->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-neutral btn-sm text-light items-align-center py-2" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
|
@ -47,7 +47,7 @@
|
||||
<td class="col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block">
|
||||
{{ Form::bulkActionGroup($item->id, $item->name) }}
|
||||
</td>
|
||||
<td class="col-xs-4 col-sm-3 col-md-4 col-lg-3 col-xl-3">
|
||||
<td class="col-xs-4 col-sm-3 col-md-4 col-lg-3 col-xl-3 long-texts">
|
||||
<a class="col-aka" href="{{ route('vendors.show', $item->id) }}">{{ $item->name }}</a>
|
||||
</td>
|
||||
<td class="col-md-3 col-lg-3 col-xl-3 d-none d-md-block long-texts">
|
||||
|
@ -47,7 +47,7 @@
|
||||
<td class="col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block">
|
||||
{{ Form::bulkActionGroup($item->id, $item->name) }}
|
||||
</td>
|
||||
<td class="col-xs-4 col-sm-3 col-md-4 col-lg-3 col-xl-3">
|
||||
<td class="col-xs-4 col-sm-3 col-md-4 col-lg-3 col-xl-3 long-texts">
|
||||
<a class="col-aka" href="{{ route('customers.show', $item->id) }}">{{ $item->name }}</a>
|
||||
</td>
|
||||
<td class="col-md-3 col-lg-3 col-xl-3 d-none d-md-block long-texts">
|
||||
|
@ -78,7 +78,7 @@
|
||||
@endif
|
||||
</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left long-texts">{{ $item->category->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left">{{ $item->account->name }}</td>
|
||||
<td class="col-lg-2 col-xl-2 d-none d-lg-block text-left long-texts">{{ $item->account->name }}</td>
|
||||
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-neutral btn-sm text-light items-align-center py-2" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
|
@ -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