mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 03:34:36 -04:00
View Composers + JS testing framework (#2521)
* Add Jest testing to travis * View Composers * Composers
This commit is contained in:
parent
6a390aedbc
commit
cdb98ce528
@ -65,6 +65,7 @@ before_script:
|
|||||||
script:
|
script:
|
||||||
- php ./vendor/bin/phpunit --debug --verbose --coverage-clover=coverage.xml
|
- php ./vendor/bin/phpunit --debug --verbose --coverage-clover=coverage.xml
|
||||||
- php artisan dusk
|
- php artisan dusk
|
||||||
|
- npm test
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class ClientController extends Controller
|
|||||||
'data' => 'function(d) { d.key = "value"; }',
|
'data' => 'function(d) { d.key = "value"; }',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$data['header'] = $this->headerData();
|
//$data['header'] = $this->headerData();
|
||||||
$data['html'] = $html;
|
$data['html'] = $html;
|
||||||
|
|
||||||
return view('client.list', $data);
|
return view('client.list', $data);
|
||||||
|
39
app/Http/ViewComposers/HeaderComposer.php
Normal file
39
app/Http/ViewComposers/HeaderComposer.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\ViewComposers;
|
||||||
|
|
||||||
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class HeaderComposer
|
||||||
|
{
|
||||||
|
use UserSessionAttributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind data to the view.
|
||||||
|
*
|
||||||
|
* @param View $view
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function compose(View $view)
|
||||||
|
{
|
||||||
|
$view->with('header', $this->headerData());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function headerData()
|
||||||
|
{
|
||||||
|
//companies
|
||||||
|
$companies = auth()->user()->companies;
|
||||||
|
|
||||||
|
$data['current_company'] = $companies->first(function ($company){
|
||||||
|
return $company->id == $this->getCurrentCompanyId();
|
||||||
|
});
|
||||||
|
|
||||||
|
$data['companies'] = $companies->reject(function ($company){
|
||||||
|
return $company->id == $this->getCurrentCompanyId();
|
||||||
|
});
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
app/Providers/ComposerServiceProvider.php
Normal file
36
app/Providers/ComposerServiceProvider.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class ComposerServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
View::composer(
|
||||||
|
[
|
||||||
|
'client.edit',
|
||||||
|
'client.list',
|
||||||
|
'dashboard.index',
|
||||||
|
],
|
||||||
|
'App\Http\ViewComposers\HeaderComposer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Utils\Traits;
|
namespace App\Utils\Traits;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +15,7 @@ trait MakesHeaderData
|
|||||||
public function headerData()
|
public function headerData()
|
||||||
{
|
{
|
||||||
//companies
|
//companies
|
||||||
$companies = Auth::user()->companies;
|
$companies = auth()->user()->companies;
|
||||||
|
|
||||||
$data['current_company'] = $companies->first(function ($company){
|
$data['current_company'] = $companies->first(function ($company){
|
||||||
return $company->id == $this->getCurrentCompanyId();
|
return $company->id == $this->getCurrentCompanyId();
|
||||||
|
@ -179,6 +179,7 @@ return [
|
|||||||
// App\Providers\BroadcastServiceProvider::class,
|
// App\Providers\BroadcastServiceProvider::class,
|
||||||
App\Providers\EventServiceProvider::class,
|
App\Providers\EventServiceProvider::class,
|
||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
|
App\Providers\ComposerServiceProvider::class,
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user