Skip to content

Commit

Permalink
add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
vonsogt committed Jul 8, 2021
1 parent 566832f commit 97d8ed2
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/dusk": "^6.15",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
Expand Down
141 changes: 140 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions database/factories/CompanyFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Database\Factories;

use App\Models\Company;
use Illuminate\Database\Eloquent\Factories\Factory;

class CompanyFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Company::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'logo' => $this->faker->image('/'),
'website_link' => $this->faker->url(),
];
}
}
16 changes: 16 additions & 0 deletions phpunit.dusk.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Browser Test Suite">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 1 addition & 3 deletions resources/views/partials/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class="nav-link {{ Request::routeIs('admin.home') ? 'active' : '' }}">
<a href="{{ route('logout') }}" class="nav-link"
onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
<i class="nav-icon fas fa-sign-out-alt"></i>
<p>
{{ trans('simplecrm.sign_out') }}
</p>
<p>{{ trans('simplecrm.sign_out') }}</p>
</a>
</li>
</ul>
Expand Down
32 changes: 32 additions & 0 deletions tests/Browser/Auth/LoginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Tests\Browser\Auth;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class LoginTest extends DuskTestCase
{
use DatabaseMigrations;

public function testRegisteredUserCanSignInAndSignOut()
{
$this->browse(function (Browser $browser) {
// Create new user
$user = User::factory()->create([
'email' => 'admin@admin.com'
]);

// Begin test
$browser->visit('/login')
->type('email', $user->email)
->type('password', 'password')
->press(trans('simplecrm.sign_in'))
->click('a[href="' . route('logout') . '"]')
->visit('/admin')
->assertPathIs('/login');
});
}
}
26 changes: 26 additions & 0 deletions tests/Browser/CompanyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Browser;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class CompanyTest extends DuskTestCase
{
use DatabaseMigrations;

public function testIndex()
{
$user = User::factory()->create([
'email' => 'admin@admin.com'
]);

$this->browse(function (Browser $browser) use ($user) {
$browser->loginAs($user)
->visit(route('admin.company.index'))
->assertRouteIs('admin.company.index');
});
}
}
26 changes: 26 additions & 0 deletions tests/Browser/EmployeeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Browser;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class EmployeeTest extends DuskTestCase
{
use DatabaseMigrations;

public function testIndex()
{
$user = User::factory()->create([
'email' => 'admin@admin.com'
]);

$this->browse(function (Browser $browser) use ($user) {
$browser->loginAs($user)
->visit(route('admin.employee.index'))
->assertRouteIs('admin.employee.index');
});
}
}
23 changes: 23 additions & 0 deletions tests/Browser/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* @return void
*/
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}
41 changes: 41 additions & 0 deletions tests/Browser/Pages/HomePage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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.
*
* @param \Laravel\Dusk\Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}

/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}
Loading

0 comments on commit 97d8ed2

Please sign in to comment.