Skip to content

Commit 74b547c

Browse files
authored
Third Party Asset Tests (#1341)
* 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]>
1 parent 9ec84f1 commit 74b547c

File tree

7 files changed

+99
-4
lines changed

7 files changed

+99
-4
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
/psalm.xml export-ignore
2323
/psalm.xml.dist export-ignore
2424
/testbench.yaml export-ignore
25+
/codecov.yml export-ignore
26+
/coverage.xml export-ignore

codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: 80%
6+
threshold: 1%
7+
patch:
8+
default:
9+
target: 80%
10+
threshold: 1%

config/livewire-tables.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
'inject_assets' => true,
1414

15+
/**
16+
* Enable or Disable automatic injection of assets
17+
*/
18+
'inject_third_party_assets' => false,
19+
1520
/**
1621
* Enable or Disable inclusion of published third-party assets
1722
*/

src/Features/AutoInjectRappasoftAssets.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public function dehydrate(): void
4646

4747
public static function injectAssets(mixed $html): string
4848
{
49-
$rappasoftTableStyles = RappasoftFrontendAssets::tableStyles();
50-
$rappasoftTableScripts = RappasoftFrontendAssets::tableScripts();
51-
$rappasoftTableThirdPartyStyles = (config('livewire-tables.inject_third_party_assets', true) === false) ? RappasoftFrontendAssets::tableThirdPartyStyles() : '';
49+
$rappasoftTableStyles = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '';
50+
$rappasoftTableScripts = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '';
51+
$rappasoftTableThirdPartyStyles = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : '';
5252
//$rappasoftTableThirdPartyStyles = '';
53-
$rappasoftTableThirdPartyScripts = (config('livewire-tables.inject_third_party_assets', true) !== false) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '';
53+
$rappasoftTableThirdPartyScripts = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '';
5454
//$rappasoftTableThirdPartyScripts = '';
5555

5656
$html = str($html);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Features;
4+
5+
use Rappasoft\LaravelLivewireTables\Features\AutoInjectRappasoftAssets;
6+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
7+
8+
class AutoInjectRappasoftAssetsTest extends TestCase
9+
{
10+
/** @test */
11+
public function shouldInjectRappasoftAndThirdParty()
12+
{
13+
config()->set('livewire-tables.inject_assets', true);
14+
config()->set('livewire-tables.inject_third_party_assets', true);
15+
config()->set('livewire-tables.published_third_party_assets', false);
16+
config()->set('livewire-tables.remote_third_party_assets', false);
17+
$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>'));
18+
}
19+
20+
/** @test */
21+
public function shouldNotInjectRappasoftOrThirdParty()
22+
{
23+
config()->set('livewire-tables.inject_assets', false);
24+
config()->set('livewire-tables.inject_third_party_assets', false);
25+
config()->set('livewire-tables.published_third_party_assets', false);
26+
config()->set('livewire-tables.remote_third_party_assets', false);
27+
$this->assertEquals('<html><head> </head><body></body></html>', AutoInjectRappasoftAssets::injectAssets('<html><head></head><body></body></html>'));
28+
}
29+
30+
/** @test */
31+
public function shouldOnlyInjectThirdParty()
32+
{
33+
config()->set('livewire-tables.inject_assets', false);
34+
config()->set('livewire-tables.inject_third_party_assets', true);
35+
config()->set('livewire-tables.published_third_party_assets', false);
36+
config()->set('livewire-tables.remote_third_party_assets', false);
37+
38+
$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>'));
39+
}
40+
41+
/** @test */
42+
public function shouldOnlyInjectRappasoft()
43+
{
44+
config()->set('livewire-tables.inject_assets', true);
45+
config()->set('livewire-tables.inject_third_party_assets', false);
46+
config()->set('livewire-tables.published_third_party_assets', false);
47+
config()->set('livewire-tables.remote_third_party_assets', false);
48+
49+
$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>'));
50+
}
51+
}

tests/Views/ColumnTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public function can_get_contents_of_column(): void
5757
$this->assertSame('Norwegian Forest', $rows->first()['breed.name']);
5858
}
5959

60+
/** @test */
61+
public function can_get_column_formatted_contents(): void
62+
{
63+
$column = $this->basicTable->getColumnBySelectName('name');
64+
$rows = $this->basicTable->getRows();
65+
66+
$this->assertFalse($column->hasFormatter());
67+
$this->assertNull($column->getFormatCallback());
68+
69+
$column->format(fn ($value) => strtoupper($value));
70+
71+
$this->assertTrue($column->hasFormatter());
72+
$this->assertNotNull($column->getFormatCallback());
73+
74+
$this->assertSame(strtoupper($rows->first()->name), $column->getContents($rows->first()));
75+
}
76+
6077
/** @test */
6178
public function column_table_gets_set_for_base_and_relationship_columns(): void
6279
{

tests/Views/Traits/Helpers/FilterHelpersTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,14 @@ public function can_get_filter_has_default_value_component_level_text(): void
343343
$filter->setFilterDefaultValue('foo');
344344
$this->assertTrue($filter->hasFilterDefaultValue());
345345
}
346+
347+
/** @test */
348+
public function can_get_filter_custom_filter_pills_blade(): void
349+
{
350+
$filter = TextFilter::make('Active');
351+
$this->assertFalse($filter->hasCustomPillBlade());
352+
$filter->setFilterPillBlade('foo');
353+
$this->assertTrue($filter->hasCustomPillBlade());
354+
$this->assertSame('foo', $filter->getCustomPillBlade());
355+
}
346356
}

0 commit comments

Comments
 (0)