View Composers + JS testing framework (#2521)

* Add Jest testing to travis

* View Composers

* Composers
This commit is contained in:
David Bomba 2018-11-26 15:15:08 +11:00 committed by GitHub
parent 6a390aedbc
commit cdb98ce528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 3 deletions

View File

@ -65,6 +65,7 @@ before_script:
script:
- php ./vendor/bin/phpunit --debug --verbose --coverage-clover=coverage.xml
- php artisan dusk
- npm test
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -81,7 +81,7 @@ class ClientController extends Controller
'data' => 'function(d) { d.key = "value"; }',
]);
$data['header'] = $this->headerData();
//$data['header'] = $this->headerData();
$data['html'] = $html;
return view('client.list', $data);

View 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;
}
}

View 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()
{
//
}
}

View File

@ -1,7 +1,6 @@
<?php
namespace App\Utils\Traits;
use Illuminate\Support\Facades\Auth;
/**
@ -16,7 +15,7 @@ trait MakesHeaderData
public function headerData()
{
//companies
$companies = Auth::user()->companies;
$companies = auth()->user()->companies;
$data['current_company'] = $companies->first(function ($company){
return $company->id == $this->getCurrentCompanyId();

View File

@ -179,6 +179,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ComposerServiceProvider::class,
],