Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image component - original width and height #5

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test image width attribute result
  • Loading branch information
lpheller committed Nov 3, 2020
commit 260fc21dcde2bdfca8313e691e633d4485d51d8a
34 changes: 33 additions & 1 deletion tests/Components/ImageComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function test_it_has_alt_from_attribute()
public function it_has_an_image_component_with_a_data_sizes_attribute()
{
$media = $this->getMediaMockWithConversions();

$blade = $this->blade('<x-lit-image :image="$image"/>', ['image' => $media]);
$blade->assertHas('.image-container')->withChild('img');
$blade->assertHas('img')->withAttribute('data-sizes')->thatIs('auto');
Expand Down Expand Up @@ -176,6 +176,38 @@ public function it_has_url_in_src_without_conversions()
->thatIs('image.png');
}

/** @test */
public function it_receives_original_image_width()
{
$image = UploadedFile::fake()->image('image.png', 450);

$media = m::mock(Media::class)->makePartial();
$media->shouldReceive('getPath')->andReturn($image->getRealPath());
$media->shouldReceive('getFullUrl')->andReturn('image.png');

$blade = $this->blade('<x-lit-image :image="$image" width="original" />', ['image' => $media]);

$blade->assertHas('img')
->withAttribute('width')
->thatIs('450');
}

/** @test */
public function it_receives_the_given_image_width()
{
$image = UploadedFile::fake()->image('image.png');

$media = m::mock(Media::class)->makePartial();
$media->shouldReceive('getPath')->andReturn($image->getRealPath());
$media->shouldReceive('getFullUrl')->andReturn('image.png');

$blade = $this->blade('<x-lit-image :image="$image" width="300" />', ['image' => $media]);

$blade->assertHas('img')
->withAttribute('width')
->thatIs('300');
}

public function getMediaMockWithConversions()
{
$this->image = UploadedFile::fake()->image('image.png');
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Blade;
use Illuminate\Http\Testing\FileFactory;
use Intervention\Image\ImageServiceProvider;
use Litstack\Bladesmith\BladesmithServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use BladeStyle\ServiceProvider as BladeStyleServiceProvider;
Expand Down Expand Up @@ -35,6 +36,7 @@ protected function getPackageProviders($app)
BladeStyleServiceProvider::class,
BladeScriptServiceProvider::class,
BladesmithServiceProvider::class,
ImageServiceProvider::class,
];
}

Expand Down