feat(examples): add comprehensive showcase example with tests#252
feat(examples): add comprehensive showcase example with tests#252
Conversation
Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/b856d77e-5b54-4993-90a6-2bece8085c55 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
… improve mock Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/b856d77e-5b54-4993-90a6-2bece8085c55 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new examples/showcase Vite + React app intended to demonstrate the full @forward-software/react-auth API surface using a mock auth client, along with a Vitest test suite to validate the example’s behavior.
Changes:
- Introduces
examples/showcaseexample app withMockAuthClient, UI components, and styling. - Adds Vitest + Testing Library test suite covering mock client lifecycle and core UI flows.
- Documents setup, usage, and feature mapping in
examples/showcase/README.mdand wires example dependencies.
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds dependency resolution entries for the new showcase example. |
| examples/showcase/vitest.config.ts | Vitest config for jsdom tests + local lib aliasing. |
| examples/showcase/vite.config.ts | Vite dev config (port 3003) + local lib aliasing. |
| examples/showcase/tsconfig.json | TypeScript config for the showcase example (strict, bundler resolution, path alias). |
| examples/showcase/test/test-utils.tsx | Shared test AuthClient + wrapper helpers. |
| examples/showcase/test/mock-auth-client.spec.ts | Unit tests for the mock auth client behavior and lifecycle hooks. |
| examples/showcase/test/components/LoginForm.spec.tsx | Component tests for login flows and error display. |
| examples/showcase/test/components/EventLog.spec.tsx | Component tests for auth event logging UI. |
| examples/showcase/test/components/AuthStatus.spec.tsx | Component tests for reactive auth state badges/token rendering. |
| examples/showcase/test/components/AuthenticatedView.spec.tsx | Component tests for refresh/logout interactions and expiry display. |
| examples/showcase/src/vite-env.d.ts | Vite type refs + CSS module declaration for TS 6 compatibility. |
| examples/showcase/src/styles.css | Styling for the dashboard/cards/badges/event log/loading screens. |
| examples/showcase/src/mock-auth-client.ts | Mock AuthClient implementation with storage persistence + lifecycle hooks. |
| examples/showcase/src/main.tsx | React root bootstrap. |
| examples/showcase/src/hooks/useAsyncCallback.ts | Async action hook with loading + error state. |
| examples/showcase/src/components/LoginForm.tsx | Login UI (valid + intentional invalid credentials) with async handling. |
| examples/showcase/src/components/EventLog.tsx | UI panel subscribing to auth events via on/off. |
| examples/showcase/src/components/Dashboard.tsx | Main layout + conditional authenticated/unauthenticated rendering using useSyncExternalStore. |
| examples/showcase/src/components/AuthStatus.tsx | Auth status badges + token JSON display using useSyncExternalStore. |
| examples/showcase/src/components/AuthenticatedView.tsx | Authenticated UI with refresh/logout actions and token expiry display. |
| examples/showcase/src/auth.ts | createAuth() wiring using MockAuthClient. |
| examples/showcase/src/App.tsx | Root provider usage with loading/error screens. |
| examples/showcase/README.md | Showcase documentation: features, commands, structure, credentials. |
| examples/showcase/package.json | Example dependencies + scripts for dev/build/test. |
| examples/showcase/index.html | Vite HTML entrypoint for the example. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot can you take care of the review comments. Note about the lock-file one, please update it by running |
… improve mock Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/836e3d55-e4d0-47fe-90d2-ec2c18a4ea95 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
Done in 61b7f31. Three things addressed:
Also added |
Affected Package(s)
@forward-software/react-auth(lib)@forward-software/react-auth-google(packages/google-signin)Related Issue(s)
Follow-up issues for integration hiccups discovered during development will be opened separately.
Motivation
No existing example demonstrates the full API surface of
@forward-software/react-auth, and none have tests. This adds ashowcaseexample app that exercises every key library feature using a mock backend — zero external dependencies beyond React and the auth library itself — and ships with a Vitest test suite.Description of Changes
examples/showcase/— new Vite + React 19 example app running on port 3003src/mock-auth-client.ts—MockAuthClientimplementing all 11 lifecycle hooks (onInit,onPostInit,onPreLogin,onLogin,onPostLogin,onPreRefresh,onRefresh,onPostRefresh,onPreLogout,onLogout,onPostLogout) with localStorage token persistence, shape validation, configurable network-delay simulation, and credential validation.onInitnow wrapsJSON.parsein a try/catch so corrupted localStorage is cleared andnullreturned cleanly instead of crashing the provider.createAuth()andAuthProviderwithLoadingComponent/ErrorComponentuseAuthClienthookuseSyncExternalStore(subscribe, getSnapshot)for reactive auth state (not shown in any existing example)on/off) via a real-time EventLog panel subscribing to all 11 auth eventstest/mock-auth-client.spec.ts— 17 unit tests for the full lifecycletest/components/AuthStatus.spec.tsx— 4 teststest/components/LoginForm.spec.tsx— 3 teststest/components/AuthenticatedView.spec.tsx— 4 teststest/components/EventLog.spec.tsx— 3 testsREADME.mdwith features table, setup/run/test instructions, project structure, valid credentials, and local development notesexamples/showcase/pnpm-lock.yamlcommitted alongside the app; rootpnpm-lock.yamlregenerated soexamples/showcaseis no longer tracked as a workspace member, consistent with all other examples being standalonetest/test-utils.tsx— fixedReact.FC→FCimport (was referencing undefinedReactnamespace under the automatic JSX runtime)vitest.config.ts— addedreact/react-domresolve aliases to deduplicate React when lib source is resolved directly, preventing duplicate-React hook errors in testsBreaking Changes
None
How to Test
Checklist
Notes for Reviewers
Five integration hiccups were discovered during development of this showcase and will be tracked as separate issues:
2.0.3), but local development benefits from aliasing to lib source.useSyncExternalStorepattern is undocumented for consumers —EnhancedAuthClientexposessubscribe/getSnapshotbut no existing example or README mentions this. Without it, components only re-render viauseAsyncCallbackloading-state changes, which is fragile for multi-component layouts.declare module '*.css'; onlyrefresh-tokenhas avite-env.d.tstoday.useAsyncCallbackinexamples/baseswallows rejections silently — missing try/catch meanssetLoading(false)never runs if the callback rejects, leaving the UI in a permanent loading state.onRefreshsignature in libtest/test-utils.tsxomits the required first parameter — declared asonRefresh(_minValidity?)instead ofonRefresh(currentTokens, _minValidity?), which misleads anyone reading tests to learn the API contract.