<?php

namespace FluxCms\Core\Tests\Browser;

use FluxCms\Core\Models\User;
use FluxCms\Core\Tests\DuskTestCase;
use Laravel\Dusk\Browser;

class LoginTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function test_admin_can_login_successfully()
    {
        $admin = User::factory()->create([
            'email' => 'admin@flux-cms.com',
            'password' => bcrypt('password'),
            'is_admin' => true,
        ]);

        $this->browse(function (Browser $browser) use ($admin) {
            $browser->visit('/login')
                ->type('email', $admin->email)
                ->type('password', 'password')
                ->press('Login')
                ->assertPathIs('/admin/cms');
        });
    }
}
