From 7a66389d241ffe734724df4c94a761f2d458cd08 Mon Sep 17 00:00:00 2001 From: Ryan Scherler Date: Tue, 20 Oct 2020 23:04:14 -0700 Subject: [PATCH] Continue setting up testing. --- config/filament.php | 18 +-------- resources/views/livewire/dashboard.blade.php | 3 ++ routes/web.php | 17 +++++---- src/Http/Livewire/Auth/Login.php | 5 +-- src/Http/Livewire/Dashboard.php | 14 +++++++ tests/Database/Factories/UserFactory.php | 33 +++++++++++++++++ tests/Database/Models/User.php | 39 ++++++++++++++++++++ tests/Feature/LoginTest.php | 16 +++----- tests/TestCase.php | 2 + 9 files changed, 111 insertions(+), 36 deletions(-) create mode 100644 resources/views/livewire/dashboard.blade.php create mode 100644 src/Http/Livewire/Dashboard.php create mode 100644 tests/Database/Factories/UserFactory.php create mode 100644 tests/Database/Models/User.php diff --git a/config/filament.php b/config/filament.php index 5b92e8b817..dd093b19a4 100644 --- a/config/filament.php +++ b/config/filament.php @@ -20,24 +20,11 @@ return [ 'prefix' => [ - /* - |-------------------------------------------------------------------------- - | Route Name Prefix - |-------------------------------------------------------------------------- - | - | This value will set a prefix for all Filament route names. - | - */ - - 'name' => 'filament.', - /* |-------------------------------------------------------------------------- | Route Prefix |-------------------------------------------------------------------------- | - | This value will set a prefix for all Filament routes. - | */ 'route' => 'filament', @@ -47,8 +34,6 @@ return [ | Component Prefix |-------------------------------------------------------------------------- | - | This value will set a prefix for all Filament components. - | | If set with the default "filament", for example, you can reference components like: | | @@ -87,7 +72,8 @@ return [ 'livewire' => [ 'login' => Filament\Http\Livewire\Auth\Login::class, - 'forgot-password' => Filament\Http\Livewire\Auth\ForgotPassword::class, + // 'forgot-password' => Filament\Http\Livewire\Auth\ForgotPassword::class, + 'dashboard' => Filament\Http\Livewire\Dashboard::class, ], ]; diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php new file mode 100644 index 0000000000..d1b66d86e9 --- /dev/null +++ b/resources/views/livewire/dashboard.blade.php @@ -0,0 +1,3 @@ +
+ Dashboard +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index a0fd23bd59..26be51f782 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,13 +6,11 @@ use Filament\Http\Controllers\{ AssetController, }; -$routeNamePrefix = config('filament.prefix.name', 'filament.'); - Route::group([ 'prefix' => config('filament.prefix.route'), 'middleware' => config('filament.middleware', ['web']), - 'as' => $routeNamePrefix, -], function () use ($routeNamePrefix) { + 'as' => 'filament.', +], function () { // Assets Route::name('assets.')->group(function () { Route::get('filament.css', [AssetController::class, 'css'])->name('css'); @@ -23,10 +21,14 @@ Route::group([ // Auth Route::get('/login', config('filament.livewire.login'))->name('login'); - Route::get('/forgot-password', config('filament.livewire.forgot-password'))->name('password.forgot'); + // Route::get('/forgot-password', config('filament.livewire.forgot-password'))->name('password.forgot'); // Authenticated routes Route::group(['middleware' => ['auth', 'verified']], function () { + // Dashboard + Route::get('/', config('filament.livewire.dashboard'))->name('dashboard'); + + /* // User profile Route::get('/profile', config('filament.livewire.profile'))->name('profile'); @@ -37,12 +39,13 @@ Route::group([ Route::get('/user/{user}', config('filament.livewire.user'))->name('show'); }); } + */ }); }); // Conditional route login alias if (!Route::has('login')) { - Route::get('/login', function () use ($routeNamePrefix) { - return redirect()->route("{$routeNamePrefix}login"); + Route::get('/login', function () { + return redirect()->route("filament.login"); })->name('login'); } \ No newline at end of file diff --git a/src/Http/Livewire/Auth/Login.php b/src/Http/Livewire/Auth/Login.php index c6e717cf62..f722b973ca 100644 --- a/src/Http/Livewire/Auth/Login.php +++ b/src/Http/Livewire/Auth/Login.php @@ -2,10 +2,9 @@ namespace Filament\Http\Livewire\Auth; -use App\Providers\RouteServiceProvider; +use Livewire\Component; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use Livewire\Component; use Filament\Traits\ThrottlesLogins; class Login extends Component @@ -34,7 +33,7 @@ class Login extends Component } if (Auth::attempt($data, (bool) $this->remember)) { - return redirect()->intended(RouteServiceProvider::HOME); + return redirect()->intended(route('filament.dashboard')); } // If the login attempt was unsuccessful we will increment the number of attempts diff --git a/src/Http/Livewire/Dashboard.php b/src/Http/Livewire/Dashboard.php new file mode 100644 index 0000000000..ca596ef020 --- /dev/null +++ b/src/Http/Livewire/Dashboard.php @@ -0,0 +1,14 @@ +layout('filament::layouts.auth'); + } +} \ No newline at end of file diff --git a/tests/Database/Factories/UserFactory.php b/tests/Database/Factories/UserFactory.php new file mode 100644 index 0000000000..e04a568eb1 --- /dev/null +++ b/tests/Database/Factories/UserFactory.php @@ -0,0 +1,33 @@ + $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } +} \ No newline at end of file diff --git a/tests/Database/Models/User.php b/tests/Database/Models/User.php new file mode 100644 index 0000000000..357cd67c3d --- /dev/null +++ b/tests/Database/Models/User.php @@ -0,0 +1,39 @@ + 'datetime', + ]; + + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory() + { + return UserFactory::new(); + } +} diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index 7f4361192f..a9c3dbe6f4 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -2,27 +2,24 @@ namespace Tests\Feature; +use Filament\Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; use Livewire\Livewire; -use App\Models\User; -use App\Providers\RouteServiceProvider; -use Filament\Tests\TestCase; +use Filament\Tests\Database\Models\User; use Filament\Http\Livewire\Auth\Login; - class LoginTest extends TestCase { use RefreshDatabase; public function test_can_see_login_form() { - $this->withoutExceptionHandling(); - $this->get('/filament/login') + // $this->withoutExceptionHandling(); + $this->get(route('filament.login')) ->assertSuccessful() ->assertSee(trans('filament::auth.signin')); } - /* public function test_existing_user_can_log_in() { $user = User::factory()->create(); @@ -31,12 +28,11 @@ class LoginTest extends TestCase ->set('email', $user->email) ->set('password', 'password') ->call('login') - ->assertRedirect(RouteServiceProvider::HOME); + ->assertRedirect(route('filament.dashboard')); $this->assertAuthenticated(); } - */ - + /* public function test_email_is_required() { diff --git a/tests/TestCase.php b/tests/TestCase.php index 5ed5b2402a..4b061f3e96 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,6 +24,8 @@ abstract class TestCase extends OrchestraTestCase }); parent::setUp(); + $this->loadLaravelMigrations(['--database' => 'testbench']); + $this->artisan('migrate', ['--database' => 'testbench'])->run(); Facade::setFacadeApplication(app()); }