Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Aug 11, 2021
1 parent 5380c45 commit 2362659
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 57 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\" : "tests/"
"PowerComponents\\LivewirePowerGrid\\Tests\\" : "tests/"
}
}
}
40 changes: 28 additions & 12 deletions tests/Feature/PowerGridComponentFilterNameOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;

beforeEach(function () {
$this->component = new PowerGridComponent;
$this->columns = [
'id',
'name'
];
});

it('clean filters', function () {
Expand All @@ -24,13 +27,6 @@

it('properly filters by "name is"', function () {

/*
$pg = new PowerGridComponent();
$filters = $pg->filters;
$model = Dish::query();
*/

$data = new Collection([
new ModelStub([
'id' => '1',
Expand All @@ -51,7 +47,12 @@
]
];

$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::filter($this->component->filters, $data);
$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::query($data)
->setColumns($this->columns)
->setSearch('')
->setFilters($this->component->filters)
->filterContains()
->filter();

$this->assertCount(1,$filtered);
$this->AssertEquals($filtered->first()->name, 'john');
Expand All @@ -78,7 +79,12 @@
]
];

$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::filter($this->component->filters, $data);
$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::query($data)
->setColumns($this->columns)
->setSearch('')
->setFilters($this->component->filters)
->filterContains()
->filter();
$this->assertEmpty($filtered);
});

Expand All @@ -103,7 +109,12 @@
]
];

$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::filter($this->component->filters, $data);
$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::query($data)
->setColumns($this->columns)
->setSearch('')
->setFilters($this->component->filters)
->filterContains()
->filter();

$this->assertCount(1, $filtered);
$this->AssertEquals($filtered->first()->name, 'john smith');
Expand All @@ -130,7 +141,12 @@
]
];

$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::filter($this->component->filters, $data);
$filtered = \PowerComponents\LivewirePowerGrid\Helpers\Collection::query($data)
->setColumns($this->columns)
->setSearch('')
->setFilters($this->component->filters)
->filterContains()
->filter();

$this->assertCount(2, $filtered);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/PowerGridTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace PowerComponents\LivewirePowerGrid\Tests;
namespace PowerComponents\LivewirePowerGrid\Tests\Feature;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Tests\TestCase;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\Tests\TestCase;

class PowerGridTest extends TestCase
{
Expand Down
42 changes: 2 additions & 40 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,9 @@
<?php

use SebastianBergmann\CodeCoverage\Report\Xml\Tests;
use Orchestra\Testbench\TestCase;

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

uses(\Orchestra\Testbench\TestCase::class)->in(__DIR__);

/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
uses(TestCase::class)->in(__DIR__);

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});

/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/

function something()
{
// ..
}
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace Tests;
namespace PowerComponents\LivewirePowerGrid\Tests;

use PowerComponents\LivewirePowerGrid\Providers\PowerGridServiceProvider;

class TestCase extends \Orchestra\Testbench\TestCase
{
protected function getPackageProviders($app)
{

return [
PowerGridServiceProvider::class
];
Expand Down

0 comments on commit 2362659

Please sign in to comment.