Adds the fallbacks for visitors without JavaScript
The mobile menu works through CSS, and controls that need JavaScript are hidden without it. The contact photo gets its own preload, and the tests cover the new Reveal behaviour, the first row and the noscript markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,29 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { act, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Reveal from './Reveal';
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
FakeIntersectionObserver.reset();
|
||||
});
|
||||
|
||||
// The rules of the element outside media queries, as one text
|
||||
const baseRules = (element: Element) =>
|
||||
cssRulesFor(element)
|
||||
.filter((rule) => !rule.startsWith('@media'))
|
||||
.join(' ');
|
||||
|
||||
// jsdom has no layout: put the element below the bottom edge of the viewport
|
||||
function startBelowFold() {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({
|
||||
top: innerHeight,
|
||||
} as DOMRect);
|
||||
}
|
||||
|
||||
describe('Reveal', () => {
|
||||
it('renders its content visibly when IntersectionObserver is missing', async () => {
|
||||
await renderWithProviders(
|
||||
@@ -25,4 +46,50 @@ describe('Reveal', () => {
|
||||
);
|
||||
expect(screen.getByTestId('reveal').tagName).toBe('FIGURE');
|
||||
});
|
||||
|
||||
it('stays visible, without a transition, when it is in view at load', async () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'visible');
|
||||
expect(reveal).toHaveStyle({ opacity: '1' });
|
||||
expect(baseRules(reveal)).toContain('transition: none');
|
||||
});
|
||||
|
||||
it('is hidden without a transition when it starts below the fold', async () => {
|
||||
startBelowFold();
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'hidden');
|
||||
expect(reveal).toHaveStyle({
|
||||
opacity: '0',
|
||||
transform: 'translateY(24px)',
|
||||
});
|
||||
expect(baseRules(reveal)).toContain('transition: none');
|
||||
});
|
||||
|
||||
it('fades in with its delay once it scrolls into view', async () => {
|
||||
startBelowFold();
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
act(() => FakeIntersectionObserver.instances[0].trigger(true));
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'visible');
|
||||
expect(reveal).toHaveStyle({ opacity: '1', transform: 'none' });
|
||||
const rules = baseRules(reveal);
|
||||
expect(rules).toContain('transition-property: opacity,transform');
|
||||
expect(rules).toContain('transition-delay: 0.4s');
|
||||
expect(rules).not.toContain('transition: none');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user