<?php

use Illuminate\Support\Facades\File;

test('homepage renders one gallery tile per configured gallery item', function () {
    $response = $this->get('/');

    $response->assertStatus(200);

    $tileCount = substr_count($response->getContent(), 'gallery-item reveal-scale');

    expect($tileCount)->toBe(count(config('gallery.items')));
});

test('a gallery tile without a photo renders the icon fallback and no image', function () {
    $imagePath = public_path('images/gallery/wedding.jpg');

    expect($imagePath)->not->toBeFile();

    $response = $this->get('/');

    $response->assertStatus(200);
    $response->assertSee('fa-ring', false);
    $response->assertDontSee('Mandap decorated with white and pink roses by Pushpvatika Florist, Surat', false);
});

test('a gallery tile with a photo renders an img with the configured alt text', function () {
    $imagePath = public_path('images/gallery/wedding.jpg');

    File::ensureDirectoryExists(dirname($imagePath));
    File::put($imagePath, 'fake-image-contents');

    try {
        $response = $this->get('/');

        $response->assertStatus(200);
        $response->assertSee('images/gallery/wedding.jpg', false);
        $response->assertSee('alt="Mandap decorated with white and pink roses by Pushpvatika Florist, Surat"', false);
    } finally {
        File::delete($imagePath);
    }
});

test('every configured gallery item has a non-empty title, caption and alt', function () {
    foreach (config('gallery.items') as $item) {
        expect($item['title'])->not->toBeEmpty()
            ->and($item['caption'])->not->toBeEmpty()
            ->and($item['alt'])->not->toBeEmpty();
    }
});
