Skip to content

Commit

Permalink
Improve tests and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Aug 26, 2019
1 parent a875e19 commit f563b27
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __invoke($component, $props)
{
return Inertia::render($component, $props);
}
}
}
2 changes: 0 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ServiceProvider extends BaseServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Expand Down
27 changes: 10 additions & 17 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@

namespace Inertia\Tests;

use Illuminate\Http\Request;
use Inertia\Response;
use Inertia\Controller;
use Illuminate\Http\Request;

class ControllerTest extends TestCase
{
public function test_it_returns_an_inertia_response()
public function test_controller_returns_an_inertia_response()
{
$request = new Request();
$request->headers->set('X-Inertia-Partial-Component', 'Component');
$controller = new Controller();

$response = $controller('Component', ['prop1' => true, 'prop2' => false])->toResponse($request);

$response = (new Controller())('User/Edit', ['user' => ['name' => 'Jonathan']]);

$this->assertEquals('app', $response->name());
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals([
'page' => [
'component' => 'Component',
'props' => [
'prop1' => true,
'prop2' => false,
],
'component' => 'User/Edit',
'props' => ['user' => ['name' => 'Jonathan']],
'url' => '',
'version' => null,
]
], $response->getData());
],
], $response->toResponse(new Request())->getData());
}
}
}
2 changes: 1 addition & 1 deletion tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function test_the_helper_function_returns_an_instance_of_the_response_fac

public function test_the_helper_function_returns_a_response_instance()
{
$this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'George']]));
$this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'Jonathan']]));
}

public function test_the_instance_is_the_same_as_the_facade_instance()
Expand Down
30 changes: 8 additions & 22 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,20 @@

namespace Inertia\Tests;

use Illuminate\Routing\RouteCollection;
use Illuminate\Support\Facades\Route;

class RouterTest extends TestCase
{
public function test_configuring_route_via_macro()
public function test_inertia_route_macro()
{
/** @var \Illuminate\Routing\Route $route */
$route = Route::inertia('/', 'Component', ['prop1' => true, 'prop2' => false]);

/** @var RouteCollection $collection */
$collection = Route::getRoutes();

$this->assertNotEmpty($collection->getRoutes());
$this->assertEquals($route, $collection->getRoutes()[0]);
$route = Route::inertia('/', 'User/Edit', ['user' => ['name' => 'Jonathan']]);
$routes = Route::getRoutes();

$this->assertNotEmpty($routes->getRoutes());
$this->assertEquals($route, $routes->getRoutes()[0]);
$this->assertEquals(['GET', 'HEAD'], $route->methods);

$this->assertEquals('/', $route->uri);

$this->assertEquals([
'uses' => '\Inertia\Controller@__invoke',
'controller' => '\Inertia\Controller',
], $route->action);

$this->assertEquals([
'component' => 'Component',
'props' => ['prop1' => true, 'prop2' => false],
], $route->defaults);
$this->assertEquals(['uses' => '\Inertia\Controller@__invoke', 'controller' => '\Inertia\Controller'], $route->action);
$this->assertEquals(['component' => 'User/Edit', 'props' => ['user' => ['name' => 'Jonathan']]], $route->defaults);
}
}
}

0 comments on commit f563b27

Please sign in to comment.