diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..de89d8f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + tests: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [8.2, 8.1, 8.0] + laravel: [10, 9] + stability: [prefer-stable] + include: + - laravel: 10 + testbench: ^8.0 + - laravel: 9 + testbench: ^7.0 + exclude: + - php: 8.0 + laravel: 10 + + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip + coverage: none + + - name: Install dependencies + run: | + composer require "illuminate/contracts=^${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --prefer-dist --no-interaction --no-update + composer update --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/pest diff --git a/composer.json b/composer.json index 5449575..0fb9995 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,11 @@ ], "require": { "php": "^7.4|^8.0", - "spatie/laravel-package-tools": "^1.1", "illuminate/contracts": "^8.0|^9.0|^10.0" }, "require-dev": { - "orchestra/testbench": "^6.0|^7.0", + "orchestra/testbench": "^6.0|^7.0|^8.0", + "pestphp/pest": "^1.23", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", @@ -62,7 +62,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "pestphp/pest-plugin": true } }, "extra": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..318c570 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,12 @@ + + + + + tests + + + diff --git a/resources/views/components/input/uppy/ui.blade.php b/resources/views/components/input/uppy/ui.blade.php index d334825..4de7e80 100644 --- a/resources/views/components/input/uppy/ui.blade.php +++ b/resources/views/components/input/uppy/ui.blade.php @@ -1,7 +1,7 @@ @aware([ 'instanceName' => 'uppyUpload', 'uiOptions' => '{}', - 'ui' => '', + 'ui' => 'dashboard', ]) {{ $instanceName }}.use({{ Str::of($ui)->camel()->ucfirst() }}, {{ $uiOptions }}); diff --git a/tests/Components/S3MultipartTest.php b/tests/Components/S3MultipartTest.php new file mode 100644 index 0000000..56e1fa8 --- /dev/null +++ b/tests/Components/S3MultipartTest.php @@ -0,0 +1,129 @@ +blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Dashboard'); + $view->assertSee('.use(AwsS3Multipart'); +}); + +it('can pass ui and ui options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(DragDrop, { inline: true, target:'); +}); + +it('can pass the uppy instance name to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('testinstance.use(Dashboard,'); +}); + +it('can pass core options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('const uppyUpload = new Uppy({ debug: true });'); +}); + +it('can pass uploader options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('.use(AwsS3Multipart, { id: s3multiparttest, limit: 10 });'); +}); + +it('can pass events to component', function() { + $view = $this->blade( + '@php + $events = [ + "file-added" => " + console.log(file); + ", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('console.log(file);'); +}); + +it('can pass plugins to component', function() { + $view = $this->blade( + '@php + $plugins = [ + "ThumbnailGenerator" => "{ thumbnailWidth: 300, ThumbnailHeight: 300 }", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('uppyUpload.use(ThumbnailGenerator, { thumbnailWidth: 300, ThumbnailHeight: 300 });'); +}); + +it('can pass extra javascript code to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee("console.log"); +}); diff --git a/tests/Components/S3Test.php b/tests/Components/S3Test.php new file mode 100644 index 0000000..a2b0dfc --- /dev/null +++ b/tests/Components/S3Test.php @@ -0,0 +1,129 @@ +blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Dashboard'); + $view->assertSee('.use(AwsS3'); +}); + +it('can pass ui and ui options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(DragDrop, { inline: true, target:'); +}); + +it('can pass the uppy instance name to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('testinstance.use(Dashboard,'); +}); + +it('can pass core options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('const uppyUpload = new Uppy({ debug: true });'); +}); + +it('can pass uploader options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('.use(AwsS3, { id: s3test, limit: 10, timeout: 40_000 });'); +}); + +it('can pass events to component', function() { + $view = $this->blade( + '@php + $events = [ + "file-added" => " + console.log(file); + ", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('console.log(file);'); +}); + +it('can pass plugins to component', function() { + $view = $this->blade( + '@php + $plugins = [ + "ThumbnailGenerator" => "{ thumbnailWidth: 300, ThumbnailHeight: 300 }", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('uppyUpload.use(ThumbnailGenerator, { thumbnailWidth: 300, ThumbnailHeight: 300 });'); +}); + +it('can pass extra javascript code to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee("console.log"); +}); diff --git a/tests/Components/TransloaditTest.php b/tests/Components/TransloaditTest.php new file mode 100644 index 0000000..422f38e --- /dev/null +++ b/tests/Components/TransloaditTest.php @@ -0,0 +1,129 @@ +blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Dashboard'); + $view->assertSee('.use(Transloadit,'); +}); + +it('can pass ui and ui options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(DragDrop, { inline: true, target:'); +}); + +it('can pass the uppy instance name to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('testinstance.use(Dashboard,'); +}); + +it('can pass core options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('const uppyUpload = new Uppy({ debug: true });'); +}); + +it('can pass uploader options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('.use(Transloadit, { id: transloadittest, limit: 10, waitForEncoding: true'); +}); + +it('can pass events to component', function() { + $view = $this->blade( + '@php + $events = [ + "file-added" => " + console.log(file); + ", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('console.log(file);'); +}); + +it('can pass plugins to component', function() { + $view = $this->blade( + '@php + $plugins = [ + "Compressor" => "{ quality: 0.6 }", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Compressor, { quality: 0.6 });'); +}); + +it('can pass extra javascript code to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee("console.log"); +}); diff --git a/tests/Components/TusTest.php b/tests/Components/TusTest.php new file mode 100644 index 0000000..0e52b3f --- /dev/null +++ b/tests/Components/TusTest.php @@ -0,0 +1,129 @@ +blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Dashboard'); + $view->assertSee('.use(Tus,'); +}); + +it('can pass ui and ui options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(DragDrop, { inline: true, target:'); +}); + +it('can pass the uppy instance name to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('testinstance.use(Dashboard,'); +}); + +it('can pass core options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('const uppyUpload = new Uppy({ debug: true });'); +}); + +it('can pass uploader options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('.use(Tus, { id: tustest, withCredentials: true'); +}); + +it('can pass events to component', function() { + $view = $this->blade( + '@php + $events = [ + "file-added" => " + console.log(file); + ", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('console.log(file);'); +}); + +it('can pass plugins to component', function() { + $view = $this->blade( + '@php + $plugins = [ + "Compressor" => "{ quality: 0.6 }", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Compressor, { quality: 0.6 });'); +}); + +it('can pass extra javascript code to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee("console.log"); +}); diff --git a/tests/Components/XhrTest.php b/tests/Components/XhrTest.php new file mode 100644 index 0000000..dbb673a --- /dev/null +++ b/tests/Components/XhrTest.php @@ -0,0 +1,129 @@ +blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Dashboard'); + $view->assertSee('.use(XHR,'); +}); + +it('can pass ui and ui options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('uppyUpload.use(DragDrop, { inline: true, target:'); +}); + +it('can pass the uppy instance name to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('testinstance.use(Dashboard,'); +}); + +it('can pass core options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('const uppyUpload = new Uppy({ debug: true });'); +}); + +it('can pass uploader options to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee('.use(XHR, { id: xhrtest, method:'); +}); + +it('can pass events to component', function() { + $view = $this->blade( + '@php + $events = [ + "file-added" => " + console.log(file); + ", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('console.log(file);'); +}); + +it('can pass plugins to component', function() { + $view = $this->blade( + '@php + $plugins = [ + "Compressor" => "{ quality: 0.6 }", + ]; + @endphp + + +
+
+
' + ); + + $view->assertSee('uppyUpload.use(Compressor, { quality: 0.6 });'); +}); + +it('can pass extra javascript code to component', function() { + $view = $this->blade( + ' +
+
+
' + ); + + $view->assertSee("console.log"); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..39393c5 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +in('Components'); + +/* +|-------------------------------------------------------------------------- +| Test Case +|-------------------------------------------------------------------------- +| +| The closure you provide to your test functions is always bound to a specific PHPUnit test +| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may +| need to change it using the "uses()" function to bind a different classes or traits. +| +*/ + +/** @link https://pestphp.com/docs/configuring-tests */ + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +/** @link https://pestphp.com/docs/custom-expectations */ + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +/** @link https://pestphp.com/docs/custom-helpers */ diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..7ac3c7e --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,16 @@ +