Skip to content

Commit

Permalink
feat(tests): add some ai generated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-infernal committed Aug 22, 2023
1 parent bb0f19d commit dedc8db
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -28,7 +28,7 @@
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest": "^2.16",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

20 changes: 20 additions & 0 deletions tests/ResponsiveImageCraftTest.php
@@ -0,0 +1,20 @@
<?php

use Illuminate\Support\Facades\Config;
use Infernalmedia\ResponsiveImageCraft\Exceptions\InvalidDiskException;
use Infernalmedia\ResponsiveImageCraft\ResponsiveImageCraft;

test('it throws an exception if URL is missing', function () {
Config::set('responsive-image-craft.use_responsive_images', true);
Config::set('responsive-image-craft.source_disk', 'local');
Config::set('filesystems.disks.local.url', null);

$responsiveImageCraft = new ResponsiveImageCraft();

$maxWidth = 800;
$extensions = ['jpg', 'webp'];

$this->expectException(InvalidDiskException::class);

$responsiveImageCraft->getCssVariables('image.jpg', $maxWidth, $extensions);
});
47 changes: 47 additions & 0 deletions tests/ResponsiveImgTest.php
@@ -0,0 +1,47 @@
<?php

use Infernalmedia\ResponsiveImageCraft\View\Components\ResponsiveImg;

it('can be created with minimum required attributes', function () {
$component = new ResponsiveImg('image.jpg');
expect($component)->toBeInstanceOf(ResponsiveImg::class);
});

it('can get the container CSS class', function () {
$component = new ResponsiveImg(src: 'image.jpg');

$this->assertSame('img-container', $component->getContainerCssClass());

$component = new ResponsiveImg(src: 'image.jpg', containerClass: 'custom-class');

$this->assertSame('img-container custom-class', $component->getContainerCssClass());
});

it('can get the image type', function () {
$component = new ResponsiveImg('image.jpg');

$this->assertSame('image/jpeg', $component->getImageType('jpg'));
$this->assertSame('', $component->getImageType('invalid-extension'));
});

it('jpg returns an array of filtered extensions without png', function () {
$component = new ResponsiveImg(
src: 'image.jpg',
);

$filteredExtensions = $component->getFilteredExtensions();

expect($filteredExtensions)->toContain('webp');
expect($filteredExtensions)->not->toContain('png');
});

it('png returns an array of filtered extensions without jpg', function () {
$component = new ResponsiveImg(
src: 'image.png',
);

$filteredExtensions = $component->getFilteredExtensions();

expect($filteredExtensions)->toContain('webp');
expect($filteredExtensions)->not->toContain('jpg');
});

0 comments on commit dedc8db

Please sign in to comment.