Add tests for creating entities inline

This commit is contained in:
Hillel Coren 2017-03-25 22:01:35 +03:00
parent 5c98c73fde
commit 902cb2a5dc
5 changed files with 31 additions and 12 deletions

View File

@ -73,7 +73,12 @@ class ExpenseDatatable extends EntityDatatable
[
'category',
function ($model) {
return $model->category != null ? substr($model->category, 0, 100) : '';
$category = $model->category != null ? substr($model->category, 0, 100) : '';
if (! Auth::user()->can('editByOwner', [ENTITY_EXPENSE_CATEGORY, $model->category_user_id])) {
return $category;
}
return $model->category_public_id ? link_to("expense_categories/{$model->category_public_id}/edit", $category)->toHtml() : '';
},
],
[

View File

@ -81,6 +81,8 @@ class ExpenseRepository extends BaseRepository
'expenses.tax_rate1',
'expenses.tax_rate2',
'expense_categories.name as category',
'expense_categories.user_id as category_user_id',
'expense_categories.public_id as category_public_id',
'invoices.public_id as invoice_public_id',
'invoices.user_id as invoice_user_id',
'invoices.balance',

View File

@ -49,6 +49,13 @@ class AcceptanceTester extends \Codeception\Actor
$I->click(sprintf('ul.typeahead li[data-value="%s"]', $option));
}
function selectDropdownCreate(\AcceptanceTester $I, $entityType, $value, $entityTypeShort = false)
{
$entityTypeShort = $entityTypeShort ?: $entityType;
$I->fillField("#{$entityType}_name", $value);
$I->click(sprintf('ul.typeahead li[data-value="%s"]', "Create {$entityTypeShort}: \$name"));
}
function selectDropdownRow(\AcceptanceTester $I, $option, $dropdownSelector)
{
$I->click("$dropdownSelector span.dropdown-toggle");

View File

@ -22,17 +22,11 @@ class ExpenseCest
$I->wantTo('Create an expense');
$vendorName = $this->faker->name;
$categoryName = $this->faker->text(20);
$clientName = $this->faker->name;
$clientEmail = $this->faker->safeEmail;
$amount = $this->faker->numberBetween(10, 20);
// create vendor
$I->amOnPage('/vendors/create');
$I->fillField(['name' => 'name'], $vendorName);
$I->click('Save');
$I->see($vendorName);
$vendorId = $I->grabFromDatabase('vendors', 'id', ['name' => $vendorName]);
// create client
$I->amOnPage('/clients/create');
$I->fillField(['name' => 'name'], $clientName);
@ -44,17 +38,24 @@ class ExpenseCest
// create expense
$I->amOnPage('/expenses/create');
$I->fillField(['name' => 'amount'], $amount);
$I->selectDropdown($I, $vendorName, '.vendor-select .dropdown-toggle');
$I->selectDropdownCreate($I, 'vendor', $vendorName);
$I->selectDropdownCreate($I, 'expense_category', $categoryName, 'category');
$I->selectDropdown($I, $clientName, '.client-select .dropdown-toggle');
$I->click('Save');
$I->wait(2);
$I->seeInDatabase('expenses', ['vendor_id' => $vendorId]);
$I->seeInDatabase('expenses', ['client_id' => $clientId]);
$vendorId = $I->grabFromDatabase('vendors', 'id', ['name' => $vendorName]);
$categoryId = $I->grabFromDatabase('expense_categories', 'id', ['name' => $categoryName]);
$I->seeInDatabase('expenses', [
'client_id' => $clientId,
'vendor_id' => $vendorId,
'expense_category_id' => $categoryId
]);
// invoice expense
$I->executeJS('submitAction(\'invoice\')');
$I->wait(2);
$I->click('Save');
$I->click('Save Draft');
$I->wait(2);
$I->see($clientEmail);
$I->see($amount);

View File

@ -19,11 +19,14 @@ class TaskCest
public function createTimerTask(AcceptanceTester $I)
{
$description = $this->faker->text(100);
$project = $this->faker->text(20);
$I->wantTo('create a timed task');
$I->amOnPage('/tasks/create');
$I->seeCurrentUrlEquals('/tasks/create');
$I->selectDropdown($I, 'Wilford Borer', '.client-select .dropdown-toggle');
$I->selectDropdownCreate($I, 'project', $project);
$I->fillField('#description', $description);
$I->click('Start');
@ -32,6 +35,7 @@ class TaskCest
$I->click('Save');
$I->seeInDatabase('tasks', ['description' => $description]);
$I->seeInDatabase('projects', ['name' => $project]);
}
public function createManualTask(AcceptanceTester $I)