Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(profile-ui): cover portal review followups r1-m3

Josuéfb1538253eaa
diff --git a/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx b/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
index 3cec178d9..c703f7a18 100644
--- a/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
+++ b/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
@@ -1,13 +1,45 @@
import React from 'react'
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import '@testing-library/jest-dom/vitest'
import { cleanup, render, screen } from '@testing-library/react'
+import { createRequire } from 'node:module'
+import { join, resolve } from 'node:path'
+import { buildDesktopEnvironmentLink } from '@lib/desktopAppLinks'
+import type { DesktopEnvironmentResponse } from '@/app/types/api'
import Page from '../../page'
+type ExpressTestApp = { use: (path: string, router: unknown) => void }
+type ExpressFactory = () => ExpressTestApp
+type SupertestResponse = { body: unknown }
+type SupertestRequest = { expect: (status: number) => Promise<SupertestResponse> }
+type SupertestFactory = (app: ExpressTestApp) => { get: (path: string) => SupertestRequest }
+
+const requireExternalRestApi = createRequire(
+ join(resolve(process.cwd(), '../external-rest-api'), 'package.json')
+)
+const express = requireExternalRestApi('express') as ExpressFactory
+const request = requireExternalRestApi('supertest') as SupertestFactory
+
const api = vi.hoisted(() => ({
getDesktopEnvironment: vi.fn(),
}))
+const originalDesktopEnvironmentConfig = {
+ appName: process.env.EXTERNAL_REST_API_DESKTOP_APP_NAME,
+ externalRestApiBaseUrl: process.env.EXTERNAL_REST_API_PUBLIC_BASE_URL,
+ rpcProxyBaseUrl: process.env.EXTERNAL_REST_API_DESKTOP_RPC_PROXY_BASE_URL,
+}
+
+async function getDesktopEnvironmentFromProducer(): Promise<DesktopEnvironmentResponse> {
+ const { createDesktopRouter } =
+ await import('../../../../external-rest-api/src/routes/desktop.js')
+ const app = express()
+ app.use('/api/v1', createDesktopRouter())
+
+ const response = await request(app).get('/api/v1/desktop/environment').expect(200)
+ return response.body as DesktopEnvironmentResponse
+}
+
vi.mock('@lib/api', () => ({
getDesktopEnvironment: api.getDesktopEnvironment,
}))
@@ -38,18 +70,49 @@ vi.mock('next/link', () => ({
),
}))
+beforeAll(() => {
+ process.env.EXTERNAL_REST_API_PUBLIC_BASE_URL = 'https://api.example.com/'
+ process.env.EXTERNAL_REST_API_DESKTOP_RPC_PROXY_BASE_URL = 'https://rpc.example.com/'
+ process.env.EXTERNAL_REST_API_DESKTOP_APP_NAME = 'Example Tenant'
+})
+
+afterAll(() => {
+ if (originalDesktopEnvironmentConfig.externalRestApiBaseUrl === undefined) {
+ delete process.env.EXTERNAL_REST_API_PUBLIC_BASE_URL
+ } else {
+ process.env.EXTERNAL_REST_API_PUBLIC_BASE_URL =
+ originalDesktopEnvironmentConfig.externalRestApiBaseUrl
+ }
+ if (originalDesktopEnvironmentConfig.rpcProxyBaseUrl === undefined) {
+ delete process.env.EXTERNAL_REST_API_DESKTOP_RPC_PROXY_BASE_URL
+ } else {
+ process.env.EXTERNAL_REST_API_DESKTOP_RPC_PROXY_BASE_URL =
+ originalDesktopEnvironmentConfig.rpcProxyBaseUrl
+ }
+ if (originalDesktopEnvironmentConfig.appName === undefined) {
+ delete process.env.EXTERNAL_REST_API_DESKTOP_APP_NAME
+ } else {
+ process.env.EXTERNAL_REST_API_DESKTOP_APP_NAME = originalDesktopEnvironmentConfig.appName
+ }
+})
+
beforeEach(() => {
api.getDesktopEnvironment.mockReset()
- api.getDesktopEnvironment.mockResolvedValue({
- appName: 'Evenfire Test',
- externalRestApiBaseUrl: 'https://api.example.com',
- rpcProxyBaseUrl: 'https://rpc.example.com',
- })
+ api.getDesktopEnvironment.mockImplementation(getDesktopEnvironmentFromProducer)
})
afterEach(cleanup)
describe('Profile Portal home desktop setup link', () => {
+ it('keeps the welcome, portal prompt, and account summary in three cards', () => {
+ api.getDesktopEnvironment.mockReturnValue(new Promise(() => {}))
+
+ const view = render(<Page />)
+
+ expect(view.container.querySelectorAll('.cu-page-stack > .cu-card')).toHaveLength(3)
+ expect(screen.getByText('Profile Portal', { selector: 'strong' })).toBeInTheDocument()
+ })
+
it('shows a loading status while desktop setup availability is checked', () => {
api.getDesktopEnvironment.mockReturnValue(new Promise(() => {}))
@@ -75,16 +138,32 @@ describe('Profile Portal home desktop setup link', () => {
})
it('labels the environment setup handoff accurately', async () => {
+ const environment = await getDesktopEnvironmentFromProducer()
+ api.getDesktopEnvironment.mockResolvedValue(environment)
+
render(<Page />)
const setupLink = await screen.findByRole('link', { name: 'Set up Desktop App' })
const setupCopy = setupLink.closest('p')
+ const href = new URL(setupLink.getAttribute('href') ?? '')
expect(setupCopy).toHaveTextContent('Prefer the desktop app?')
expect(setupCopy).not.toHaveTextContent('instead')
- expect(setupLink).toHaveAttribute(
- 'href',
- 'evenfire://desktop-environment?externalRestApiBaseUrl=https%3A%2F%2Fapi.example.com&tenantName=Evenfire+Test'
+ expect(href.searchParams.get('externalRestApiBaseUrl')).toBe(environment.externalRestApiBaseUrl)
+ expect(href.searchParams.get('tenantName')).toBe(environment.appName)
+ })
+
+ it('builds the setup link from the real public discovery response', async () => {
+ const environment = await getDesktopEnvironmentFromProducer()
+ const href = buildDesktopEnvironmentLink(environment)
+
+ expect(href).not.toBeNull()
+ const parsedLink = new URL(href ?? '')
+ expect(parsedLink.protocol).toBe('evenfire:')
+ expect(parsedLink.hostname).toBe('desktop-environment')
+ expect(parsedLink.searchParams.get('externalRestApiBaseUrl')).toBe(
+ environment.externalRestApiBaseUrl
)
+ expect(parsedLink.searchParams.get('tenantName')).toBe(environment.appName)
})
})
diff --git a/profile-ui/app/components/__tests__/Sidebar.test.tsx b/profile-ui/app/components/__tests__/Sidebar.test.tsx
index 2dd167c42..e6d7ea2c4 100644
--- a/profile-ui/app/components/__tests__/Sidebar.test.tsx
+++ b/profile-ui/app/components/__tests__/Sidebar.test.tsx
@@ -88,6 +88,23 @@ describe('Profile Sidebar access-controlled entries', () => {
})
})
+describe('Profile Sidebar navigation order', () => {
+ it('renders Home first, then the remaining sections alphabetically', () => {
+ profileAccessState.approvalTargets = [{ id: 'slack-target' }]
+ profileAccessState.canManageMembers = true
+
+ render(<Sidebar currentRoute="home" onLogout={vi.fn()} />)
+
+ expect(screen.getAllByRole('link').map(link => link.textContent?.trim())).toEqual([
+ 'Home',
+ 'Approval Channels',
+ 'Connected Accounts',
+ 'Members',
+ 'Settings',
+ ])
+ })
+})
+
describe('Profile Sidebar release identity', () => {
it('titles the brand with the platform release, not the portal package version', async () => {
const view = render(<Sidebar currentRoute="settings" onLogout={vi.fn()} />)
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index eb7a0b123..9d06f1e14 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.149",
+ "version": "0.1.151",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.149",
+ "version": "0.1.151",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index b7e9f6e3b..ad9d115db 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.149",
+ "version": "0.1.151",
"private": true,
"scripts": {
"dev": "next dev",