|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { resolveManagedByEmptyState } from '../managedByEmptyState'; |
| 3 | + |
| 4 | +// Mirror the real i18n fallback: return the English `defaultValue` baked into |
| 5 | +// the helper. The en.ts bundle mirrors these strings verbatim, so asserting on |
| 6 | +// the defaults is asserting on the copy a user actually sees. |
| 7 | +const t = (key: string, opts?: Record<string, unknown>): string => |
| 8 | + (opts?.defaultValue as string) ?? key; |
| 9 | + |
| 10 | +describe('resolveManagedByEmptyState', () => { |
| 11 | + it('returns undefined for platform / config / unknown buckets', () => { |
| 12 | + expect(resolveManagedByEmptyState('platform', t)).toBeUndefined(); |
| 13 | + expect(resolveManagedByEmptyState('config', t)).toBeUndefined(); |
| 14 | + expect(resolveManagedByEmptyState(undefined, t)).toBeUndefined(); |
| 15 | + expect(resolveManagedByEmptyState('nope', t)).toBeUndefined(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('leaves the system / append-only buckets intact', () => { |
| 19 | + expect(resolveManagedByEmptyState('system', t)?.title).toBe('Nothing here yet'); |
| 20 | + expect(resolveManagedByEmptyState('append-only', t)?.title).toBe('No events recorded'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('gives sys_user an actionable empty state (org invite + SSO JIT, end-users)', () => { |
| 24 | + const es = resolveManagedByEmptyState('better-auth', t, 'sys_user'); |
| 25 | + expect(es?.title).toBe('No users yet'); |
| 26 | + expect(es?.message).toMatch(/invite teammates to your organization/i); |
| 27 | + expect(es?.message).toMatch(/just-in-time/i); |
| 28 | + expect(es?.message).toMatch(/end-users/i); |
| 29 | + }); |
| 30 | + |
| 31 | + it('gives every other identity table a generic, accurate empty state', () => { |
| 32 | + // The single better-auth bucket is shared by ~18 identity tables; only |
| 33 | + // sys_user has a real onboarding answer. Sessions / tokens / jwks must NOT |
| 34 | + // get a "go invite someone" CTA. |
| 35 | + for (const name of ['sys_session', 'sys_api_key', 'sys_jwks', undefined]) { |
| 36 | + const es = resolveManagedByEmptyState('better-auth', t, name as string | undefined); |
| 37 | + expect(es?.title).toBe('No identity records'); |
| 38 | + expect(es?.message).toMatch(/created by the authentication provider/i); |
| 39 | + expect(es?.message).not.toMatch(/invite/i); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + // cloud#580 regression: the empty state must never advertise affordances that |
| 44 | + // are gated off (env-level "Invite User" is multi-org-only, hidden in |
| 45 | + // single-org) or that do not exist ("Reset Password" is not a toolbar action). |
| 46 | + it('never names the unreachable "Invite User" / "Reset Password" workflows', () => { |
| 47 | + for (const name of ['sys_user', 'sys_session', undefined]) { |
| 48 | + const es = resolveManagedByEmptyState('better-auth', t, name as string | undefined); |
| 49 | + expect(es?.message).not.toMatch(/invite user/i); |
| 50 | + expect(es?.message).not.toMatch(/reset password/i); |
| 51 | + } |
| 52 | + }); |
| 53 | +}); |
0 commit comments