From d700b3b5772022902948430d076fc3c0a00f20ef Mon Sep 17 00:00:00 2001 From: Sam Light Date: Mon, 31 Mar 2025 22:08:20 +0100 Subject: Changes to Assets class manifest function --- tests/Feature/AssetsTest.php | 62 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/Feature/AssetsTest.php b/tests/Feature/AssetsTest.php index 7850081..f618d46 100644 --- a/tests/Feature/AssetsTest.php +++ b/tests/Feature/AssetsTest.php @@ -2,6 +2,7 @@ use Lightscale\LaralightAssets\Assets; use Lightscale\LaralightAssets\Manifest; +use Lightscale\LaralightAssets\FileString; describe('instance', function() { it('instantiates', function() { @@ -17,16 +18,14 @@ describe('instance', function() { }); }); -describe('manages manifests', function() { - it('adds manifests', function() { - app(Assets::class)->addManifest( - 'main', - new Manifest( - public_path('dist/manifest.json'), - '/dist', - ), - isDefault: true, - ); +$newManifest = fn() => new Manifest( + public_path('dist/manifest.json'), + '/dist', +); + +describe('manages manifests', function() use ($newManifest) { + it('adds manifests', function() use ($newManifest) { + app(Assets::class)->addManifest('main', $newManifest(), isDefault: true); })->throwsNoExceptions(); it('registers manifests', function() { @@ -46,24 +45,18 @@ describe('manages manifests', function() { ->toContainOnlyInstancesOf(Manifest::class); }); - it('gets manifest', function() { + it('gets manifest', function() use ($newManifest){ $assets = app(Assets::class); - $manifest = new Manifest( - public_path('dist/manifest.json'), - '/dist', - ); + $manifest = $newManifest(); $name = 'main'; $assets->addManifest($name, $manifest, true); expect($assets->getManifest($name))->toBe($manifest); }); - it('gets default manifest', function() { + it('gets default manifest', function() use ($newManifest) { $assets = app(Assets::class); - $manifest = new Manifest( - public_path('dist/manifest.json'), - '/dist', - ); + $manifest = $newManifest(); $name = 'main'; $assets->addManifest($name, $manifest, true); @@ -75,8 +68,31 @@ describe('manages manifests', function() { $assets->getManifest('main'); })->throws(Exception::class); - it('throws exception without default', function() { + it('has null default manifest') + ->expect(fn() => app(Assets::class)->getDefaultManifest()) + ->toBeNull(); + + it('throws exception setting default to missing manifest', function() { $assets = app(Assets::class); - $assets->getDefaultManifest(); - })->throws(Error::class); + $assets->setDefaultManifest('testing'); + })->throws(Exception::class); + + test('get manifest from FileString', function() use($newManifest) { + $assets = app(Assets::class); + $manifest = $newManifest(); + $assets->addManifest('main', $manifest, true); + $file = new FileString('main::test.css'); + $result = $assets->getFileManifest($file); + expect($result)->toBe($manifest); + }); + + test('default manifest from FileString', function() use($newManifest) { + $assets = app(Assets::class); + $manifest = $newManifest(); + $assets->addManifest('main', $manifest, true); + $file = new FileString('test.css'); + $result = $assets->getFileManifest($file); + expect($result)->toBe($manifest); + }); + }); -- cgit v1.2.3