This is the code for my tests both of the first tests are passing, but the last one for the password will not and keeps erroring. I will post the error in the comments.
namespace Tests\Browser\Auth;
use Illuminate\Foundation\Testing\DatabaseTruncation;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Tests\Browser\Pages\Auth\Profile;
use Tests\Browser\Pages\Auth\Login;
class ProfileTest extends DuskTestCase
{
use DatabaseTruncation;
private $defaultUser = null;
/**
* Setup for profile tests.
*/
public function setUp(): void
{
parent::setUp();
$this->defaultUser = $this->createUser();
}
/**
* Test unauthenticated users are redirected to login.
*/
public function testUnauthenticatedUsersRedirectedToLogin(): void
{
$this->browse(function (Browser $browser) {
$browser->visit((new Profile)->url())
->assertPathIs((new Login)->url());
});
}
/**
* Test authenticated users can access the profile information form
* and that if functions correctly.
*/
public function testProfileFormAccessibleToAuthenticatedUsers(): void
{
$this->browse(function (Browser $browser) {
$browser->loginAs($this->defaultUser);
$browser->visit(new Profile);
$browser->assertDisabled("@email");
$browser->assertDisabled("@username");
$browser->type("@firstName", "")
->type("@middleName", "middle")
->type("@lastName", "last")
->press("@saveProfileButton")
->refresh()
->assertInputValueIsNot("@firstName", "");
$browser->type("@firstName", "first")
->type("@middleName", "middle")
->type("@lastName", "last")
->press("@saveProfileButton")
->refresh()
->assertInputValue("@middleName", "middle");
$browser->type("@firstName", "first")
->type("@middleName", "middle")
->type("@lastName", "")
->press("@saveProfileButton")
->refresh()
->assertInputValueIsNot("@lastName", "");
$browser->type("@firstName", "first")
->type("@middleName", "middle")
->type("@lastName", "last")
->pressAndWaitFor("@saveProfileButton")
->assertSee("Saved.");
});
}
public function testPasswordFormAccessibleToAuthenticatedUsers(): void
{
$this->browse(function (Browser $browser) {
$browser->loginAs($this->defaultUser);
$browser->visit(new Profile);
$browser->type("@currentPassword", "")
->type("@password", "Password")
->type("@passwordConfirmation", "Password")
->press("@savePasswordButton")
->refresh()
->assertInputValueIsNot("@currentPassword", "");
$browser->type("@currentPassword", "currentPassword")
->type("@password", "")
->type("@passwordConfirmation", "Password")
->press("@savePasswordButton")
->refresh()
->assertInputValueIsNot("@password", "");
$browser->type("@currentPassword", "currentPassword")
->type("@password", "Password")
->type("@passwordConfirmation", "")
->press("@savePasswordButton")
->refresh()
->assertInputValueIsNot("@passwordConfirmation", "");
$browser->type("@currentPassword", "currentPassword")
->type("@password", "Password")
->type("@passwordConfirmation", "Password")
->pressAndWaitFor("@savePasswordButton")
->assertSee("Saved.");
});
}
}