Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/WalletTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Transaction; | |||||
use App\Wallet; | use App\Wallet; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\Wallet as WalletPage; | use Tests\Browser\Pages\Wallet as WalletPage; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
class WalletTest extends TestCaseDusk | class WalletTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | |||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
Wallet::where('user_id', $john->id)->update(['balance' => -1234]); | Wallet::where('user_id', $john->id)->update(['balance' => -1234]); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | |||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
Wallet::where('user_id', $john->id)->update(['balance' => 0]); | Wallet::where('user_id', $john->id)->update(['balance' => 0]); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test wallet page (unauthenticated) | * Test wallet page (unauthenticated) | ||||
*/ | */ | ||||
public function testWalletUnauth(): void | public function testWalletUnauth(): void | ||||
{ | { | ||||
Show All 27 Lines | class WalletTest extends TestCaseDusk | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->click('@links .link-wallet') | $browser->click('@links .link-wallet') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->assertSeeIn('#wallet .card-title', 'Account balance') | ->assertSeeIn('#wallet .card-title', 'Account balance') | ||||
->assertSeeIn('#wallet .card-text', 'Current account balance is -12,34 CHF'); | ->assertSeeIn('#wallet .card-text', 'Current account balance is -12,34 CHF'); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test History tab | |||||
*/ | |||||
public function testHistory(): void | |||||
{ | |||||
$user = $this->getTestUser('wallets-controller@kolabnow.com', ['password' => 'simple123']); | |||||
// Log out John and log in the test user | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit('/logout') | |||||
->waitForLocation('/login') | |||||
->on(new Home()) | |||||
->submitLogon('wallets-controller@kolabnow.com', 'simple123', true); | |||||
}); | |||||
$package_kolab = \App\Package::where('title', 'kolab')->first(); | |||||
$user->assignPackage($package_kolab); | |||||
$wallet = $user->wallets()->first(); | |||||
// Create some sample transactions | |||||
$transactions = $this->createTestTransactions($wallet); | |||||
$transactions = array_reverse($transactions); | |||||
$pages = array_chunk($transactions, 10 /* page size*/); | |||||
$this->browse(function (Browser $browser) use ($pages, $wallet) { | |||||
$browser->on(new Dashboard()) | |||||
->click('@links .link-wallet') | |||||
->on(new WalletPage()) | |||||
->assertSeeIn('@nav #tab-history', 'History') | |||||
->with('@history-tab', function (Browser $browser) use ($pages, $wallet) { | |||||
$browser->assertElementsCount('table tbody tr', 10) | |||||
->assertSeeIn('#transactions-loader button', 'Load more'); | |||||
foreach ($pages[0] as $idx => $transaction) { | |||||
$selector = 'table tbody tr:nth-child(' . ($idx + 1) . ')'; | |||||
$priceStyle = $transaction->type == Transaction::WALLET_AWARD ? 'text-success' : 'text-danger'; | |||||
$browser->assertSeeIn("$selector td.description", $transaction->shortDescription()) | |||||
->assertMissing("$selector td.selection button") | |||||
->assertVisible("$selector td.price.{$priceStyle}"); | |||||
// TODO: Test more transaction details | |||||
} | |||||
// Load the next page | |||||
$browser->click('#transactions-loader button') | |||||
->waitUntilMissing('.app-loader') | |||||
->assertElementsCount('table tbody tr', 12) | |||||
->assertMissing('#transactions-loader button'); | |||||
$debitEntry = null; | |||||
foreach ($pages[1] as $idx => $transaction) { | |||||
$selector = 'table tbody tr:nth-child(' . ($idx + 1 + 10) . ')'; | |||||
$priceStyle = $transaction->type == Transaction::WALLET_CREDIT ? 'text-success' : 'text-danger'; | |||||
$browser->assertSeeIn("$selector td.description", $transaction->shortDescription()); | |||||
if ($transaction->type == Transaction::WALLET_DEBIT) { | |||||
$debitEntry = $selector; | |||||
} else { | |||||
$browser->assertMissing("$selector td.selection button"); | |||||
} | |||||
} | |||||
// Load sub-transactions | |||||
$browser->click("$debitEntry td.selection button") | |||||
->waitUntilMissing('.app-loader') | |||||
->assertElementsCount("$debitEntry td.description ul li", 2) | |||||
->assertMissing("$debitEntry td.selection button"); | |||||
}); | |||||
}); | |||||
} | |||||
} | } |