Skip to content

Commit 9ecd881

Browse files
Pollepsjoepio
authored andcommitted
fix tests
1 parent b8d73e4 commit 9ecd881

File tree

7 files changed

+42
-26
lines changed

7 files changed

+42
-26
lines changed

data-browser/src/components/Card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from 'styled-components';
2-
import { getTransitionName } from '../helpers/transitionName';
2+
import { transitionName } from '../helpers/transitionName';
33

44
type CardProps = {
55
/** Adds a colorful border */
@@ -23,7 +23,7 @@ export const Card = styled.div<CardProps>`
2323
border-color: ${props =>
2424
props.highlight ? props.theme.colors.main : props.theme.colors.bg2};
2525
26-
view-transition-name: ${p => getTransitionName('resource-page', p.about)};
26+
${p => transitionName('resource-page', p.about)};
2727
`;
2828

2929
export interface CardRowProps {

data-browser/src/components/SideBar/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ const SideBarStyled = styled('nav').attrs<SideBarStyledProps>(p => ({
101101
flex-direction: column;
102102
overflow-y: auto;
103103
overflow-x: hidden;
104-
105-
view-transition-name: sidebar;
106104
`;
107105

108106
const MenuWrapper = styled.div`

data-browser/src/helpers/AppSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export const AppSettingsContextProvider = (
2020
): JSX.Element => {
2121
const [darkMode, setDarkMode, darkModeSetting] = useDarkMode();
2222
const [mainColor, setMainColor] = useLocalStorage('mainColor', '#1b50d8');
23-
const [navbarTop, setNavbarTop] = useLocalStorage('navbarTop', true);
23+
const [navbarTop, setNavbarTop] = useLocalStorage('navbarTop', false);
2424
const [viewTransitionsEnabled, setViewTransitionsEnabled] = useLocalStorage(
2525
'viewTransitionsEnabled',
26-
false,
26+
true,
2727
);
2828
const [navbarFloating, setNavbarFloating] = useLocalStorage(
2929
'navbarFloating',

data-browser/src/helpers/transitionName.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cyrb53 = (str, seed = 0) => {
1+
const hashStringWithCYRB53 = (str, seed = 0) => {
22
let h1 = 0xdeadbeef ^ seed,
33
h2 = 0x41c6ce57 ^ seed;
44

@@ -21,7 +21,8 @@ export function getTransitionName(tag: string, subject: string | undefined) {
2121
throw new Error('Subject is required for transition name');
2222
}
2323

24-
return `${tag}-${cyrb53(subject ?? '')}`;
24+
// URL's are not allowed in view-transition-name so we hash the subject.
25+
return `${tag}-${hashStringWithCYRB53(subject ?? '')}`;
2526
}
2627

2728
export function transitionName(tag: string, subject: string | undefined) {

data-browser/src/hooks/useGlobalStylesWhileMounted.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const getNode = (id: string) => {
1414
return node;
1515
};
1616

17+
/**
18+
* Add a style element to the head with the given cssText while the component is mounted.
19+
* @param cssText CSS Styles to be added to the head.
20+
*/
1721
export function useGlobalStylesWhileMounted(cssText: string) {
1822
const id = useId();
1923

data-browser/src/hooks/useNavigateWithTransition.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { useNavigate } from 'react-router';
44
import { useSettings } from '../helpers/AppSettings';
55
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
66

7-
export function useNavigateWithTransition(onTransitionStart?: () => void) {
7+
/**
8+
* A wrapper around react-router's navigate function that will trigger css view transitions if enabled.
9+
*/
10+
export function useNavigateWithTransition() {
811
const navigate = useNavigate();
912
const { viewTransitionsEnabled } = useSettings();
1013

@@ -19,21 +22,20 @@ export function useNavigateWithTransition(onTransitionStart?: () => void) {
1922
}
2023

2124
// @ts-ignore
22-
document.startViewTransition(async () => {
23-
onTransitionStart?.();
24-
25-
return new Promise<void>(resolve => {
26-
flushSync(() => {
27-
// @ts-ignore
28-
navigate(to);
29-
wait(1).then(() => {
30-
resolve();
25+
document.startViewTransition(
26+
async () =>
27+
new Promise<void>(resolve => {
28+
flushSync(() => {
29+
// @ts-ignore
30+
navigate(to);
31+
wait(1).then(() => {
32+
resolve();
33+
});
3134
});
32-
});
33-
});
34-
});
35+
}),
36+
);
3537
},
36-
[navigate, onTransitionStart],
38+
[navigate],
3739
);
3840

3941
return navigateWithTransition;

data-browser/tests/e2e.spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,19 @@ test.describe('data-browser', async () => {
622622
});
623623
});
624624

625+
async function disableViewTransition(page: Page) {
626+
await page.click('text=Theme Settings');
627+
const checkbox = await page.getByLabel('Enable view transition');
628+
629+
await expect(checkbox).toBeVisible();
630+
631+
await checkbox.uncheck();
632+
await page.goBack();
633+
}
634+
625635
/** Signs in using an AtomicData.dev test user */
626636
async function signIn(page: Page) {
637+
await disableViewTransition(page);
627638
await page.click('text=user settings');
628639
await expect(
629640
await page.locator('text=edit data and sign Commits'),
@@ -657,7 +668,7 @@ async function newDrive(page: Page) {
657668
return { driveURL: driveURL as string, driveTitle };
658669
}
659670

660-
async function makeDrivePublic(page) {
671+
async function makeDrivePublic(page: Page) {
661672
await page.click(currentDriveTitle);
662673
await page.click(contextMenu);
663674
await page.click('button:has-text("share")');
@@ -686,13 +697,13 @@ async function openAtomic(page: Page) {
686697
async function editProfileAndCommit(page: Page) {
687698
await page.click('text=user settings');
688699
await page.click('text=Edit profile');
689-
await expect(await page.locator('text=add another property')).toBeVisible();
700+
await expect(page.locator('text=add another property')).toBeVisible();
690701
const username = `Test user edited at ${new Date().toLocaleDateString()}`;
691702
await page.fill('[data-test="input-name"]', username);
692703
await page.click('[data-test="save"]');
693-
await expect(await page.locator('text=saved')).toBeVisible();
704+
await expect(page.locator('text=Resource saved')).toBeVisible();
694705
await page.waitForURL(/\/app\/show/);
695-
await expect(await page.locator(`text=${username}`).first()).toBeVisible();
706+
await expect(page.locator(`text=${username}`).first()).toBeVisible();
696707
}
697708

698709
/** Create a new Resource in the current Drive */

0 commit comments

Comments
 (0)