From 3d91db66d05f2f226d3d64d1479fc6a5513a0793 Mon Sep 17 00:00:00 2001
From: Sam Light <sam@lightscale.co.uk>
Date: Mon, 31 Mar 2025 00:50:18 +0100
Subject: Assets testing

---
 tests/Feature/AssetsTest.php | 78 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 tests/Feature/AssetsTest.php

(limited to 'tests/Feature/AssetsTest.php')

diff --git a/tests/Feature/AssetsTest.php b/tests/Feature/AssetsTest.php
new file mode 100644
index 0000000..887142c
--- /dev/null
+++ b/tests/Feature/AssetsTest.php
@@ -0,0 +1,78 @@
+<?php
+
+use Lightscale\LaralightAssets\Assets;
+use Lightscale\LaralightAssets\Manifest;
+
+it('instantiates', function() {
+    new Assets();
+})->throwsNoExceptions();
+
+it('instantiates from container', function() {
+    app(Assets::class);
+})->throwsNoExceptions();
+
+it('is singleton', function() {
+    expect(app(Assets::class))->toBe(app(Assets::class));
+});
+
+it('adds manifests', function() {
+    app(Assets::class)->addManifest(
+        'main',
+        new Manifest(
+            public_path('dist/manifest.json'),
+            '/dist',
+        ),
+        isDefault: true,
+    );
+})->throwsNoExceptions();
+
+it('registers manifests', function() {
+    app(Assets::class)->registerManifest(
+        'main', public_path('dist/manifest.json'), '/dist', isDefault: true,
+    );
+})->throwsNoExceptions();
+
+it('gets manifests', function() {
+    $assets = app(Assets::class);
+    $assets->registerManifest(
+        'main', public_path('dist/manifest.json'), '/dist', isDefault: true,
+    );
+
+    expect($assets->getManifests())
+        ->toHaveLength(1)
+        ->toContainOnlyInstancesOf(Manifest::class);
+});
+
+it('gets manifest', function() {
+    $assets = app(Assets::class);
+    $manifest = new Manifest(
+        public_path('dist/manifest.json'),
+        '/dist',
+    );
+    $name = 'main';
+    $assets->addManifest($name, $manifest, true);
+
+    expect($assets->getManifest($name))->toBe($manifest);
+});
+
+it('gets default manifest', function() {
+    $assets = app(Assets::class);
+    $manifest = new Manifest(
+        public_path('dist/manifest.json'),
+        '/dist',
+    );
+    $name = 'main';
+    $assets->addManifest($name, $manifest, true);
+
+    expect($assets->getDefaultManifest())->toBe($manifest);
+});
+
+it('throws exception missing manifest', function() {
+    $assets = app(Assets::class);
+    $assets->getManifest('main');
+})->throws(Exception::class);
+
+it('throws exception without default', function() {
+    $assets = app(Assets::class);
+    $assets->getDefaultManifest();
+})->throws(Error::class);
-- 
cgit v1.2.3