Separated laravel app to its own folder (#540)
This commit is contained in:
40
api/tests/Browser/LoginTest.php
Normal file
40
api/tests/Browser/LoginTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\Browser\Pages\Home;
|
||||
use Tests\Browser\Pages\Login;
|
||||
|
||||
uses(\Tests\DuskTestCase::class);
|
||||
|
||||
/** @test */
|
||||
it('can login onboarded users', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->createUserWorkspace($user);
|
||||
|
||||
$this->browse(function ($browser) use ($user) {
|
||||
$browser->visit(new Login())
|
||||
->submit($user->email, 'password')
|
||||
->assertPageIs(Home::class);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot login with invalid credentials', function () {
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit(new Login())
|
||||
->submit('test@test.app', 'password')
|
||||
->pause(100)
|
||||
->assertSee('These credentials do not match our records.');
|
||||
});
|
||||
});
|
||||
|
||||
it('can log out the user', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->browse(function ($browser) use ($user) {
|
||||
$browser->visit(new Login())
|
||||
->submit($user->email, 'password')
|
||||
->on(new Home())
|
||||
->clickLogout()
|
||||
->assertPageIs(Login::class);
|
||||
});
|
||||
});
|
||||
53
api/tests/Browser/Pages/Home.php
Normal file
53
api/tests/Browser/Pages/Home.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class Home extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/home';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
$browser->waitForLocation($this->url())->assertPathIs($this->url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element shortcuts for the page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function elements()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Click on the log out link.
|
||||
*
|
||||
* @param \Laravel\Dusk\Browser $browser
|
||||
* @return void
|
||||
*/
|
||||
public function clickLogout($browser)
|
||||
{
|
||||
$browser->click('@nav-dropdown-button')
|
||||
->waitFor('@nav-dropdown')
|
||||
->waitForText('Logout')
|
||||
->clickLink('Logout')
|
||||
->pause(100);
|
||||
}
|
||||
}
|
||||
40
api/tests/Browser/Pages/HomePage.php
Normal file
40
api/tests/Browser/Pages/HomePage.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class HomePage extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element shortcuts for the page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function elements()
|
||||
{
|
||||
return [
|
||||
'@element' => '#selector',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
api/tests/Browser/Pages/Login.php
Normal file
32
api/tests/Browser/Pages/Login.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
class Login extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/login';
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the form with the given credentials.
|
||||
*
|
||||
* @param \Laravel\Dusk\Browser $browser
|
||||
* @param string $email
|
||||
* @param string $password
|
||||
* @return void
|
||||
*/
|
||||
public function submit($browser, $email, $password)
|
||||
{
|
||||
$browser->type('email', $email)
|
||||
->type('password', $password)
|
||||
->press('@btn_login')
|
||||
->pause(500);
|
||||
}
|
||||
}
|
||||
38
api/tests/Browser/Pages/Onboarding.php
Normal file
38
api/tests/Browser/Pages/Onboarding.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class Onboarding extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/onboarding';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
$browser->waitForLocation($this->url())->assertPathIs($this->url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element shortcuts for the page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function elements()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
31
api/tests/Browser/Pages/Page.php
Normal file
31
api/tests/Browser/Pages/Page.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Laravel\Dusk\Page as BasePage;
|
||||
|
||||
abstract class Page extends BasePage
|
||||
{
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
$browser->assertPathIs($this->url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global element shortcuts for the site.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function siteElements()
|
||||
{
|
||||
return [
|
||||
'@element' => '#selector',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
api/tests/Browser/Pages/Register.php
Normal file
32
api/tests/Browser/Pages/Register.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
class Register extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/register';
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the form with the given data.
|
||||
*
|
||||
* @param \Laravel\Dusk\Browser $browser
|
||||
* @return void
|
||||
*/
|
||||
public function submit($browser, array $data = [])
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$browser->type($key, $value);
|
||||
}
|
||||
|
||||
$browser->press('Register')
|
||||
->pause(1000);
|
||||
}
|
||||
}
|
||||
72
api/tests/Browser/RegisterTest.php
Normal file
72
api/tests/Browser/RegisterTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\Browser\Pages\Onboarding;
|
||||
use Tests\Browser\Pages\Register;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class RegisterTest extends DuskTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setup();
|
||||
|
||||
static::closeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick Random option from custom select
|
||||
*
|
||||
* @throws \Facebook\WebDriver\Exception\TimeOutException
|
||||
*/
|
||||
public function selectHearAboutUsReason(Browser $browser)
|
||||
{
|
||||
$browser->waitFor('@hear_about_us')
|
||||
->click('@hear_about_us')
|
||||
->waitFor('@hear_about_us_dropdown');
|
||||
$options = $browser->elements('@hear_about_us_option');
|
||||
shuffle($options);
|
||||
$options[0]->click();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function register_with_valid_data()
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit(new Register());
|
||||
$this->selectHearAboutUsReason($browser);
|
||||
$browser->submit([
|
||||
'name' => 'Test User',
|
||||
'email' => 'testuser@test.test',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
])
|
||||
->assertPageIs(Onboarding::class);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function can_not_register_with_the_same_twice()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user) {
|
||||
$browser->visit(new Register());
|
||||
$this->selectHearAboutUsReason($browser);
|
||||
$browser->submit([
|
||||
'name' => 'Test User',
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
])
|
||||
->pause(3000)
|
||||
->assertSee('The email has already been taken.');
|
||||
});
|
||||
}
|
||||
}
|
||||
18
api/tests/Browser/WelcomeTest.php
Normal file
18
api/tests/Browser/WelcomeTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class WelcomeTest extends DuskTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function basic_test()
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/')
|
||||
->waitFor('@title', 1)
|
||||
->assertSee('Forms for Notion');
|
||||
});
|
||||
}
|
||||
}
|
||||
2
api/tests/Browser/console/.gitignore
vendored
Normal file
2
api/tests/Browser/console/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
api/tests/Browser/screenshots/.gitignore
vendored
Normal file
2
api/tests/Browser/screenshots/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
api/tests/Browser/source/.gitignore
vendored
Normal file
2
api/tests/Browser/source/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user