-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pilot-app): load route state through URL param (#480)
* define route schema * chore: start test setup for app * chore: start pulling shared types into schema package * move more creator methods * start extending test-utils to cater for framework use-case of react-router * use new methods in app * update imports after chains package has been created * get type setup in order for app * revert some changes; make test work; break app * remove unused code * remove noExternal flag * make tests run again * add nodejs compat * run app tests in pipeline * enable coverage report for app tests * also use styles from ui pcakage
- Loading branch information
1 parent
fb6c75f
commit 1d7c86c
Showing
70 changed files
with
786 additions
and
209 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Deploy Pilot App | ||
name: Pilot App | ||
|
||
on: | ||
pull_request: | ||
|
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { type RouteConfig, index } from '@react-router/dev/routes' | ||
import { type RouteConfig, index, route } from '@react-router/dev/routes' | ||
|
||
export default [index('routes/index.tsx')] satisfies RouteConfig | ||
export default [ | ||
index('routes/index.tsx'), | ||
route('/edit-route', 'routes/edit-route.tsx'), | ||
] satisfies RouteConfig |
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,21 @@ | ||
import { render } from '@/test-utils' | ||
import { screen } from '@testing-library/react' | ||
import { createMockExecutionRoute } from '@zodiac/test-utils' | ||
import { describe, expect, it } from 'vitest' | ||
import EditRoute, { loader } from './edit-route' | ||
|
||
describe('Edit route', () => { | ||
it('shows the name of a route', async () => { | ||
const route = createMockExecutionRoute({ label: 'Test route' }) | ||
|
||
await render<typeof import('./edit-route')>( | ||
'/edit-route', | ||
{ path: '/edit-route', Component: EditRoute, loader }, | ||
{ searchParams: { route: btoa(JSON.stringify(route)) } }, | ||
) | ||
|
||
expect(screen.getByRole('textbox', { name: 'Label' })).toHaveValue( | ||
'Test route', | ||
) | ||
}) | ||
}) |
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,32 @@ | ||
import { invariantResponse } from '@epic-web/invariant' | ||
import { executionRouteSchema } from '@zodiac/schema' | ||
import { TextInput } from '@zodiac/ui' | ||
import type { Route } from './+types/edit-route' | ||
|
||
export const loader = ({ request }: Route.LoaderArgs) => { | ||
const url = new URL(request.url) | ||
|
||
const routeData = url.searchParams.get('route') | ||
|
||
invariantResponse(routeData != null, 'Missing "route" parameter') | ||
|
||
const decodedData = Buffer.from(routeData, 'base64') | ||
|
||
try { | ||
const rawJson = JSON.parse(decodedData.toString()) | ||
|
||
return { route: executionRouteSchema.parse(rawJson) } | ||
} catch { | ||
throw new Response(null, { status: 400 }) | ||
} | ||
} | ||
|
||
const EditRoute = ({ loaderData }: Route.ComponentProps) => { | ||
return ( | ||
<> | ||
<TextInput label="Label" defaultValue={loaderData.route.label} /> | ||
</> | ||
) | ||
} | ||
|
||
export default EditRoute |
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 @@ | ||
export { render } from './render' |
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,14 @@ | ||
import { | ||
renderFramework, | ||
type FrameworkRoute, | ||
type RenderOptions, | ||
type RouteModule, | ||
} from '@zodiac/test-utils' | ||
|
||
export function render<Module extends RouteModule>( | ||
currentPath: string, | ||
route: FrameworkRoute<Module>, | ||
options: RenderOptions, | ||
) { | ||
return renderFramework(currentPath, route, options) | ||
} |
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
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,35 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { fileURLToPath } from 'url' | ||
import { defineConfig } from 'vitest/config' | ||
import tsConfig from './tsconfig.json' | ||
|
||
const alias = Object.entries(tsConfig.compilerOptions.paths).reduce( | ||
(result, [key, value]) => ({ | ||
...result, | ||
[key]: fileURLToPath(new URL(value[0], import.meta.url)), | ||
}), | ||
{}, | ||
) | ||
|
||
const { CI } = process.env | ||
|
||
export default defineConfig({ | ||
test: { | ||
alias, | ||
environment: 'happy-dom', | ||
setupFiles: ['./vitest.setup.ts'], | ||
include: ['./app/**/*.{spec,test}.{ts,tsx}'], | ||
mockReset: true, | ||
clearMocks: true, | ||
|
||
coverage: { | ||
skipFull: true, | ||
enabled: CI != null, | ||
reportOnFailure: CI != null, | ||
reporter: CI ? ['json', 'json-summary'] : undefined, | ||
include: ['**/app/**/*.{ts,tsx}'], | ||
exclude: ['**/src/**/*.spec.{ts,tsx}'], | ||
}, | ||
}, | ||
}) |
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 @@ | ||
import '@testing-library/jest-dom/vitest' |
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
Oops, something went wrong.