Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
Show All 18 Lines | |||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class UsersTest extends TestCaseDusk | class UsersTest extends TestCaseDusk | ||||
{ | { | ||||
private $profile = [ | private $profile = [ | ||||
'first_name' => 'John', | 'first_name' => 'John', | ||||
'last_name' => 'Doe', | 'last_name' => 'Doe', | ||||
'organization' => 'Kolab Developers', | |||||
]; | ]; | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | public function testInfo(): void | ||||
// Assert form content | // Assert form content | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | $browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | ||||
->assertSeeIn('div.row:nth-child(1) #status', 'Active') | ->assertSeeIn('div.row:nth-child(1) #status', 'Active') | ||||
->assertFocused('div.row:nth-child(2) input') | ->assertFocused('div.row:nth-child(2) input') | ||||
->assertSeeIn('div.row:nth-child(2) label', 'First name') | ->assertSeeIn('div.row:nth-child(2) label', 'First name') | ||||
->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['first_name']) | ->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['first_name']) | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Last name') | ->assertSeeIn('div.row:nth-child(3) label', 'Last name') | ||||
->assertValue('div.row:nth-child(3) input[type=text]', $this->profile['last_name']) | ->assertValue('div.row:nth-child(3) input[type=text]', $this->profile['last_name']) | ||||
->assertSeeIn('div.row:nth-child(4) label', 'Email') | ->assertSeeIn('div.row:nth-child(4) label', 'Organization') | ||||
->assertValue('div.row:nth-child(4) input[type=text]', 'john@kolab.org') | ->assertValue('div.row:nth-child(4) input[type=text]', $this->profile['organization']) | ||||
->assertDisabled('div.row:nth-child(4) input[type=text]') | ->assertSeeIn('div.row:nth-child(5) label', 'Email') | ||||
->assertSeeIn('div.row:nth-child(5) label', 'Email aliases') | ->assertValue('div.row:nth-child(5) input[type=text]', 'john@kolab.org') | ||||
->assertVisible('div.row:nth-child(5) .list-input') | ->assertDisabled('div.row:nth-child(5) input[type=text]') | ||||
->assertSeeIn('div.row:nth-child(6) label', 'Email aliases') | |||||
->assertVisible('div.row:nth-child(6) .list-input') | |||||
->with(new ListInput('#aliases'), function (Browser $browser) { | ->with(new ListInput('#aliases'), function (Browser $browser) { | ||||
$browser->assertListInputValue(['john.doe@kolab.org']) | $browser->assertListInputValue(['john.doe@kolab.org']) | ||||
->assertValue('@input', ''); | ->assertValue('@input', ''); | ||||
}) | }) | ||||
->assertSeeIn('div.row:nth-child(6) label', 'Password') | ->assertSeeIn('div.row:nth-child(7) label', 'Password') | ||||
->assertValue('div.row:nth-child(6) input[type=password]', '') | |||||
->assertSeeIn('div.row:nth-child(7) label', 'Confirm password') | |||||
->assertValue('div.row:nth-child(7) input[type=password]', '') | ->assertValue('div.row:nth-child(7) input[type=password]', '') | ||||
->assertSeeIn('div.row:nth-child(8) label', 'Confirm password') | |||||
->assertValue('div.row:nth-child(8) input[type=password]', '') | |||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
// Clear some fields and submit | // Clear some fields and submit | ||||
$browser->type('#first_name', '') | $browser->type('#first_name', '') | ||||
->type('#last_name', '') | ->type('#last_name', '') | ||||
->click('button[type=submit]'); | ->click('button[type=submit]'); | ||||
}) | }) | ||||
->assertToast(Toast::TYPE_SUCCESS, 'User data updated successfully.'); | ->assertToast(Toast::TYPE_SUCCESS, 'User data updated successfully.'); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function testInfo(): void | ||||
}); | }); | ||||
$john = User::where('email', 'john@kolab.org')->first(); | $john = User::where('email', 'john@kolab.org')->first(); | ||||
$alias = UserAlias::where('user_id', $john->id)->where('alias', 'john.test@kolab.org')->first(); | $alias = UserAlias::where('user_id', $john->id)->where('alias', 'john.test@kolab.org')->first(); | ||||
$this->assertTrue(!empty($alias)); | $this->assertTrue(!empty($alias)); | ||||
// Test subscriptions | // Test subscriptions | ||||
$browser->with('@form', function (Browser $browser) { | $browser->with('@form', function (Browser $browser) { | ||||
$browser->assertSeeIn('div.row:nth-child(8) label', 'Subscriptions') | $browser->assertSeeIn('div.row:nth-child(9) label', 'Subscriptions') | ||||
->assertVisible('@skus.row:nth-child(8)') | ->assertVisible('@skus.row:nth-child(9)') | ||||
->with('@skus', function ($browser) { | ->with('@skus', function ($browser) { | ||||
$browser->assertElementsCount('tbody tr', 5) | $browser->assertElementsCount('tbody tr', 5) | ||||
// Mailbox SKU | // Mailbox SKU | ||||
->assertSeeIn('tbody tr:nth-child(1) td.name', 'User Mailbox') | ->assertSeeIn('tbody tr:nth-child(1) td.name', 'User Mailbox') | ||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '4,44 CHF/month') | ->assertSeeIn('tbody tr:nth-child(1) td.price', '4,44 CHF/month') | ||||
->assertChecked('tbody tr:nth-child(1) td.selection input') | ->assertChecked('tbody tr:nth-child(1) td.selection input') | ||||
->assertDisabled('tbody tr:nth-child(1) td.selection input') | ->assertDisabled('tbody tr:nth-child(1) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | public function testNewUser(): void | ||||
->assertSeeIn('#user-info .card-title', 'New user account') | ->assertSeeIn('#user-info .card-title', 'New user account') | ||||
->with('@form', function (Browser $browser) { | ->with('@form', function (Browser $browser) { | ||||
// Assert form content | // Assert form content | ||||
$browser->assertFocused('div.row:nth-child(1) input') | $browser->assertFocused('div.row:nth-child(1) input') | ||||
->assertSeeIn('div.row:nth-child(1) label', 'First name') | ->assertSeeIn('div.row:nth-child(1) label', 'First name') | ||||
->assertValue('div.row:nth-child(1) input[type=text]', '') | ->assertValue('div.row:nth-child(1) input[type=text]', '') | ||||
->assertSeeIn('div.row:nth-child(2) label', 'Last name') | ->assertSeeIn('div.row:nth-child(2) label', 'Last name') | ||||
->assertValue('div.row:nth-child(2) input[type=text]', '') | ->assertValue('div.row:nth-child(2) input[type=text]', '') | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Email') | ->assertSeeIn('div.row:nth-child(3) label', 'Organization') | ||||
->assertValue('div.row:nth-child(3) input[type=text]', '') | ->assertValue('div.row:nth-child(3) input[type=text]', '') | ||||
->assertEnabled('div.row:nth-child(3) input[type=text]') | ->assertSeeIn('div.row:nth-child(4) label', 'Email') | ||||
->assertSeeIn('div.row:nth-child(4) label', 'Email aliases') | ->assertValue('div.row:nth-child(4) input[type=text]', '') | ||||
->assertVisible('div.row:nth-child(4) .list-input') | ->assertEnabled('div.row:nth-child(4) input[type=text]') | ||||
->assertSeeIn('div.row:nth-child(5) label', 'Email aliases') | |||||
->assertVisible('div.row:nth-child(5) .list-input') | |||||
->with(new ListInput('#aliases'), function (Browser $browser) { | ->with(new ListInput('#aliases'), function (Browser $browser) { | ||||
$browser->assertListInputValue([]) | $browser->assertListInputValue([]) | ||||
->assertValue('@input', ''); | ->assertValue('@input', ''); | ||||
}) | }) | ||||
->assertSeeIn('div.row:nth-child(5) label', 'Password') | ->assertSeeIn('div.row:nth-child(6) label', 'Password') | ||||
->assertValue('div.row:nth-child(5) input[type=password]', '') | |||||
->assertSeeIn('div.row:nth-child(6) label', 'Confirm password') | |||||
->assertValue('div.row:nth-child(6) input[type=password]', '') | ->assertValue('div.row:nth-child(6) input[type=password]', '') | ||||
->assertSeeIn('div.row:nth-child(7) label', 'Package') | ->assertSeeIn('div.row:nth-child(7) label', 'Confirm password') | ||||
->assertValue('div.row:nth-child(7) input[type=password]', '') | |||||
->assertSeeIn('div.row:nth-child(8) label', 'Package') | |||||
// assert packages list widget, select "Lite Account" | // assert packages list widget, select "Lite Account" | ||||
->with('@packages', function ($browser) { | ->with('@packages', function ($browser) { | ||||
$browser->assertElementsCount('tbody tr', 2) | $browser->assertElementsCount('tbody tr', 2) | ||||
->assertSeeIn('tbody tr:nth-child(1)', 'Groupware Account') | ->assertSeeIn('tbody tr:nth-child(1)', 'Groupware Account') | ||||
->assertSeeIn('tbody tr:nth-child(2)', 'Lite Account') | ->assertSeeIn('tbody tr:nth-child(2)', 'Lite Account') | ||||
->assertSeeIn('tbody tr:nth-child(1) .price', '9,99 CHF/month') | ->assertSeeIn('tbody tr:nth-child(1) .price', '9,99 CHF/month') | ||||
->assertSeeIn('tbody tr:nth-child(2) .price', '4,44 CHF/month') | ->assertSeeIn('tbody tr:nth-child(2) .price', '4,44 CHF/month') | ||||
->assertChecked('tbody tr:nth-child(1) input') | ->assertChecked('tbody tr:nth-child(1) input') | ||||
Show All 31 Lines | public function testNewUser(): void | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->with(new ListInput('#aliases'), function (Browser $browser) { | ->with(new ListInput('#aliases'), function (Browser $browser) { | ||||
$browser->assertFormError(1, 'The specified alias is invalid.', false); | $browser->assertFormError(1, 'The specified alias is invalid.', false); | ||||
}); | }); | ||||
}); | }); | ||||
// Successful account creation | // Successful account creation | ||||
$browser->with('@form', function (Browser $browser) { | $browser->with('@form', function (Browser $browser) { | ||||
$browser->with(new ListInput('#aliases'), function (Browser $browser) { | $browser->type('#first_name', 'Julia') | ||||
->type('#last_name', 'Roberts') | |||||
->type('#organization', 'Test Org') | |||||
->with(new ListInput('#aliases'), function (Browser $browser) { | |||||
$browser->removeListEntry(1) | $browser->removeListEntry(1) | ||||
->addListEntry('julia.roberts2@kolab.org'); | ->addListEntry('julia.roberts2@kolab.org'); | ||||
}) | }) | ||||
->click('button[type=submit]'); | ->click('button[type=submit]'); | ||||
}) | }) | ||||
->assertToast(Toast::TYPE_SUCCESS, 'User created successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'User created successfully.') | ||||
// check redirection to users list | // check redirection to users list | ||||
->waitForLocation('/users') | ->waitForLocation('/users') | ||||
->on(new UserList()) | ->on(new UserList()) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->whenAvailable('@table', function (Browser $browser) { | ||||
$browser->assertElementsCount('tbody tr', 5) | $browser->assertElementsCount('tbody tr', 5) | ||||
->assertSeeIn('tbody tr:nth-child(4) a', 'julia.roberts@kolab.org'); | ->assertSeeIn('tbody tr:nth-child(4) a', 'julia.roberts@kolab.org'); | ||||
}); | }); | ||||
$julia = User::where('email', 'julia.roberts@kolab.org')->first(); | $julia = User::where('email', 'julia.roberts@kolab.org')->first(); | ||||
$alias = UserAlias::where('user_id', $julia->id)->where('alias', 'julia.roberts2@kolab.org')->first(); | $alias = UserAlias::where('user_id', $julia->id)->where('alias', 'julia.roberts2@kolab.org')->first(); | ||||
$this->assertTrue(!empty($alias)); | $this->assertTrue(!empty($alias)); | ||||
$this->assertUserEntitlements($julia, ['mailbox', 'storage', 'storage']); | $this->assertUserEntitlements($julia, ['mailbox', 'storage', 'storage']); | ||||
$this->assertSame('Julia', $julia->getSetting('first_name')); | |||||
$this->assertSame('Roberts', $julia->getSetting('last_name')); | |||||
$this->assertSame('Test Org', $julia->getSetting('organization')); | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test user delete | * Test user delete | ||||
* | * | ||||
* @depends testNewUser | * @depends testNewUser | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |