mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Got unit and browser tests working, added documentation
This commit is contained in:
parent
c7d9baad8e
commit
07585809b3
56
TESTING.md
Normal file
56
TESTING.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Using the Test Suite
|
||||
|
||||
This document is targeted at developers looking to make modifications to
|
||||
this application's code base and want to run the existing test suite.
|
||||
|
||||
|
||||
## Setup
|
||||
|
||||
Follow the instructions for installing the application locally,
|
||||
making sure to have also run the [database migrations](link to db migrations).
|
||||
|
||||
|
||||
## Unit Tests
|
||||
|
||||
The application will use values in the `.env.testing` file located
|
||||
in the root directory to override the
|
||||
default settings and/or other values that exist in your `.env` files.
|
||||
|
||||
Make sure to modify the section in `.env.testing` that has the
|
||||
database settings. In the example below, it is connecting to the
|
||||
[MariaDB](link-to-maria-db) server that is used if you install the
|
||||
application using [Docker](https://docker.com).
|
||||
|
||||
```dotenv
|
||||
# --------------------------------------------
|
||||
# REQUIRED: DATABASE SETTINGS
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_DATABASE=snipeit
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=changeme1234
|
||||
```
|
||||
|
||||
To run the entire unit test suite, use the following command from your terminal:
|
||||
|
||||
`php artisan test --env=testing`
|
||||
|
||||
To run individual test files, you can pass the path to the test that
|
||||
you want to run.
|
||||
|
||||
`php artisan test --env=testing tests/Unit/AccessoryTest.php`
|
||||
|
||||
## Browser Tests
|
||||
|
||||
The browser tests use [Dusk](https://laravel.com/docs/8.x/dusk) to run them.
|
||||
When troubleshooting any problems, make sure that your `.env` file is configured
|
||||
correctly to run the existing application.
|
||||
|
||||
To run the test suite use the following command from your terminal:
|
||||
|
||||
`php artisan dusk`
|
||||
|
||||
To run individual test files, you can pass the path to the test that you want to run.
|
||||
|
||||
`php artisan dusk tests/Browser/LoginTest.php`
|
|
@ -26,6 +26,8 @@ services:
|
|||
- .env.docker
|
||||
networks:
|
||||
- snipeit-backend
|
||||
ports:
|
||||
- "3306:3306"
|
||||
|
||||
redis:
|
||||
image: redis:6.2.5-buster
|
||||
|
@ -45,4 +47,4 @@ volumes:
|
|||
db: {}
|
||||
|
||||
networks:
|
||||
snipeit-backend: {}
|
||||
snipeit-backend: {}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
@ -15,37 +16,31 @@ class LoginTest extends DuskTestCase
|
|||
*/
|
||||
public function testLoginPageLoadsAndUserCanLogin()
|
||||
{
|
||||
// Create a new user
|
||||
$user = User::factory()->make();
|
||||
|
||||
// We override the existing password to use a hash of one we know
|
||||
$user->password = '$2y$10$8o5W8fgAKJbN3Kz4taepeeRVgKsG8pkZ1L4eJfdEKrn2mgI/JgCJy';
|
||||
|
||||
// We want a user that is a superuser
|
||||
$user->permissions = '{"superuser": 1}';
|
||||
|
||||
$user->save();
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visitRoute('login')
|
||||
->assertSee(trans('auth/general.login_prompt'));
|
||||
});
|
||||
|
||||
$this->browse(function ($browser) {
|
||||
$this->browse(function ($browser) use ($user) {
|
||||
$browser->visitRoute('login')
|
||||
->type('username', 'snipe')
|
||||
->type('username', $user->username)
|
||||
->type('password', 'password')
|
||||
->press(trans('auth/general.login'))
|
||||
->assertPathIs('/');
|
||||
$browser->screenshot('dashboard');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test dashboard loads
|
||||
*
|
||||
* @todo Flesh this out further to make sure the individual tables actually load with
|
||||
* content inside them.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDashboardLoadsWithSuperAdmin()
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->assertSee(trans('general.dashboard'));
|
||||
$browser->assertSee(trans('general.loading'));
|
||||
$browser->screenshot('dashboard-2');
|
||||
});
|
||||
|
||||
// Delete the user afterwards
|
||||
$user->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ abstract class DuskTestCase extends BaseTestCase
|
|||
})->all());
|
||||
|
||||
return RemoteWebDriver::create(
|
||||
$_ENV['DUSK_DRIVER_URL'] ?? 'http://127.0.0.1:8000',
|
||||
$_ENV['DUSK_DRIVER_URL'] ?? 'http://127.0.0.1:9515',
|
||||
DesiredCapabilities::chrome()->setCapability(
|
||||
ChromeOptions::CAPABILITY, $options
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue