87 lines
2.9 KiB
PHP
87 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
SiteSetting::instance();
|
|
});
|
|
|
|
it('does not overflow horizontally when briefing contact info contains long unbroken strings', function (): void {
|
|
SiteSetting::instance()->update([
|
|
'email' => str_repeat('a', 50).'@email.'.str_repeat('b', 40),
|
|
'phone' => '(11) 99999-9999',
|
|
]);
|
|
|
|
$page = $this->visit('/briefing');
|
|
|
|
$overflow = $page->script(
|
|
'() => document.documentElement.scrollWidth - document.documentElement.clientWidth',
|
|
);
|
|
|
|
expect((int) $overflow)->toBeLessThanOrEqual(0);
|
|
});
|
|
|
|
it('shows sending state on submit and resets on bfcache restore', function (): void {
|
|
$page = $this->visit('/briefing');
|
|
|
|
$state = $page->script(<<<'JS'
|
|
() => {
|
|
const form = document.querySelector("form[data-contact-form]");
|
|
const button = document.querySelector("[data-submit-button]");
|
|
form?.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
|
const afterSubmit = {
|
|
label: button?.textContent?.trim(),
|
|
disabled: button?.disabled ?? false,
|
|
formBusy: form?.getAttribute("aria-busy"),
|
|
};
|
|
window.dispatchEvent(new PageTransitionEvent("pageshow", { persisted: true }));
|
|
return {
|
|
afterSubmit,
|
|
afterRestore: {
|
|
label: button?.textContent?.trim(),
|
|
disabled: button?.disabled ?? false,
|
|
formBusy: form?.getAttribute("aria-busy"),
|
|
},
|
|
};
|
|
}
|
|
JS);
|
|
|
|
expect($state['afterSubmit']['label'])->toBe('Enviando…');
|
|
expect($state['afterSubmit']['disabled'])->toBeTrue();
|
|
expect($state['afterSubmit']['formBusy'])->toBe('true');
|
|
|
|
expect($state['afterRestore']['label'])->toBe('Enviar briefing');
|
|
expect($state['afterRestore']['disabled'])->toBeFalse();
|
|
expect($state['afterRestore']['formBusy'])->toBeNull();
|
|
});
|
|
|
|
it('traps focus within the open mobile menu', function (): void {
|
|
$page = $this->visit('/');
|
|
$page->resize(390, 844);
|
|
$page->click('[data-menu-button]');
|
|
|
|
for ($i = 0; $i < 20; $i++) {
|
|
$inside = $page->script(
|
|
'() => document.querySelector("[data-main-nav]")?.contains(document.activeElement) ?? false',
|
|
);
|
|
expect($inside)->toBeTrue();
|
|
|
|
$page->keys(':focus', 'Tab');
|
|
}
|
|
|
|
$page->script('() => document.querySelector("[data-main-nav] a")?.focus()');
|
|
$page->keys(':focus', 'Shift+Tab');
|
|
|
|
$wrappedToLast = $page->script('() => {
|
|
const nav = document.querySelector("[data-main-nav]");
|
|
const links = nav?.querySelectorAll("a[href], button:not([disabled])") ?? [];
|
|
return links.length > 0 && document.activeElement === links[links.length - 1];
|
|
}');
|
|
expect($wrappedToLast)->toBeTrue();
|
|
});
|