Skip to content

Commit

Permalink
Third Party Asset Tests (#1341)
Browse files Browse the repository at this point in the history
* Add NonArray setAdditionalSelects Test

* Update for FrontendAssets Test

* Add ThirdPartyScripts/Styles to Test

* Add ThirdParty Tests

* Fix AutoInjection Issue

* Fix 3rd party test

* Set default back to remote 3rd party assets

* Add CodeCov YML

* Update CodeCov - 80% minimum

* Add Filter Custom Pills Blade Test

* Fix styling

* Add formatted column test

* Column - Get Formatted Contents Test

* Fix styling

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Sep 4, 2023
1 parent 9ec84f1 commit 74b547c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
/testbench.yaml export-ignore
/codecov.yml export-ignore
/coverage.xml export-ignore
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 80%
threshold: 1%
patch:
default:
target: 80%
threshold: 1%
5 changes: 5 additions & 0 deletions config/livewire-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
'inject_assets' => true,

/**
* Enable or Disable automatic injection of assets
*/
'inject_third_party_assets' => false,

Check warning on line 18 in config/livewire-tables.php

View check run for this annotation

Codecov / codecov/patch

config/livewire-tables.php#L18

Added line #L18 was not covered by tests

/**
* Enable or Disable inclusion of published third-party assets
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Features/AutoInjectRappasoftAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public function dehydrate(): void

public static function injectAssets(mixed $html): string
{
$rappasoftTableStyles = RappasoftFrontendAssets::tableStyles();
$rappasoftTableScripts = RappasoftFrontendAssets::tableScripts();
$rappasoftTableThirdPartyStyles = (config('livewire-tables.inject_third_party_assets', true) === false) ? RappasoftFrontendAssets::tableThirdPartyStyles() : '';
$rappasoftTableStyles = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '';
$rappasoftTableScripts = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '';
$rappasoftTableThirdPartyStyles = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : '';
//$rappasoftTableThirdPartyStyles = '';
$rappasoftTableThirdPartyScripts = (config('livewire-tables.inject_third_party_assets', true) !== false) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '';
$rappasoftTableThirdPartyScripts = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '';
//$rappasoftTableThirdPartyScripts = '';

$html = str($html);
Expand Down
51 changes: 51 additions & 0 deletions tests/Features/AutoInjectRappasoftAssetsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Features;

use Rappasoft\LaravelLivewireTables\Features\AutoInjectRappasoftAssets;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

class AutoInjectRappasoftAssetsTest extends TestCase
{
/** @test */
public function shouldInjectRappasoftAndThirdParty()
{
config()->set('livewire-tables.inject_assets', true);
config()->set('livewire-tables.inject_third_party_assets', true);
config()->set('livewire-tables.published_third_party_assets', false);
config()->set('livewire-tables.remote_third_party_assets', false);
$this->assertEquals('<html><head> <link href="/rappasoft/laravel-livewire-tables/core.min.css" rel="stylesheet" /> <link href="/rappasoft/laravel-livewire-tables/thirdparty.css" rel="stylesheet" /><script src="/rappasoft/laravel-livewire-tables/core.min.js" ></script> <script src="/rappasoft/laravel-livewire-tables/thirdparty.min.js" type="module" ></script></head><body></body></html>', AutoInjectRappasoftAssets::injectAssets('<html><head></head><body></body></html>'));
}

/** @test */
public function shouldNotInjectRappasoftOrThirdParty()
{
config()->set('livewire-tables.inject_assets', false);
config()->set('livewire-tables.inject_third_party_assets', false);
config()->set('livewire-tables.published_third_party_assets', false);
config()->set('livewire-tables.remote_third_party_assets', false);
$this->assertEquals('<html><head> </head><body></body></html>', AutoInjectRappasoftAssets::injectAssets('<html><head></head><body></body></html>'));
}

/** @test */
public function shouldOnlyInjectThirdParty()
{
config()->set('livewire-tables.inject_assets', false);
config()->set('livewire-tables.inject_third_party_assets', true);
config()->set('livewire-tables.published_third_party_assets', false);
config()->set('livewire-tables.remote_third_party_assets', false);

$this->assertEquals('<html><head> <link href="/rappasoft/laravel-livewire-tables/thirdparty.css" rel="stylesheet" /> <script src="/rappasoft/laravel-livewire-tables/thirdparty.min.js" type="module" ></script></head><body></body></html>', AutoInjectRappasoftAssets::injectAssets('<html><head></head><body></body></html>'));
}

/** @test */
public function shouldOnlyInjectRappasoft()
{
config()->set('livewire-tables.inject_assets', true);
config()->set('livewire-tables.inject_third_party_assets', false);
config()->set('livewire-tables.published_third_party_assets', false);
config()->set('livewire-tables.remote_third_party_assets', false);

$this->assertEquals('<html><head> <link href="/rappasoft/laravel-livewire-tables/core.min.css" rel="stylesheet" /> <script src="/rappasoft/laravel-livewire-tables/core.min.js" ></script> </head><body></body></html>', AutoInjectRappasoftAssets::injectAssets('<html><head></head><body></body></html>'));
}
}
17 changes: 17 additions & 0 deletions tests/Views/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ public function can_get_contents_of_column(): void
$this->assertSame('Norwegian Forest', $rows->first()['breed.name']);
}

/** @test */
public function can_get_column_formatted_contents(): void
{
$column = $this->basicTable->getColumnBySelectName('name');
$rows = $this->basicTable->getRows();

$this->assertFalse($column->hasFormatter());
$this->assertNull($column->getFormatCallback());

$column->format(fn ($value) => strtoupper($value));

$this->assertTrue($column->hasFormatter());
$this->assertNotNull($column->getFormatCallback());

$this->assertSame(strtoupper($rows->first()->name), $column->getContents($rows->first()));
}

/** @test */
public function column_table_gets_set_for_base_and_relationship_columns(): void
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Views/Traits/Helpers/FilterHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,14 @@ public function can_get_filter_has_default_value_component_level_text(): void
$filter->setFilterDefaultValue('foo');
$this->assertTrue($filter->hasFilterDefaultValue());
}

/** @test */
public function can_get_filter_custom_filter_pills_blade(): void
{
$filter = TextFilter::make('Active');
$this->assertFalse($filter->hasCustomPillBlade());
$filter->setFilterPillBlade('foo');
$this->assertTrue($filter->hasCustomPillBlade());
$this->assertSame('foo', $filter->getCustomPillBlade());
}
}

0 comments on commit 74b547c

Please sign in to comment.