<?php

namespace Tests\Unit;

use App\Models\GeneralSetting;
use PHPUnit\Framework\TestCase;

class GeneralSettingSeoTrackingNormalizationTest extends TestCase
{
    public function test_google_analytics_id_can_be_extracted_from_full_snippet(): void
    {
        $value = '<script async src="https://www.googletagmanager.com/gtag/js?id=G-AB12CD34EF"></script>';

        $this->assertSame('G-AB12CD34EF', GeneralSetting::normalizeGoogleAnalyticsId($value));
    }

    public function test_google_tag_manager_id_can_be_extracted_from_full_snippet(): void
    {
        $value = '<script>https://www.googletagmanager.com/gtm.js?id=GTM-ABC1234</script>';

        $this->assertSame('GTM-ABC1234', GeneralSetting::normalizeGoogleTagManagerId($value));
    }

    public function test_facebook_pixel_id_can_be_extracted_from_init_call(): void
    {
        $value = "fbq('init', '123456789012345'); fbq('track', 'PageView');";

        $this->assertSame('123456789012345', GeneralSetting::normalizeFacebookPixelId($value));
    }

    public function test_social_profile_links_are_unique_and_trimmed(): void
    {
        $settings = new GeneralSetting([
            'facebook_link' => ' https://facebook.com/example ',
            'youtube_link' => 'https://youtube.com/@example',
            'whatsapp_link' => 'https://wa.me/8801000000000',
            'telegram_link' => 'https://facebook.com/example',
        ]);

        $this->assertSame([
            'https://facebook.com/example',
            'https://youtube.com/@example',
            'https://wa.me/8801000000000',
        ], GeneralSetting::socialProfileLinks($settings));
    }
}
