Expand AITURK Turkish settings and desktop surfaces for beta 5
This commit is contained in:
1 parent
237d1e2060
commit
5e76f58637
108 files changed
+6675
-1034
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { I18nProvider } from '@/i18n'
|
||||
import type { QuickEntryStatePush } from '@/store/quick-entry'
|
||||
|
||||
import { QuickEntryApp } from './quick-entry-app'
|
||||
|
||||
const originalBridge = window.hermesDesktop
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: originalBridge })
|
||||
})
|
||||
|
||||
describe('localized Quick Entry', () => {
|
||||
it('adopts the main window language without losing the draft or changing the target ID', () => {
|
||||
let push: (payload: QuickEntryStatePush) => void = () => {}
|
||||
const submit = vi.fn()
|
||||
const offState = vi.fn()
|
||||
Object.defineProperty(window, 'hermesDesktop', {
|
||||
configurable: true,
|
||||
value: {
|
||||
quickEntry: {
|
||||
onShown: () => () => {},
|
||||
onState: (callback: typeof push) => {
|
||||
push = callback
|
||||
|
||||
return offState
|
||||
},
|
||||
submit,
|
||||
dismiss: vi.fn()
|
||||
}
|
||||
}
|
||||
})
|
||||
const view = render(
|
||||
<I18nProvider configClient={null} initialLocale="en">
|
||||
<QuickEntryApp />
|
||||
</I18nProvider>
|
||||
)
|
||||
const sessions = [{ id: 'stored-session-42', title: 'Customer’s custom title' }]
|
||||
act(() => push({ connected: true, locale: 'en', sessions }))
|
||||
fireEvent.change(screen.getByRole('textbox', { name: 'Quick Entry' }), { target: { value: 'Dosyayı incele' } })
|
||||
fireEvent.change(screen.getByRole('combobox', { name: 'Target session' }), {
|
||||
target: { value: 'stored-session-42' }
|
||||
})
|
||||
act(() => push({ connected: true, locale: 'tr', sessions }))
|
||||
const input = screen.getByRole('textbox', { name: 'Hızlı giriş' }) as HTMLInputElement
|
||||
expect(input.value).toBe('Dosyayı incele')
|
||||
expect(input.placeholder).toBe('AITURK’e sor…')
|
||||
expect((screen.getByRole('combobox', { name: 'Hedef oturum' }) as HTMLSelectElement).value).toBe(
|
||||
'stored-session-42'
|
||||
)
|
||||
expect(screen.getByRole('option', { name: 'Customer’s custom title' })).toBeTruthy()
|
||||
fireEvent.keyDown(input, { key: 'Enter' })
|
||||
expect(submit).toHaveBeenCalledExactlyOnceWith({ target: 'stored-session-42', text: 'Dosyayı incele' })
|
||||
view.unmount()
|
||||
expect(offState).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useReducer, useRef } from 'react'
|
||||
|
||||
import { normalizeLocale, useI18n } from '@/i18n'
|
||||
import {
|
||||
initialQuickComposerState,
|
||||
QUICK_TARGET_CURRENT,
|
||||
@@ -26,6 +27,8 @@ import {
|
||||
* the primary renderer's normal prompt-submit path.
|
||||
*/
|
||||
export function QuickEntryApp() {
|
||||
const { t, setLocale } = useI18n()
|
||||
const copy = t.surfaces.quickEntry
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
// The reducer returns { send, state }; this wrapper performs the side effect
|
||||
@@ -56,6 +59,7 @@ export function QuickEntryApp() {
|
||||
})
|
||||
|
||||
const offState = api?.onState(payload => {
|
||||
void setLocale(normalizeLocale(payload?.locale))
|
||||
dispatch({
|
||||
connected: payload?.connected === true,
|
||||
sessions: Array.isArray(payload?.sessions) ? payload.sessions : [],
|
||||
@@ -69,7 +73,7 @@ export function QuickEntryApp() {
|
||||
offShown?.()
|
||||
offState?.()
|
||||
}
|
||||
}, [])
|
||||
}, [setLocale])
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -110,7 +114,7 @@ export function QuickEntryApp() {
|
||||
›
|
||||
</span>
|
||||
<input
|
||||
aria-label="Quick Entry"
|
||||
aria-label={copy.title}
|
||||
autoCapitalize="off"
|
||||
autoComplete="off"
|
||||
autoCorrect="off"
|
||||
@@ -131,7 +135,7 @@ export function QuickEntryApp() {
|
||||
dispatch({ type: 'dismiss' })
|
||||
}
|
||||
}}
|
||||
placeholder={state.connected ? 'Ask Hermes…' : 'Not connected — open Hermes to reconnect'}
|
||||
placeholder={state.connected ? copy.ask : copy.disconnected}
|
||||
ref={inputRef}
|
||||
spellCheck={false}
|
||||
style={{
|
||||
@@ -158,10 +162,10 @@ export function QuickEntryApp() {
|
||||
userSelect: 'none'
|
||||
}}
|
||||
>
|
||||
Send to
|
||||
{copy.sendTo}
|
||||
</label>
|
||||
<select
|
||||
aria-label="Target session"
|
||||
aria-label={copy.target}
|
||||
disabled={!state.connected}
|
||||
id="quick-entry-target"
|
||||
onChange={event => dispatch({ target: event.target.value, type: 'target' })}
|
||||
@@ -182,8 +186,8 @@ export function QuickEntryApp() {
|
||||
}}
|
||||
value={state.target}
|
||||
>
|
||||
<option value={QUICK_TARGET_CURRENT}>Current chat</option>
|
||||
<option value={QUICK_TARGET_NEW}>New session</option>
|
||||
<option value={QUICK_TARGET_CURRENT}>{copy.current}</option>
|
||||
<option value={QUICK_TARGET_NEW}>{copy.newSession}</option>
|
||||
{state.sessions.map(session => (
|
||||
<option key={session.id} value={session.id}>
|
||||
{session.title}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
import { ErrorBoundary } from '@/components/error-boundary'
|
||||
import { I18nProvider } from '@/i18n'
|
||||
import { ThemeProvider } from '@/themes/context'
|
||||
|
||||
import { QuickEntryApp } from './quick-entry-app'
|
||||
@@ -30,7 +31,9 @@ export function mountQuickEntry(): void {
|
||||
<StrictMode>
|
||||
<ErrorBoundary label="quick-entry">
|
||||
<ThemeProvider>
|
||||
<QuickEntryApp />
|
||||
<I18nProvider configClient={null}>
|
||||
<QuickEntryApp />
|
||||
</I18nProvider>
|
||||
</ThemeProvider>
|
||||
</ErrorBoundary>
|
||||
</StrictMode>
|
||||
|
||||
Reference in new issue
Block a user