61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
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()
|
||
})
|
||
})
|