Loads the light logo after the page load
Lazy loading saved its bytes during page load, but left the logo empty for a moment when navigating to the homepage on a wide screen. Also adds the second unit's code summary and the shared docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { fireEvent, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { act } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { mockViewport } from '@/test/navViewport';
|
||||
@@ -26,6 +27,24 @@ const panelLink = (text: string) =>
|
||||
.find((link) => link.textContent === text)!;
|
||||
|
||||
describe('NavigationBar', () => {
|
||||
it('houdt het lichte logo lui tot de pagina geladen is, behalve op home (BR-PRE-05)', async () => {
|
||||
const readyState = vi
|
||||
.spyOn(document, 'readyState', 'get')
|
||||
.mockReturnValue('interactive');
|
||||
const { container } = await renderWithProviders(<NavigationBar />, {
|
||||
path: '/over-mij',
|
||||
});
|
||||
const light = () => container.querySelectorAll('header img')[1];
|
||||
expect(light()).toHaveAttribute('loading', 'lazy');
|
||||
|
||||
act(() => {
|
||||
readyState.mockReturnValue('complete');
|
||||
window.dispatchEvent(new Event('load'));
|
||||
});
|
||||
expect(light()).not.toHaveAttribute('loading');
|
||||
readyState.mockRestore();
|
||||
});
|
||||
|
||||
it('heeft het logo als link naar home', async () => {
|
||||
await renderWithProviders(<NavigationBar />, { path: '/portfolio' });
|
||||
expect(
|
||||
|
||||
@@ -12,6 +12,7 @@ import { NoScriptMenuOpen } from './NoScriptNav';
|
||||
import NavSubmenu from './NavSubmenu';
|
||||
import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import usePageLoaded from '@/hooks/usePageLoaded';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
|
||||
import { isSectionCurrent } from '@/lib/navCurrent';
|
||||
@@ -49,6 +50,7 @@ export default function NavigationBar() {
|
||||
select: (routerState) => routerState.location.pathname,
|
||||
});
|
||||
const isHome = pathname === '/';
|
||||
const pageLoaded = usePageLoaded();
|
||||
|
||||
// Elke wissel van pagina sluit de menu's (ook de terugknop), maar niet
|
||||
// bij de eerste render
|
||||
@@ -139,8 +141,13 @@ export default function NavigationBar() {
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
// Not shown on pages with a solid header, so
|
||||
// not fetched there (BR-PRE-05)
|
||||
loading={isHome ? undefined : 'lazy'}
|
||||
// it must not compete with the page's own
|
||||
// photos until the page has loaded. Then it
|
||||
// loads anyway: a lazy hidden image would
|
||||
// flash on a client navigation to / (BR-PRE-05)
|
||||
loading={
|
||||
isHome || pageLoaded ? undefined : 'lazy'
|
||||
}
|
||||
display={overlay('none', 'block')}
|
||||
/>
|
||||
</RouterLink>
|
||||
|
||||
Reference in New Issue
Block a user