đã tạo được test case của createUser
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class CreateAccountTest extends DuskTestCase
|
||||
{
|
||||
/**
|
||||
* Trang đăng ký / đăng nhập hiển thị form nhập thông tin.
|
||||
*/
|
||||
public function test_login_page_shows_form(): void
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/login')
|
||||
->assertSee('Nhập thông tin cá nhân')
|
||||
->assertPresent('input[name="name"]')
|
||||
->assertPresent('input[name="phone"]')
|
||||
->assertPresent('input[name="address"]')
|
||||
->assertPresent('input[name="job"]');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit form rỗng phải hiện lỗi validation.
|
||||
*/
|
||||
public function test_empty_form_shows_validation_errors(): void
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/login')
|
||||
->press('Gửi thông tin')
|
||||
->assertPresent('.text-danger');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Số điện thoại sai định dạng phải hiện lỗi.
|
||||
*/
|
||||
public function test_invalid_phone_shows_error(): void
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/login')
|
||||
->type('name', 'Nguyễn Test')
|
||||
->type('phone', '12345')
|
||||
->type('address', 'Hà Nội')
|
||||
->radio('known_sis', '0')
|
||||
->type('job', 'Kỹ sư')
|
||||
->press('Gửi thông tin')
|
||||
->pause(400)
|
||||
->assertSee('Số điện thoại không đúng định dạng');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Đăng ký thành công với số điện thoại mới và redirect về /game.
|
||||
* Lưu ý: test này dùng số điện thoại ngẫu nhiên để tránh trùng DB.
|
||||
*/
|
||||
public function test_successful_registration_redirects_to_game(): void
|
||||
{
|
||||
$uniquePhone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($uniquePhone) {
|
||||
$browser->visit('/login')
|
||||
->type('name', 'Test Dusk User')
|
||||
->type('phone', $uniquePhone)
|
||||
->type('address', 'Cần Thơ')
|
||||
->radio('known_sis', '1')
|
||||
->type('job', 'Kỹ sư')
|
||||
->press('Gửi thông tin')
|
||||
->waitForText('thành công', 10)
|
||||
->assertPathIs('/game');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Khi đã đăng nhập, GET /login hiển thị trang tài khoản (không có form đăng ký).
|
||||
*/
|
||||
public function test_authenticated_user_sees_account_page(): void
|
||||
{
|
||||
$uniquePhone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($uniquePhone) {
|
||||
// Đảm bảo guest (xóa session từ test trước)
|
||||
$browser->visit('/logout');
|
||||
|
||||
// Đăng ký và đăng nhập
|
||||
$browser->visit('/login')
|
||||
->type('name', 'Dusk Auth User')
|
||||
->type('phone', $uniquePhone)
|
||||
->type('address', 'TP.HCM')
|
||||
->radio('known_sis', '0')
|
||||
->type('job', 'Bác sĩ')
|
||||
->press('Gửi thông tin')
|
||||
->waitForText('thành công', 10)
|
||||
->assertPathIs('/game');
|
||||
|
||||
// Truy cập lại /login sau khi đã đăng nhập: phone field phải được điền sẵn (chỉ xảy ra khi đã login)
|
||||
$browser->visit('/login')
|
||||
->assertInputValue('phone', $uniquePhone);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user