2019-07-31 12:37:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Browser;
|
|
|
|
|
|
|
|
use App\Models\ClientContact;
|
2020-05-14 23:04:41 +02:00
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\RecurringInvoice;
|
2019-07-31 12:37:55 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
|
|
use Tests\DuskTestCase;
|
|
|
|
|
|
|
|
class ClientPortalTest extends DuskTestCase
|
|
|
|
{
|
|
|
|
use WithFaker;
|
|
|
|
use MakesHash;
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
public $contact;
|
|
|
|
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
$this->browse(function ($browser) {
|
|
|
|
$browser->driver->manage()->deleteAllCookies();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:37:55 +02:00
|
|
|
public function testLoginPageDisplayed()
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->browse(function ($browser) {
|
2019-07-31 12:37:55 +02:00
|
|
|
$browser->visit('/client/login')
|
2020-05-14 23:04:41 +02:00
|
|
|
->assertPathIs('/client/login');
|
2019-07-31 12:37:55 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLoginAValidUser()
|
|
|
|
{
|
2020-05-14 23:04:41 +02:00
|
|
|
$this->browse(function ($browser) {
|
2019-07-31 12:37:55 +02:00
|
|
|
$browser->visit('/client/login')
|
2020-05-14 23:04:41 +02:00
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard')
|
|
|
|
->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
2019-07-31 12:37:55 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-12 13:08:44 +02:00
|
|
|
public function testDashboardElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
|
|
|
$browser->visit('/client/dashboard')
|
2020-05-14 23:04:41 +02:00
|
|
|
->assertSee(ctrans('texts.quick_overview_statistics'))
|
2019-10-12 13:08:44 +02:00
|
|
|
->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test list of invoices.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvoicesElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$invoice = Invoice::first();
|
|
|
|
|
2019-10-12 13:08:44 +02:00
|
|
|
$browser->visit('/client/invoices')
|
|
|
|
->assertSee(ctrans('texts.pay_now'))
|
2020-05-14 23:04:41 +02:00
|
|
|
->assertSee($invoice->number)
|
|
|
|
->clickLink(ctrans('texts.view'))
|
|
|
|
->assertPathIs(route('client.invoice.show', $invoice->hashed_id, false))
|
|
|
|
->assertSee(ctrans('texts.pay_now'));
|
|
|
|
|
|
|
|
$browser->visit('/client/invoices')
|
|
|
|
->check('#paid')
|
|
|
|
->assertSee(ctrans('texts.paid'))
|
2019-10-12 13:08:44 +02:00
|
|
|
->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecurringInvoicesElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$invoice = RecurringInvoice::first();
|
|
|
|
|
2019-10-12 13:08:44 +02:00
|
|
|
$browser->visit('/client/recurring_invoices')
|
2020-05-14 23:04:41 +02:00
|
|
|
->assertSee(ctrans('texts.recurring_invoices'))
|
|
|
|
->clickLink(ctrans('texts.view'))
|
|
|
|
->assertPathIs(route('client.recurring_invoices.show', $invoice->hashed_id, false))
|
|
|
|
->visit('/client/logout')
|
2019-10-12 13:08:44 +02:00
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of payments.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPaymentsElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit('/client/login')
|
2019-10-12 13:08:44 +02:00
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$payment = Payment::first();
|
|
|
|
|
2019-10-12 13:08:44 +02:00
|
|
|
$browser->visit('/client/payments')
|
2020-05-14 23:04:41 +02:00
|
|
|
->clickLink(ctrans('texts.view'))
|
|
|
|
->assertPathIs(route('client.payments.show', $payment->hashed_id, false))
|
2020-02-16 04:21:02 +01:00
|
|
|
->visit('/client/logout')
|
2019-10-12 13:08:44 +02:00
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of payment methods.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPaymentMethodsElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit('/client/login')
|
2019-10-12 13:08:44 +02:00
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$browser->visit('/client/payment_methods')
|
2020-05-14 23:04:41 +02:00
|
|
|
->assertSee('No results found.')
|
2019-10-12 13:08:44 +02:00
|
|
|
->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
public function testQuotesElements(): void
|
2019-10-12 13:08:44 +02:00
|
|
|
{
|
2020-05-14 23:04:41 +02:00
|
|
|
$this->browse(function ($browser) {
|
2019-10-12 13:08:44 +02:00
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$credit = Credit::first();
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit('/client/quotes')
|
|
|
|
->clickLink(ctrans('texts.view'))
|
|
|
|
->assertPathIs(route('client.credits.show', $credit->hashed_id, false))
|
|
|
|
->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
public function testCreditsElements(): void
|
|
|
|
{
|
|
|
|
$this->browse(function ($browser) {
|
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit('/client/credits')
|
|
|
|
->assertSee('No results found.')
|
|
|
|
->visit('client/logout')
|
2019-10-12 13:08:44 +02:00
|
|
|
->assertPathIs('/client/login');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
public function testProfilePageContactUpdate(): void
|
2019-10-12 13:08:44 +02:00
|
|
|
{
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
$this->browse(function ($browser) use ($faker) {
|
|
|
|
$browser->visit('/client/login')
|
|
|
|
->type('email', 'user@example.com')
|
|
|
|
->type('password', config('ninja.testvars.password'))
|
|
|
|
->press('Login')
|
|
|
|
->assertPathIs('/client/dashboard');
|
|
|
|
|
|
|
|
$client_contact = ClientContact::where('email', 'user@example.com')->first();
|
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->maximize();
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit(sprintf('/client/profile/%s/edit', $client_contact->client->user->hashed_id))
|
|
|
|
->assertSee(ctrans('texts.profile'));
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$first_name = $browser->value('#first_name');
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->value('#first_name', $faker->firstName);
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->assertSee(ctrans('texts.save'))
|
|
|
|
->press(ctrans('texts.save'));
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$this->assertNotEquals($first_name, $browser->value('#first_name'));
|
2019-10-12 13:08:44 +02:00
|
|
|
|
2020-05-14 23:04:41 +02:00
|
|
|
$browser->visit('client/logout')
|
|
|
|
->assertPathIs('/client/login');
|
2019-10-12 13:08:44 +02:00
|
|
|
});
|
|
|
|
}
|
2019-10-16 22:12:38 +02:00
|
|
|
}
|