Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dusk #15422

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@
"brianium/paratest": "^7.0",
"fakerphp/faker": "^1.16",
"larastan/larastan": "^2.9",
"laravel/dusk": "^8.2",
"mockery/mockery": "^1.4",
"nunomaduro/phpinsights": "^2.11",
"php-mock/php-mock-phpunit": "^2.10",
"phpunit/phpunit": "^10.0",
"roquie/laravel-dusk-select2": "^2.1",
"squizlabs/php_codesniffer": "^3.5",
"symfony/css-selector": "^4.4",
"symfony/dom-crawler": "^4.4",
Expand Down
183 changes: 182 additions & 1 deletion composer.lock

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

4 changes: 2 additions & 2 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<a class="skip-main" href="#main">{{ trans('general.skip_to_main_content') }}</a>
<div class="wrapper">

<header class="main-header">
<header class="main-header" dusk="main-header">

<!-- Logo -->

Expand Down Expand Up @@ -819,7 +819,7 @@

<!-- Content Header (Page header) -->
<section class="content-header" style="padding-bottom: 30px;">
<h1 class="pull-left pagetitle">@yield('title') </h1>
<h1 class="pull-left pagetitle" dusk="pagetitle">@yield('title') </h1>

@if (isset($helpText))
@include ('partials.more-info',
Expand Down
47 changes: 47 additions & 0 deletions tests/Browser/CreateAssetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use App\Models\User;
use App\Models\Asset;
use Illuminate\Support\Facades\Hash;

class CreateAssetTest extends DuskTestCase
{

public function testUserCanCreateAnAsset(): void
{
$asset = Asset::factory()->make([
]);

$user = User::factory()->createAssets()->create([
'password' => Hash::make('password'),
]);

$this->browse(function (Browser $browser) use ($user, $asset) {
$browser->logout();

$browser->visit('/login')
->type('username', $user->username)
->type('password', 'password')
->press('Login')
->visit('/hardware/create')
->type('asset_tags[1]', $asset->asset_tag)
->select2('#model_select_id', 'Macbook')
->waitForText('Macbook Pro')
->click('label:first-child') // close the previous select
->select2('#status_select_id')
->waitForText('Ready to Deploy')
->click('label:first-child') // close the previous select
->press('Save')
->assertPresent('.alert-success')
->assertNotPresent('.alert-msg');

$browser->logout();
});
}

}
73 changes: 73 additions & 0 deletions tests/Browser/LoginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Tests\Browser;

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

class LoginTest extends DuskTestCase
{
/**
* A Dusk test example.
*/
public function testUserCanLoadLoginPage(): void
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Login');
});
}

/**
* A basic browser test example.
*/
public function testUserCanLoginAndSeeDashboard(): void
{
$user = User::factory()->superuser()->create([
'username' => 'admin',
'password' => Hash::make('password'),
]);

$this->browse(function (Browser $browser) use ($user) {
$browser->logout();

$browser->visit('/login')
->type('username', $user->username)
->type('password', 'password')
->press('Login')
->assertPathIs('/')
->assertSeeIn('.pagetitle', 'Dashboard')
->assertSeeIn('.alert-success', 'Success')
->assertNotPresent('.alert-danger');

$browser->logout();
});


}

/**
* A basic browser test example.
*/
public function testRegularUserCanLoginAndSeeProfile(): void
{
$user = User::factory()->create([
'password' => Hash::make('password'),
]);

$this->browse(function (Browser $browser) use ($user) {
$browser->logout()
->visit('/login')
->type('username', $user->username)
->type('password', 'password')
->press('Login')
->assertPathIs('/account/view-assets')
->assertSeeIn('.pagetitle', 'Hello')
->assertNotPresent('.alert-danger')
->logout();
});
}
}
Loading
Loading