whisper-money/tests/Pest.php

100 lines
3.4 KiB
PHP

<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature', 'Browser');
pest()->browser()->timeout(15000);
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
// expect()->extend('toBeOne', function () {
// return $this->toBe(1);
// });
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function setupEncryptionKey($page, ?string $key = null): void
{
$key ??= base64_encode(random_bytes(32));
$currentUrl = $page->url();
$page->script("localStorage.setItem('encryption_key', ".json_encode($key).')');
// Reload to trigger sync
$page->navigate($currentUrl)->wait(1);
// Reload again to ensure sync completes
$page->navigate($currentUrl)->wait(3);
}
function createCategoryViaUI($page, string $name, string $color = 'green', string $type = 'Expense'): void
{
$page->click('Create Category')
->wait(0.5)
->fill('name', $name)
->click('Select an icon')
->wait(0.5)
->click('//div[@role="option"][1]')
->wait(0.3)
->click('Select a color')
->wait(0.5)
->click("//div[@role=\"option\"][contains(., \"{$color}\")]")
->wait(0.3)
->click('Select a type')
->wait(0.5)
->click("//div[@role=\"option\"][contains(., \"{$type}\")]")
->wait(0.3)
->click('button[type="submit"]')
->wait(2);
}
function createAccountViaUI($page, string $displayName, string $bankName, string $type = 'Checking', string $currency = 'USD'): void
{
$page->assertSee('Bank accounts');
$page->click('Create Account')
->wait(0.5)
->fill('#display_name', $displayName)
->click('[data-testid="bank-select"]')
->wait(0.5)
->fill('input[placeholder="Search bank..."]', $bankName)
->wait(0.5)
->click($bankName)
->click('button[name="type"]')
->wait(0.5)
->click("[role=\"option\"]:has-text(\"{$type}\")")
->wait(0.3)
->click('button[name="currency_code"]')
->wait(0.5)
->click("[role=\"option\"]:has-text(\"{$currency}\")")
->wait(0.3)
->click('[data-testid="submit-account"]')
->wait(2);
}