Skip to content

Commit

Permalink
fix: respect reduced motion preference and set it in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Sep 15, 2023
1 parent 3d0c3f5 commit f931428
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
18 changes: 15 additions & 3 deletions packages/ui/src/components/Molecules/PageTransition.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { motion } from 'framer-motion';
import React, { PropsWithChildren } from 'react';
import { motion, useReducedMotion } from 'framer-motion';
import React, { PropsWithChildren, useEffect } from 'react';

import { Messages, readMessages } from './Messages';

export function PageTransition({ children }: PropsWithChildren) {
return (
const [messages, setMessages] = React.useState<Array<string>>([]);
useEffect(() => {
setMessages(readMessages());
}, []);
return useReducedMotion() ? (
<main id="main-content">
<Messages messages={messages} />
{children}
</main>
) : (
<motion.main
id="main-content"
initial={{ opacity: 0 }}
Expand All @@ -15,6 +26,7 @@ export function PageTransition({ children }: PropsWithChildren) {
duration: 0.3,
}}
>
<Messages messages={messages} />
{children}
</motion.main>
);
Expand Down
20 changes: 9 additions & 11 deletions packages/ui/src/components/Routes/Frame.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AnimatePresence } from 'framer-motion';
import React, { ComponentProps, PropsWithChildren, useEffect } from 'react';
import { AnimatePresence, useReducedMotion } from 'framer-motion';
import React, { ComponentProps, PropsWithChildren } from 'react';

import { Messages, readMessages } from '../Molecules/Messages';
import { Footer } from '../Organisms/Footer';
import Header from '../Organisms/Header';

Expand All @@ -11,18 +10,17 @@ export function Frame(
footer: ComponentProps<typeof Footer>;
}>,
) {
const [messages, setMessages] = React.useState<Array<string>>([]);
useEffect(() => {
setMessages(readMessages());
}, []);
return (
<div>
<Header {...props.header} />
<main>
<AnimatePresence mode="wait" initial={false}>
<Messages messages={messages} />
{props.children}
</AnimatePresence>
{useReducedMotion() ? (
<>{props.children}</>
) : (
<AnimatePresence mode="wait" initial={false}>
{props.children}
</AnimatePresence>
)}
</main>
<Footer {...props.footer} />
</div>
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/specs/links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ test.describe('links', () => {
await page.getByRole('link', { name: 'link to page' }).click();
await page.waitForURL(websiteUrl('/en/privacy'));

await page.goBack();
await page.goto(websiteUrl('/en/page-links'));

const downloadPromise = page.waitForEvent('download');
await page.getByRole('link', { name: 'link to file' }).click();
await page
.getByRole('link', { name: 'link to file', includeHidden: true })
.click();
const download = await downloadPromise;
expect(download.url()).toBe(
websiteUrl('/sites/default/files/2023-04/document_docx.docx'),
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/specs/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, test as setup } from '@playwright/test';
import { cmsUrl } from '../helpers/url';

setup('setup', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.goto(cmsUrl('/user/login'));
await page.getByRole('textbox', { name: 'Username' }).fill('admin');
await page.getByRole('textbox', { name: 'Password' }).fill('admin');
Expand Down

0 comments on commit f931428

Please sign in to comment.