đã tạo được test case của createUser
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class AccountManagementTest extends DuskTestCase
|
||||
{
|
||||
/**
|
||||
* Helper: đăng ký tài khoản mới và đăng nhập.
|
||||
*/
|
||||
private function registerAndLogin(Browser $browser, string $phone): void
|
||||
{
|
||||
$browser->visit('/login')
|
||||
->type('name', 'Dusk Test User')
|
||||
->type('phone', $phone)
|
||||
->type('address', 'Cần Thơ')
|
||||
->radio('known_sis', '1')
|
||||
->type('job', 'Nhân viên văn phòng')
|
||||
->press('Gửi thông tin')
|
||||
->assertPathIs('/game');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cập nhật tài khoản thành công.
|
||||
*/
|
||||
public function test_update_account_successfully(): void
|
||||
{
|
||||
$phone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($phone) {
|
||||
$this->registerAndLogin($browser, $phone);
|
||||
|
||||
$browser->visit('/login')
|
||||
->assertSee('Cập nhật thông tin cá nhân')
|
||||
->clear('name')
|
||||
->type('name', 'Tên Mới Test')
|
||||
->clear('address')
|
||||
->type('address', 'Hà Nội')
|
||||
->radio('known_sis', '0')
|
||||
->clear('job')
|
||||
->type('job', 'Giáo viên')
|
||||
->press('Cập nhật')
|
||||
->assertPathIs('/game')
|
||||
->assertSee('Cập nhật tài khoản thành công');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cập nhật tài khoản với tên rỗng phải hiện lỗi.
|
||||
*/
|
||||
public function test_update_account_with_empty_name_shows_error(): void
|
||||
{
|
||||
$phone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($phone) {
|
||||
$this->registerAndLogin($browser, $phone);
|
||||
|
||||
$browser->visit('/login')
|
||||
->clear('name')
|
||||
->press('Cập nhật')
|
||||
->assertSee('Nhập tên hiển thị');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cập nhật tài khoản với số điện thoại sai phải hiện lỗi.
|
||||
*/
|
||||
public function test_update_account_with_invalid_phone_shows_error(): void
|
||||
{
|
||||
$phone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($phone) {
|
||||
$this->registerAndLogin($browser, $phone);
|
||||
|
||||
$browser->visit('/login')
|
||||
->clear('phone')
|
||||
->type('phone', 'abcde')
|
||||
->press('Cập nhật')
|
||||
->assertSee('Số điện thoại không đúng định dạng');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Trang lịch sử hoạt động hiển thị khi đã đăng nhập.
|
||||
*/
|
||||
public function test_history_section_visible_when_authenticated(): void
|
||||
{
|
||||
$phone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($phone) {
|
||||
$this->registerAndLogin($browser, $phone);
|
||||
|
||||
$browser->visit('/login')
|
||||
->assertSee('LỊCH SỬ HOẠT ĐỘNG');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Đăng xuất thành công.
|
||||
*/
|
||||
public function test_logout_works(): void
|
||||
{
|
||||
$phone = '09' . rand(10000000, 99999999);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($phone) {
|
||||
$this->registerAndLogin($browser, $phone);
|
||||
|
||||
$browser->visit('/logout')
|
||||
->assertGuest();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user