Bugfixes based on functional tests (#3338)

* Toggles the disabled state of auto_increment_prefix

To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390

* Delete asset image: made checkbox more visible

Related to #3153

* Added personal-access-token component

* Created basic API testing configuration

* First version of /components endpoind cest

* On-the-fly bearer token generation

* Completed testing of PATCH and PUT methods

* Added /components/{id}/assets route with tests

* Updated route and dataTable in view

* Completed test assertion

* Added links to assets in ComponentsAssets view

* Linked Company in AssetView page

* Bugfixes based on functional tests

* Removed unused function

* Marked tests as incomplete

* Added check for  existence in groups/edit.blade.php
This commit is contained in:
Andrea Bergamasco 2017-02-23 07:49:19 +01:00 committed by snipe
parent ad9470b6f8
commit e7f7d739ed
9 changed files with 49 additions and 27 deletions

View file

@ -173,7 +173,7 @@ class CategoriesController extends Controller
$category->delete(); $category->delete();
// Redirect to the locations management page // Redirect to the locations management page
return redirect()->to('admin/settings/categories')->with('success', trans('admin/categories/message.delete.success')); return redirect()->to(route('categories.index'))->with('success', trans('admin/categories/message.delete.success'));
} }

View file

@ -72,7 +72,7 @@ class GroupsController extends Controller
if ($group->save()) { if ($group->save()) {
return redirect()->route("groups.index")->with('success', trans('admin/groups/message.success.create')); return redirect()->route("groups.index")->with('success', trans('admin/groups/message.success.create'));
} }
return redirect()->back()->withInput()->withErrors($group->getErrors()); return redirect(route('groups.create'))->withInput()->withErrors($group->getErrors());
} }
/** /**

View file

@ -208,21 +208,21 @@ class LocationsController extends Controller
// Check if the location exists // Check if the location exists
if (is_null($location = Location::find($locationId))) { if (is_null($location = Location::find($locationId))) {
// Redirect to the blogs management page // Redirect to the blogs management page
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.not_found')); return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.not_found'));
} }
if ($location->users->count() > 0) { if ($location->users->count() > 0) {
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_users')); return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_users'));
} elseif ($location->childLocations->count() > 0) { } elseif ($location->childLocations->count() > 0) {
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_child_loc')); return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_child_loc'));
} elseif ($location->assets->count() > 0) { } elseif ($location->assets->count() > 0) {
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_assets')); return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_assets'));
} elseif ($location->assignedassets->count() > 0) { } elseif ($location->assignedassets->count() > 0) {
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_assets')); return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_assets'));
} else { } else {
$location->delete(); $location->delete();
return redirect()->to('admin/settings/locations')->with('success', trans('admin/locations/message.delete.success')); return redirect()->to(route('locations.index'))->with('success', trans('admin/locations/message.delete.success'));
} }
} }

View file

@ -4,7 +4,7 @@
'helpTitle' => trans('admin/groups/general.about_groups_title'), 'helpTitle' => trans('admin/groups/general.about_groups_title'),
'helpText' => trans('admin/groups/general.about_groups_text'), 'helpText' => trans('admin/groups/general.about_groups_text'),
'item' => $group, 'item' => $group,
'formAction' => ($group) ? route('groups.update', ['accessory' => $group->id]) : route('groups.store'), 'formAction' => ($group !== null && $group->id !== null) ? route('groups.update', ['accessory' => $group->id]) : route('groups.store'),
]) ])
@section('content') @section('content')

View file

@ -9,14 +9,16 @@ class AccessoriesCest
$I->fillField('username', 'snipeit'); $I->fillField('username', 'snipeit');
$I->fillField('password', 'snipeit'); $I->fillField('password', 'snipeit');
$I->click('Login'); $I->click('Login');
$I->seeAuthentication();
} }
// tests // tests
public function tryToTest(FunctionalTester $I) public function loadsFormWithoutErrors(FunctionalTester $I)
{ {
$I->wantTo('ensure that the create accessories form loads without errors'); $I->wantTo('ensure that the create accessories form loads without errors');
$I->lookForwardTo('seeing it load without errors'); $I->lookForwardTo('seeing it load without errors');
$I->amOnPage('/accessories/create'); $I->amOnPage('/accessories/create');
$I->seeResponseCodeIs(200);
$I->dontSee('Create Accessory', '.page-header'); $I->dontSee('Create Accessory', '.page-header');
$I->see('Create Accessory', 'h1.pull-left'); $I->see('Create Accessory', 'h1.pull-left');
} }
@ -25,6 +27,7 @@ class AccessoriesCest
{ {
$I->wantTo("Test Validation Fails with blank elements"); $I->wantTo("Test Validation Fails with blank elements");
$I->amOnPage('/accessories/create'); $I->amOnPage('/accessories/create');
$I->seeResponseCodeIs(200);
$I->click('Save'); $I->click('Save');
$I->seeElement('.alert-danger'); $I->seeElement('.alert-danger');
$I->see('The name field is required.', '.alert-msg'); $I->see('The name field is required.', '.alert-msg');
@ -36,6 +39,7 @@ class AccessoriesCest
{ {
$I->wantTo("Test Validation Fails with short name"); $I->wantTo("Test Validation Fails with short name");
$I->amOnPage('/accessories/create'); $I->amOnPage('/accessories/create');
$I->seeResponseCodeIs(200);
$I->fillField('name', 't2'); $I->fillField('name', 't2');
$I->fillField('qty', '-15'); $I->fillField('qty', '-15');
$I->fillField('min_amt', '-15'); $I->fillField('min_amt', '-15');
@ -65,6 +69,7 @@ class AccessoriesCest
$I->wantTo("Test Validation Succeeds"); $I->wantTo("Test Validation Succeeds");
$I->amOnPage('/accessories/create'); $I->amOnPage('/accessories/create');
$I->seeResponseCodeIs(200);
$I->submitForm('form#create-form', $values); $I->submitForm('form#create-form', $values);
$I->seeRecord('accessories', $values); $I->seeRecord('accessories', $values);

View file

@ -1,7 +1,7 @@
<?php <?php
class CategoryCest class CategoriesCest
{ {
public function _before(FunctionalTester $I) public function _before(FunctionalTester $I)
{ {
@ -37,7 +37,7 @@ class CategoryCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$category = factory(App\Models\Category::class, 'asset-category')->make(); $category = factory(App\Models\Category::class, 'category')->make();
$values = [ $values = [
'name' => $category->name, 'name' => $category->name,
'category_type' => $category->category_type, 'category_type' => $category->category_type,
@ -55,7 +55,7 @@ class CategoryCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a category'); $I->wantTo('Ensure I can delete a category');
$category = factory(App\Models\Category::class, 'asset-category')->create(); $category = factory(App\Models\Category::class, 'category')->create();
$I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]); $I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -14,11 +14,12 @@ class GroupsCest
} }
// tests // tests
public function tryToTest(FunctionalTester $I) public function loadsFormWithoutErrors(FunctionalTester $I)
{ {
$I->wantTo('ensure that the create groups form loads without errors'); $I->wantTo('ensure that the create groups form loads without errors');
$I->lookForwardTo('seeing it load without errors'); $I->lookForwardTo('seeing it load without errors');
$I->amOnPage(route('create/group')); $I->amOnPage(route('groups.create'));
$I->seeResponseCodeIs(200);
$I->dontSee('Create New Group', '.page-header'); $I->dontSee('Create New Group', '.page-header');
$I->see('Create New Group', 'h1.pull-left'); $I->see('Create New Group', 'h1.pull-left');
} }
@ -26,7 +27,8 @@ class GroupsCest
public function failsEmptyValidation(FunctionalTester $I) public function failsEmptyValidation(FunctionalTester $I)
{ {
$I->wantTo("Test Validation Fails with blank elements"); $I->wantTo("Test Validation Fails with blank elements");
$I->amOnPage(route('create/group')); $I->amOnPage(route('groups.create'));
$I->seeResponseCodeIs(200);
$I->click('Save'); $I->click('Save');
$I->seeElement('.alert-danger'); $I->seeElement('.alert-danger');
$I->see('The name field is required.', '.alert-msg'); $I->see('The name field is required.', '.alert-msg');
@ -35,7 +37,8 @@ class GroupsCest
public function failsShortValidation(FunctionalTester $I) public function failsShortValidation(FunctionalTester $I)
{ {
$I->wantTo("Test Validation Fails with short name"); $I->wantTo("Test Validation Fails with short name");
$I->amOnPage(route('create/group')); $I->amOnPage(route('groups.create'));
$I->seeResponseCodeIs(200);
$I->fillField('name', 't2'); $I->fillField('name', 't2');
$I->click('Save'); $I->click('Save');
$I->seeElement('.alert-danger'); $I->seeElement('.alert-danger');
@ -45,19 +48,37 @@ class GroupsCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$I->wantTo("Test Validation Succeeds"); $I->wantTo("Test Validation Succeeds");
$I->amOnPage(route('create/group')); $I->amOnPage(route('groups.create'));
$I->seeResponseCodeIs(200);
$I->fillField('name', 'TestGroup'); $I->fillField('name', 'TestGroup');
$I->click('Save'); $I->click('Save');
$I->dontSee('&lt;span class=&quot;'); $I->dontSee('&lt;span class=&quot;');
$I->seeElement('.alert-success'); $I->seeElement('.alert-success');
} }
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I, $scenario)
{ {
$I->wantTo("Fix this test to generate a group for deletes"); $scenario->incomplete('Fix this test to generate a group for deletes');
$I->wantTo('Ensure I can delete a group'); $I->wantTo('Ensure I can delete a group');
// $I->amOnPage(route('delete/group', Group::doesntHave('users')->first()->id));
// $I->seeElement('.alert-success'); // create a group
$I->amOnPage(route('groups.create'));
$I->seeResponseCodeIs(200);
$I->fillField('name', 'TestGroup');
$I->click('Save');
$I->dontSee('&lt;span class=&quot;');
$I->seeElement('.alert-success');
// delete it
$I->amOnPage(route('groups.delete', Group::doesntHave('users')->first()->id));
$I->seeResponseCodeIs(200);
$I->seeElement('.alert-success');
// $I->seeResponseCodeIs(200);
} }
public function allowsEditing(FunctionalTester $I, $scenario)
{
$scenario->incomplete('Fix this test to generate a group for editing');
$I->wantTo('Ensure i can edit a group');
}
} }

View file

@ -3,7 +3,7 @@
use App\Models\License; use App\Models\License;
class licensesCest class LicensesCest
{ {
public function _before(FunctionalTester $I) public function _before(FunctionalTester $I)
{ {

View file

@ -1,6 +1,2 @@
<?php <?php
// Here you can initialize variables that will be available to your tests // Here you can initialize variables that will be available to your tests
function _beforeSuite(FunctionalTester $I)
{
echo "Hello";
}