@quilted/create 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/esm/_virtual/index7.mjs +2 -2
- package/build/esm/_virtual/index8.mjs +2 -2
- package/build/esm/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.mjs +1 -1
- package/build/esm/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.mjs +1 -1
- package/build/esnext/_virtual/index7.esnext +2 -2
- package/build/esnext/_virtual/index8.esnext +2 -2
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/async.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/sync.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/async.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/sync.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/settings.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.esnext +1 -1
- package/package.json +1 -1
- package/templates/app-basic/App.tsx +8 -13
- package/templates/app-basic/browser.tsx +1 -1
- package/templates/app-basic/context/browser.ts +7 -3
- package/templates/app-basic/context/navigation.ts +6 -13
- package/templates/app-basic/context/preact.ts +9 -0
- package/templates/app-basic/context/server.ts +10 -3
- package/templates/app-basic/context/types.ts +20 -1
- package/templates/app-basic/package.json +1 -1
- package/templates/app-basic/tests/render/render.tsx +17 -22
- package/templates/app-basic/tests/render/types.ts +17 -13
- package/templates/app-basic/tests/render.ts +1 -1
- package/templates/app-empty/package.json +1 -1
- package/templates/app-graphql/App.tsx +10 -16
- package/templates/app-graphql/browser.tsx +1 -1
- package/templates/app-graphql/context/browser.ts +9 -13
- package/templates/app-graphql/context/navigation.ts +6 -13
- package/templates/app-graphql/context/preact.ts +9 -0
- package/templates/app-graphql/context/server.ts +13 -12
- package/templates/app-graphql/context/types.ts +23 -6
- package/templates/app-graphql/package.json +1 -1
- package/templates/app-graphql/tests/render/render.tsx +17 -37
- package/templates/app-graphql/tests/render/types.ts +20 -45
- package/templates/app-graphql/tests/render.ts +1 -1
- package/templates/app-trpc/App.tsx +15 -17
- package/templates/app-trpc/browser.tsx +1 -1
- package/templates/app-trpc/context/browser.ts +8 -4
- package/templates/app-trpc/context/navigation.ts +6 -13
- package/templates/app-trpc/context/preact.ts +9 -0
- package/templates/app-trpc/context/server.ts +11 -4
- package/templates/app-trpc/context/types.ts +27 -3
- package/templates/app-trpc/package.json +1 -1
- package/templates/app-trpc/tests/render/render.tsx +25 -29
- package/templates/app-trpc/tests/render/types.ts +17 -16
- package/templates/app-trpc/tests/render.ts +1 -1
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type {GraphQLClient} from '@quilted/quilt/graphql';
|
|
2
|
+
import type {Navigation} from '@quilted/quilt/navigation';
|
|
3
|
+
import type {Localization} from '@quilted/quilt/localize';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The shared context for this application. Values in this object are
|
|
7
|
+
* available to all components in the app via `useAppContext()`.
|
|
8
|
+
*/
|
|
4
9
|
export interface AppContext {
|
|
10
|
+
/**
|
|
11
|
+
* The navigation instance for this application. Manages the current URL,
|
|
12
|
+
* browser history, and programmatic navigation.
|
|
13
|
+
*/
|
|
5
14
|
readonly navigation: Navigation;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The localization instance for this application. Contains the active
|
|
18
|
+
* locale and formatting utilities for numbers, dates, currencies, and more.
|
|
19
|
+
*/
|
|
20
|
+
readonly localization: Localization;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The GraphQL client for this application. Provides the fetch function
|
|
24
|
+
* used to execute operations and the cache used to store results.
|
|
25
|
+
*/
|
|
26
|
+
readonly graphql: GraphQLClient;
|
|
10
27
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import {Suspense} from 'preact/compat';
|
|
2
2
|
|
|
3
3
|
import {createRender} from '@quilted/quilt/testing';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
BrowserTestMock,
|
|
7
|
-
} from '@quilted/quilt/browser/testing';
|
|
8
|
-
import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
|
|
4
|
+
import {TestBrowser} from '@quilted/quilt/browser/testing';
|
|
5
|
+
import {TestNavigation} from '@quilted/quilt/navigation/testing';
|
|
9
6
|
import {Localization} from '@quilted/quilt/localize';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
import {AppContextPreact} from '~/context/preact.ts';
|
|
7
|
+
import {QuiltFrameworkTestContext} from '@quilted/quilt/context/testing';
|
|
13
8
|
|
|
14
9
|
import {GraphQLTesting, GraphQLController} from '../graphql.ts';
|
|
15
10
|
|
|
@@ -29,40 +24,25 @@ export const renderApp = createRender<
|
|
|
29
24
|
// authors on the `root.context` property. Context is used to share data between your
|
|
30
25
|
// React tree and your test code, and is ideal for mocking out global context providers.
|
|
31
26
|
context({
|
|
32
|
-
|
|
33
|
-
browser = new
|
|
27
|
+
navigation = new TestNavigation(),
|
|
28
|
+
browser = new TestBrowser(),
|
|
29
|
+
localization = new Localization('en'),
|
|
34
30
|
graphql = new GraphQLController(),
|
|
35
|
-
graphQLCache = new GraphQLCache({fetch: graphql.fetch}),
|
|
36
31
|
}) {
|
|
37
|
-
return {
|
|
38
|
-
navigation: {router},
|
|
39
|
-
browser,
|
|
40
|
-
graphql: {fetch: graphql.fetch, cache: graphQLCache, controller: graphql},
|
|
41
|
-
};
|
|
32
|
+
return {navigation, browser, localization, graphql: {controller: graphql}};
|
|
42
33
|
},
|
|
43
34
|
// Render all of our app-wide context providers around each component under test.
|
|
44
|
-
render(element,
|
|
45
|
-
const {
|
|
46
|
-
navigation: {router},
|
|
47
|
-
browser,
|
|
48
|
-
graphql,
|
|
49
|
-
} = context;
|
|
50
|
-
|
|
35
|
+
render(element, {navigation, browser, localization, graphql}) {
|
|
51
36
|
return (
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
</GraphQLTesting>
|
|
62
|
-
</Navigation>
|
|
63
|
-
</Localization>
|
|
64
|
-
</BrowserDetailsContext.Provider>
|
|
65
|
-
</AppContextPreact.Provider>
|
|
37
|
+
<QuiltFrameworkTestContext
|
|
38
|
+
navigation={navigation}
|
|
39
|
+
browser={browser}
|
|
40
|
+
localization={localization}
|
|
41
|
+
>
|
|
42
|
+
<GraphQLTesting controller={graphql.controller}>
|
|
43
|
+
<Suspense fallback={null}>{element}</Suspense>
|
|
44
|
+
</GraphQLTesting>
|
|
45
|
+
</QuiltFrameworkTestContext>
|
|
66
46
|
);
|
|
67
47
|
},
|
|
68
48
|
async afterRender(wrapper) {
|
|
@@ -1,77 +1,52 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
import type {AppContext} from '~/context/types.ts';
|
|
1
|
+
import type {TestNavigation} from '@quilted/quilt/navigation/testing';
|
|
2
|
+
import type {TestBrowser} from '@quilted/quilt/browser/testing';
|
|
3
|
+
import type {Localization} from '@quilted/quilt/localize';
|
|
6
4
|
|
|
7
5
|
import type {GraphQLController} from '../graphql.ts';
|
|
8
6
|
|
|
9
7
|
export interface RenderOptions {
|
|
10
8
|
/**
|
|
11
|
-
* A custom
|
|
12
|
-
* custom router to simulate a particular URL, and you can spy on
|
|
13
|
-
* its navigation method to check that components navigate as
|
|
14
|
-
* you expect.
|
|
9
|
+
* A custom navigation to use for this component test.
|
|
15
10
|
*/
|
|
16
|
-
readonly
|
|
11
|
+
readonly navigation?: TestNavigation;
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
14
|
* A custom environment for this component test.
|
|
20
15
|
*/
|
|
21
|
-
readonly browser?:
|
|
16
|
+
readonly browser?: TestBrowser;
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
25
|
-
* for the component under test. You can customize the responses using
|
|
26
|
-
* the `fillGraphQL` and `createGraphQLController` utilities provided
|
|
27
|
-
* by this module.
|
|
28
|
-
*
|
|
29
|
-
* ```tsx
|
|
30
|
-
* import {renderApp} from '~/tests/render.ts';
|
|
31
|
-
* import {fillGraphQL, GraphQLController} from '~/tests/graphql.ts';
|
|
32
|
-
*
|
|
33
|
-
* import {MyComponent} from './MyComponent.tsx';
|
|
34
|
-
* import myComponentQuery from './MyComponentQuery.graphql';
|
|
35
|
-
*
|
|
36
|
-
* const myComponent = await renderApp(<MyComponent />, {
|
|
37
|
-
* graphql: new GraphQLController([
|
|
38
|
-
* fillGraphQL(myComponentQuery, {me: {name: 'Winston'}}),
|
|
39
|
-
* ]),
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
19
|
+
* A custom localization instance to use for this component test.
|
|
42
20
|
*/
|
|
43
|
-
readonly
|
|
21
|
+
readonly localization?: Localization;
|
|
44
22
|
|
|
45
23
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
24
|
+
* An object that controls the responses to GraphQL queries and mutations
|
|
25
|
+
* for the component under test.
|
|
48
26
|
*/
|
|
49
|
-
readonly
|
|
27
|
+
readonly graphql?: GraphQLController;
|
|
28
|
+
}
|
|
50
29
|
|
|
30
|
+
export interface RenderContext {
|
|
51
31
|
/**
|
|
52
|
-
*
|
|
32
|
+
* The navigation used for this component test.
|
|
53
33
|
*/
|
|
54
|
-
readonly
|
|
55
|
-
}
|
|
34
|
+
readonly navigation: TestNavigation;
|
|
56
35
|
|
|
57
|
-
export interface RenderContext extends AppContext {
|
|
58
36
|
/**
|
|
59
|
-
* The
|
|
37
|
+
* The browser environment for this component test.
|
|
60
38
|
*/
|
|
61
|
-
readonly
|
|
39
|
+
readonly browser: TestBrowser;
|
|
62
40
|
|
|
63
41
|
/**
|
|
64
|
-
* The
|
|
42
|
+
* The localization used for this component test.
|
|
65
43
|
*/
|
|
66
|
-
readonly
|
|
44
|
+
readonly localization: Localization;
|
|
67
45
|
|
|
68
46
|
/**
|
|
69
47
|
* The GraphQL context used for this component test.
|
|
70
48
|
*/
|
|
71
|
-
readonly graphql:
|
|
72
|
-
/**
|
|
73
|
-
* The GraphQL controller used for this component test.
|
|
74
|
-
*/
|
|
49
|
+
readonly graphql: {
|
|
75
50
|
readonly controller: GraphQLController;
|
|
76
51
|
};
|
|
77
52
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {NotFound} from '@quilted/quilt/server';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import {Routes} from '@quilted/quilt/navigation';
|
|
3
|
+
import {QuiltFrameworkContext} from '@quilted/quilt/context';
|
|
5
4
|
import {ReactQueryContext} from '@quilted/react-query';
|
|
6
5
|
|
|
7
6
|
import {Head} from './foundation/html.ts';
|
|
@@ -9,13 +8,13 @@ import {Frame} from './foundation/frame.ts';
|
|
|
9
8
|
|
|
10
9
|
import {Home} from './features/home.ts';
|
|
11
10
|
|
|
12
|
-
import {
|
|
13
|
-
import type {AppContext as AppContextType} from './context/types.ts';
|
|
11
|
+
import type {AppContext} from './context/types.ts';
|
|
14
12
|
import {AppContextPreact} from './context/preact.ts';
|
|
13
|
+
import {trpc} from './context/trpc.ts';
|
|
15
14
|
import {routeWithAppContext} from './context/navigation.ts';
|
|
16
15
|
|
|
17
16
|
export interface AppProps {
|
|
18
|
-
context:
|
|
17
|
+
context: AppContext;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
// Define the routes for your application. If you have a lot of routes, you
|
|
@@ -40,18 +39,17 @@ const routes = [
|
|
|
40
39
|
export function App({context}: AppProps) {
|
|
41
40
|
return (
|
|
42
41
|
<AppContextPreact.Provider value={context}>
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
<QuiltFrameworkContext
|
|
43
|
+
navigation={context.navigation}
|
|
44
|
+
localization={context.localization}
|
|
45
|
+
>
|
|
46
|
+
<trpc.Provider client={context.trpc} queryClient={context.queryClient}>
|
|
47
|
+
<ReactQueryContext client={context.queryClient}>
|
|
46
48
|
<Head />
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/>
|
|
52
|
-
</Localization>
|
|
53
|
-
</ReactQueryContext>
|
|
54
|
-
</trpc.Provider>
|
|
49
|
+
<Routes list={routes} context={context} />
|
|
50
|
+
</ReactQueryContext>
|
|
51
|
+
</trpc.Provider>
|
|
52
|
+
</QuiltFrameworkContext>
|
|
55
53
|
</AppContextPreact.Provider>
|
|
56
54
|
);
|
|
57
55
|
}
|
|
@@ -15,7 +15,7 @@ const app = new BrowserApp(<App context={context} />, {context});
|
|
|
15
15
|
// @example
|
|
16
16
|
// ```js
|
|
17
17
|
// // Log the current URL
|
|
18
|
-
// console.log(globalThis.app.context.navigation.
|
|
18
|
+
// console.log(globalThis.app.context.navigation.currentRequest.url);
|
|
19
19
|
// ```
|
|
20
20
|
Object.defineProperty(globalThis, 'app', {
|
|
21
21
|
value: app,
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import {httpBatchLink} from '@trpc/client';
|
|
2
2
|
import {QueryClient} from '@tanstack/react-query';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import {Navigation} from '@quilted/quilt/navigation';
|
|
5
|
+
import {Localization} from '@quilted/quilt/localize';
|
|
6
|
+
|
|
6
7
|
import {trpc} from './trpc.ts';
|
|
8
|
+
import type {AppContext} from './types.ts';
|
|
7
9
|
|
|
8
10
|
export class BrowserAppContext implements AppContext {
|
|
9
|
-
readonly navigation:
|
|
11
|
+
readonly navigation: Navigation;
|
|
12
|
+
readonly localization: Localization;
|
|
10
13
|
readonly trpc: AppContext['trpc'];
|
|
11
14
|
readonly queryClient: QueryClient;
|
|
12
15
|
|
|
13
16
|
constructor() {
|
|
14
|
-
this.navigation = new
|
|
17
|
+
this.navigation = new Navigation();
|
|
18
|
+
this.localization = new Localization(navigator.language);
|
|
15
19
|
this.queryClient = new QueryClient();
|
|
16
20
|
this.trpc = trpc.createClient({
|
|
17
21
|
links: [httpBatchLink({url: new URL('/api', window.location.href).href})],
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createContextRouteFunction,
|
|
3
|
+
Navigation,
|
|
4
|
+
} from '@quilted/quilt/navigation';
|
|
2
5
|
|
|
3
6
|
import type {AppContext} from './types.ts';
|
|
4
7
|
|
|
5
|
-
export interface Navigation {
|
|
6
|
-
readonly router: Router;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class NavigationForApp implements Navigation {
|
|
10
|
-
readonly router: Router;
|
|
11
|
-
|
|
12
|
-
constructor(url?: string | URL) {
|
|
13
|
-
this.router = new Router(url);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
8
|
export const routeWithAppContext = createContextRouteFunction<AppContext>();
|
|
9
|
+
|
|
10
|
+
export {Navigation};
|
|
@@ -2,5 +2,14 @@ import {createOptionalContext} from '@quilted/quilt/context';
|
|
|
2
2
|
|
|
3
3
|
import type {AppContext} from './types.ts';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The Preact context object for this application's shared context.
|
|
7
|
+
* Provide it in `App.tsx` via `<AppContextPreact.Provider value={context}>`.
|
|
8
|
+
*/
|
|
5
9
|
export const AppContextPreact = createOptionalContext<AppContext>();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the app's shared context. All fields in `AppContext` are required
|
|
13
|
+
* and will be available anywhere inside `<AppContextPreact.Provider>`.
|
|
14
|
+
*/
|
|
6
15
|
export const useAppContext = AppContextPreact.use;
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import {createDirectClient} from '@quilted/trpc/server';
|
|
2
2
|
import {QueryClient} from '@tanstack/react-query';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import {Navigation} from '@quilted/quilt/navigation';
|
|
5
|
+
import {Localization, parseAcceptLanguageHeader} from '@quilted/quilt/localize';
|
|
6
|
+
|
|
6
7
|
import {appRouter} from '../trpc.ts';
|
|
8
|
+
import type {AppContext} from './types.ts';
|
|
7
9
|
|
|
8
10
|
export class ServerAppContext implements AppContext {
|
|
9
|
-
readonly navigation:
|
|
11
|
+
readonly navigation: Navigation;
|
|
12
|
+
readonly localization: Localization;
|
|
10
13
|
readonly trpc: AppContext['trpc'];
|
|
11
14
|
readonly queryClient: QueryClient;
|
|
12
15
|
|
|
13
16
|
constructor(request: Request) {
|
|
14
|
-
this.navigation = new
|
|
17
|
+
this.navigation = new Navigation(request.url);
|
|
18
|
+
this.localization = new Localization(
|
|
19
|
+
parseAcceptLanguageHeader(request.headers.get('Accept-Language') ?? '') ??
|
|
20
|
+
'en',
|
|
21
|
+
);
|
|
15
22
|
this.trpc = createDirectClient(appRouter);
|
|
16
23
|
this.queryClient = new QueryClient();
|
|
17
24
|
}
|
|
@@ -1,11 +1,35 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {TRPCUntypedClient} from '@trpc/client';
|
|
1
|
+
import type {TRPCClient} from '@trpc/client';
|
|
3
2
|
import type {QueryClient} from '@tanstack/react-query';
|
|
3
|
+
import type {Navigation} from '@quilted/quilt/navigation';
|
|
4
|
+
import type {Localization} from '@quilted/quilt/localize';
|
|
4
5
|
|
|
5
6
|
import type {AppRouter} from '../trpc.ts';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The shared context for this application. Values in this object are
|
|
10
|
+
* available to all components in the app via `useAppContext()`.
|
|
11
|
+
*/
|
|
7
12
|
export interface AppContext {
|
|
13
|
+
/**
|
|
14
|
+
* The navigation instance for this application. Manages the current URL,
|
|
15
|
+
* browser history, and programmatic navigation.
|
|
16
|
+
*/
|
|
8
17
|
readonly navigation: Navigation;
|
|
9
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The localization instance for this application. Contains the active
|
|
21
|
+
* locale and formatting utilities for numbers, dates, currencies, and more.
|
|
22
|
+
*/
|
|
23
|
+
readonly localization: Localization;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The tRPC client for this application, used to call tRPC procedures.
|
|
27
|
+
*/
|
|
28
|
+
readonly trpc: TRPCClient<AppRouter>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The react-query client for this application, used by tRPC to manage
|
|
32
|
+
* request state and caching.
|
|
33
|
+
*/
|
|
10
34
|
readonly queryClient: QueryClient;
|
|
11
35
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import {createRender} from '@quilted/quilt/testing';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
BrowserTestMock,
|
|
5
|
-
} from '@quilted/quilt/browser/testing';
|
|
6
|
-
import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
|
|
2
|
+
import {TestBrowser} from '@quilted/quilt/browser/testing';
|
|
3
|
+
import {TestNavigation} from '@quilted/quilt/navigation/testing';
|
|
7
4
|
import {Localization} from '@quilted/quilt/localize';
|
|
5
|
+
import {QuiltFrameworkTestContext} from '@quilted/quilt/context/testing';
|
|
8
6
|
|
|
9
7
|
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
|
|
10
8
|
|
|
11
9
|
import {trpc} from '~/context/trpc.ts';
|
|
12
|
-
import {AppContextPreact} from '~/context/preact.ts';
|
|
13
10
|
|
|
14
11
|
import {RenderOptions, RenderContext, RenderActions} from './types.ts';
|
|
15
12
|
|
|
@@ -26,37 +23,36 @@ export const renderApp = createRender<
|
|
|
26
23
|
// Create context that can be used by the `render` function, and referenced by test
|
|
27
24
|
// authors on the `root.context` property. Context is used to share data between your
|
|
28
25
|
// React tree and your test code, and is ideal for mocking out global context providers.
|
|
29
|
-
context({
|
|
26
|
+
context({
|
|
27
|
+
navigation = new TestNavigation(),
|
|
28
|
+
browser = new TestBrowser(),
|
|
29
|
+
localization = new Localization('en'),
|
|
30
|
+
}) {
|
|
30
31
|
return {
|
|
31
|
-
navigation
|
|
32
|
+
navigation,
|
|
32
33
|
browser,
|
|
34
|
+
localization,
|
|
33
35
|
trpc: trpc.createClient(),
|
|
34
36
|
queryClient: new QueryClient(),
|
|
35
37
|
};
|
|
36
38
|
},
|
|
37
39
|
// Render all of our app-wide context providers around each component under test.
|
|
38
|
-
render(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
trpc: trpcClient,
|
|
43
|
-
queryClient,
|
|
44
|
-
} = context;
|
|
45
|
-
|
|
40
|
+
render(
|
|
41
|
+
element,
|
|
42
|
+
{navigation, browser, localization, trpc: trpcClient, queryClient},
|
|
43
|
+
) {
|
|
46
44
|
return (
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</BrowserDetailsContext.Provider>
|
|
59
|
-
</AppContextPreact.Provider>
|
|
45
|
+
<QuiltFrameworkTestContext
|
|
46
|
+
navigation={navigation}
|
|
47
|
+
browser={browser}
|
|
48
|
+
localization={localization}
|
|
49
|
+
>
|
|
50
|
+
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
51
|
+
<QueryClientProvider client={queryClient}>
|
|
52
|
+
{element}
|
|
53
|
+
</QueryClientProvider>
|
|
54
|
+
</trpc.Provider>
|
|
55
|
+
</QuiltFrameworkTestContext>
|
|
60
56
|
);
|
|
61
57
|
},
|
|
62
58
|
async afterRender() {
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type {TestNavigation} from '@quilted/quilt/navigation/testing';
|
|
2
|
+
import type {TestBrowser} from '@quilted/quilt/browser/testing';
|
|
3
|
+
import type {Localization} from '@quilted/quilt/localize';
|
|
3
4
|
import type {QueryClient} from '@tanstack/react-query';
|
|
4
5
|
|
|
5
|
-
import type {AppContext} from '~/context/types.ts';
|
|
6
|
-
|
|
7
6
|
export interface RenderOptions {
|
|
8
7
|
/**
|
|
9
|
-
* A custom
|
|
10
|
-
* custom router to simulate a particular URL, and you can spy on
|
|
11
|
-
* its navigation method to check that components navigate as
|
|
12
|
-
* you expect.
|
|
8
|
+
* A custom navigation to use for this component test.
|
|
13
9
|
*/
|
|
14
|
-
readonly
|
|
10
|
+
readonly navigation?: TestNavigation;
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
13
|
* A custom environment for this component test.
|
|
18
14
|
*/
|
|
19
|
-
readonly browser?:
|
|
15
|
+
readonly browser?: TestBrowser;
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
|
-
* A custom
|
|
18
|
+
* A custom localization instance to use for this component test.
|
|
23
19
|
*/
|
|
24
|
-
readonly
|
|
20
|
+
readonly localization?: Localization;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
export interface RenderContext
|
|
23
|
+
export interface RenderContext {
|
|
28
24
|
/**
|
|
29
|
-
* The
|
|
25
|
+
* The navigation used for this component test.
|
|
30
26
|
*/
|
|
31
|
-
readonly navigation:
|
|
27
|
+
readonly navigation: TestNavigation;
|
|
32
28
|
|
|
33
29
|
/**
|
|
34
30
|
* The browser environment for this component test.
|
|
35
31
|
*/
|
|
36
|
-
readonly browser:
|
|
32
|
+
readonly browser: TestBrowser;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The localization used for this component test.
|
|
36
|
+
*/
|
|
37
|
+
readonly localization: Localization;
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* The react-query client used for this component test.
|