From 902cb2a5dc715db8ec84291aceb833badcfab205 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sat, 25 Mar 2017 22:01:35 +0300 Subject: [PATCH] Add tests for creating entities inline --- app/Ninja/Datatables/ExpenseDatatable.php | 7 +++++- app/Ninja/Repositories/ExpenseRepository.php | 2 ++ tests/_support/AcceptanceTester.php | 7 ++++++ tests/acceptance/ExpenseCest.php | 23 ++++++++++---------- tests/acceptance/TaskCest.php | 4 ++++ 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/Ninja/Datatables/ExpenseDatatable.php b/app/Ninja/Datatables/ExpenseDatatable.php index 1073bef63017..e540a2caa4bc 100644 --- a/app/Ninja/Datatables/ExpenseDatatable.php +++ b/app/Ninja/Datatables/ExpenseDatatable.php @@ -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() : ''; }, ], [ diff --git a/app/Ninja/Repositories/ExpenseRepository.php b/app/Ninja/Repositories/ExpenseRepository.php index 20077584e4a2..93a6ae33d9c8 100644 --- a/app/Ninja/Repositories/ExpenseRepository.php +++ b/app/Ninja/Repositories/ExpenseRepository.php @@ -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', diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 4ce2397bb6e6..5f821119b8f5 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -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"); diff --git a/tests/acceptance/ExpenseCest.php b/tests/acceptance/ExpenseCest.php index d7756ed3a070..b136f4a6cad8 100644 --- a/tests/acceptance/ExpenseCest.php +++ b/tests/acceptance/ExpenseCest.php @@ -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); diff --git a/tests/acceptance/TaskCest.php b/tests/acceptance/TaskCest.php index 9deca9a0aaaa..1b7de334363c 100644 --- a/tests/acceptance/TaskCest.php +++ b/tests/acceptance/TaskCest.php @@ -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)