Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

4.0 KB
Raw Blame
<?php

declare(strict_types=1);

use App\Enums\User\Goal;
use App\Enums\User\Persona;
use App\Enums\User\PreviousSoftware;
use App\Enums\User\ReferralSource;
use App\Models\Post;
use App\Models\User;
use App\Models\Workspace;

/**
 * Guards against horizontal overflow on mobile across the layout variants
 * (AuthLayout, default AppLayout, full-width editor).
 * Reproduces the AuthSplitLayout long-name overflow that a fixed grid column
 * caused. Returns the widest offending element on failure for quick triage.
 */
function assertNoHorizontalOverflow(mixed $page, string $label): void
{
    waitForState($page, 'h1, h2, main, [data-sidebar="trigger"]', 'true');

    $result = $page->script(<<<'JS'
        (async () => {
            await new Promise((r) => setTimeout(r, 400));
            const vw = window.innerWidth;
            let worst = null;
            document.querySelectorAll('*').forEach((el) => {
                const r = el.getBoundingClientRect();
                if (r.right > vw + 2 && (!worst || r.right > worst.right)) {
                    worst = { right: Math.round(r.right), tag: el.tagName.toLowerCase(), cls: (el.getAttribute('class') || '').slice(0, 80) };
                }
            });
            return { sw: document.documentElement.scrollWidth, iw: vw, worst };
        })()
    JS);

    $sw = (int) ($result['sw'] ?? 0);
    $iw = (int) ($result['iw'] ?? 375);
    $worst = $result['worst'] ?? null;
    $detail = $worst ? " widest: <{$worst['tag']} class=\"{$worst['cls']}\"> right={$worst['right']}" : '';

    expect($sw - $iw)->toBeLessThanOrEqual(2, "{$label} overflows: scrollWidth {$sw} > innerWidth {$iw}.{$detail}");
}

test('key pages do not overflow horizontally on a phone', function () {
    $user = User::factory()->create();
    $workspace = Workspace::factory()->create([
        'user_id' => $user->id,
        // A long name previously stretched the AuthSplitLayout grid column past the viewport.
        'name' => 'A Really Very Extremely Long Workspace Name That Should Truncate Instead Of Overflowing',
    ]);
    $workspace->members()->attach($user->id, membershipPivot('member'));
    $user->update(['current_workspace_id' => $workspace->id]);

    $post = Post::factory()->linkedin()->create([
        'workspace_id' => $workspace->id,
        'user_id' => $user->id,
        'content' => 'Launching our new mobile editor today!',
    ]);

    $this->actingAs($user);

    $pages = [
        'workspaces (AuthLayout)' => route('app.workspaces.index'),
        'posts index (default)' => route('app.posts.index'),
        'post editor (full-width)' => route('app.posts.edit', $post),
        'settings (tabs)' => route('app.api-keys.index'),
    ];

    foreach ($pages as $label => $url) {
        assertNoHorizontalOverflow(visit($url)->resize(375, 812), $label);
    }
});

test('auth and welcome pages do not overflow horizontally on a phone', function () {
    config(['trypost.self_hosted' => false]);

    $guestPages = [
        'login' => route('login'),
        'register' => route('register'),
        'forgot password' => route('password.request'),
    ];

    foreach ($guestPages as $label => $url) {
        assertNoHorizontalOverflow(visit($url)->resize(390, 844), $label);
    }

    $user = User::factory()->create();
    $user->update([
        'persona' => Persona::Agency->value,
        'goals' => [Goal::SaveTime->value],
        'previous_software' => PreviousSoftware::Buffer->value,
        'referral_source' => ReferralSource::ProductHunt->value,
    ]);
    $workspace = Workspace::factory()->create([
        'account_id' => $user->account_id,
        'user_id' => $user->id,
    ]);
    $workspace->members()->attach($user->id, membershipPivot('admin'));
    $user->update(['current_workspace_id' => $workspace->id]);
    $this->actingAs($user->fresh());

    $welcomePages = [
        'welcome software' => route('app.welcome.software'),
        'welcome plan' => route('app.welcome.plan'),
    ];

    foreach ($welcomePages as $label => $url) {
        assertNoHorizontalOverflow(visit($url)->resize(390, 844), $label);
    }
});