-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added static renderer instead of allowing Next.js specific over…
…writes BREAKING CHANGE: Reverted next.js changes for static rendering
- Loading branch information
Showing
6 changed files
with
123 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ package-lock.json | |
|
||
nextjs.d.ts | ||
historyjs.d.ts | ||
static.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* tslint:disable:no-expression-statement no-object-mutation */ | ||
|
||
import { render, cleanup, screen, act } from '@testing-library/react' | ||
import userEventImport from '@testing-library/user-event' | ||
import React from 'react' | ||
import Geschichte from '../lib/adapters/static/index.js' | ||
import { factoryParameters } from '../lib/store.js' | ||
import { pm } from '../lib/utils.js' | ||
import { serializers } from '../lib/serializers.js' | ||
|
||
const userEvent = userEventImport.default || userEventImport | ||
|
||
afterEach(cleanup) | ||
|
||
describe('<StaticGeschichteProvider />', () => { | ||
const { useQuery } = factoryParameters( | ||
{ | ||
someParameter: pm('parameter', serializers.string), | ||
}, | ||
{ someParameter: 'test' } | ||
) | ||
const ComponentThatRendersSomethingStatically = () => { | ||
const { | ||
pushState, | ||
replaceState, | ||
values: { someParameter }, | ||
} = useQuery() | ||
return ( | ||
<> | ||
<span role="content">{someParameter}</span> | ||
<button | ||
role="push" | ||
onClick={() => | ||
void pushState( | ||
(state) => void (state.someParameter = 'nextPushState') | ||
) | ||
} | ||
></button> | ||
|
||
<button | ||
role="replace" | ||
onClick={() => | ||
void replaceState( | ||
(state) => void (state.someParameter = 'nextReplaceState') | ||
) | ||
} | ||
></button> | ||
</> | ||
) | ||
} | ||
|
||
it('should render a static search string', () => { | ||
render( | ||
<Geschichte search="?parameter=myValue"> | ||
<ComponentThatRendersSomethingStatically /> | ||
</Geschichte> | ||
) | ||
expect(screen.getByRole('content').textContent).toEqual('myValue') | ||
}) | ||
|
||
it('should support replace and push state', async () => { | ||
render( | ||
<Geschichte> | ||
<ComponentThatRendersSomethingStatically /> | ||
</Geschichte> | ||
) | ||
await act(async () => { | ||
await userEvent.click(screen.getByRole('push')) | ||
}) | ||
expect(screen.getByRole('content').textContent).toEqual('nextPushState') | ||
await act(async () => { | ||
await userEvent.click(screen.getByRole('replace')) | ||
}) | ||
expect(screen.getByRole('content').textContent).toEqual('nextReplaceState') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { memo, useMemo } from 'react' | ||
import { HistoryManagement, StoreContext, useGeschichte } from '../../store.js' | ||
|
||
interface Props { | ||
readonly search?: string | ||
} | ||
|
||
const StaticGeschichteProvider = ({ | ||
search, | ||
children, | ||
}: React.PropsWithChildren<Props>) => { | ||
const historyInstance: HistoryManagement = useMemo(() => { | ||
return { | ||
initialSearch: () => search || '?', | ||
push: async () => { | ||
return | ||
}, | ||
replace: async () => { | ||
return | ||
}, | ||
} | ||
}, [search]) | ||
|
||
const value = useMemo(() => useGeschichte(historyInstance), [historyInstance]) | ||
return <StoreContext.Provider value={value}>{children}</StoreContext.Provider> | ||
} | ||
|
||
export default memo(StaticGeschichteProvider) |