From 74b547c0f3be3c0aaa4f53c1013b26d693800c88 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:27:52 +0100 Subject: [PATCH] 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 --- .gitattributes | 2 + codecov.yml | 10 ++++ config/livewire-tables.php | 5 ++ src/Features/AutoInjectRappasoftAssets.php | 8 +-- .../AutoInjectRappasoftAssetsTest.php | 51 +++++++++++++++++++ tests/Views/ColumnTest.php | 17 +++++++ .../Traits/Helpers/FilterHelpersTest.php | 10 ++++ 7 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 codecov.yml create mode 100644 tests/Features/AutoInjectRappasoftAssetsTest.php diff --git a/.gitattributes b/.gitattributes index 2abcda003..62fd9d5f7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..3491d5a70 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,10 @@ +coverage: + status: + project: + default: + target: 80% + threshold: 1% + patch: + default: + target: 80% + threshold: 1% diff --git a/config/livewire-tables.php b/config/livewire-tables.php index a563c87c7..3161f9280 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -12,6 +12,11 @@ */ 'inject_assets' => true, + /** + * Enable or Disable automatic injection of assets + */ + 'inject_third_party_assets' => false, + /** * Enable or Disable inclusion of published third-party assets */ diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 481423260..5e5d0f35c 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -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); diff --git a/tests/Features/AutoInjectRappasoftAssetsTest.php b/tests/Features/AutoInjectRappasoftAssetsTest.php new file mode 100644 index 000000000..61b306bfe --- /dev/null +++ b/tests/Features/AutoInjectRappasoftAssetsTest.php @@ -0,0 +1,51 @@ +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(' ', AutoInjectRappasoftAssets::injectAssets('')); + } + + /** @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(' ', AutoInjectRappasoftAssets::injectAssets('')); + } + + /** @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(' ', AutoInjectRappasoftAssets::injectAssets('')); + } + + /** @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(' ', AutoInjectRappasoftAssets::injectAssets('')); + } +} diff --git a/tests/Views/ColumnTest.php b/tests/Views/ColumnTest.php index 79bc0bec2..58b713c61 100644 --- a/tests/Views/ColumnTest.php +++ b/tests/Views/ColumnTest.php @@ -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 { diff --git a/tests/Views/Traits/Helpers/FilterHelpersTest.php b/tests/Views/Traits/Helpers/FilterHelpersTest.php index 6b8f733ab..e8469935b 100644 --- a/tests/Views/Traits/Helpers/FilterHelpersTest.php +++ b/tests/Views/Traits/Helpers/FilterHelpersTest.php @@ -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()); + } }