feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -0,0 +1,184 @@
|
|||
import React from 'react'
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
||||
import type { HistoryDetail } from '../src/features/history/history-service'
|
||||
|
||||
const USER_ID = '11111111-1111-4111-8111-111111111111'
|
||||
const HISTORY_ID = '22222222-2222-4222-8222-222222222222'
|
||||
const AUDIO_ID = '33333333-3333-4333-8333-333333333333'
|
||||
|
||||
const mockStartPlayer = jest.fn(async () => 'started')
|
||||
const mockStopPlayer = jest.fn(async () => 'stopped')
|
||||
const mockPausePlayer = jest.fn(async () => 'paused')
|
||||
const mockResumePlayer = jest.fn(async () => 'resumed')
|
||||
const mockGetHistoryDetail = jest.fn<Promise<HistoryDetail>, [string, string]>()
|
||||
const mockCreateAudioPlaybackUrl = jest.fn<Promise<string>, [string, unknown]>()
|
||||
const mockGoBack = jest.fn()
|
||||
|
||||
const mockT = (key: string): string => key
|
||||
const mockFormatDate = (): string => '2026-11-14'
|
||||
const mockAuthValue = { user: { id: USER_ID } }
|
||||
const { d3roNativeDarkPalette } = jest.requireActual('@d3ro/ui-native') as typeof import('@d3ro/ui-native')
|
||||
const mockPreferencesValue = { palette: d3roNativeDarkPalette }
|
||||
|
||||
jest.mock('react-native-safe-area-context', () => ({
|
||||
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
||||
}))
|
||||
jest.mock('react-native-nitro-sound', () => ({
|
||||
useSoundWithStates: () => ({
|
||||
state: {
|
||||
isPlaying: false,
|
||||
playback: { position: 0, duration: 1_000 },
|
||||
},
|
||||
startPlayer: () => mockStartPlayer(),
|
||||
stopPlayer: () => mockStopPlayer(),
|
||||
pausePlayer: () => mockPausePlayer(),
|
||||
resumePlayer: () => mockResumePlayer(),
|
||||
}),
|
||||
}))
|
||||
jest.mock('@d3ro/i18n', () => ({
|
||||
useI18n: () => ({
|
||||
t: mockT,
|
||||
formatDate: mockFormatDate,
|
||||
}),
|
||||
}))
|
||||
jest.mock('../src/lib/auth-context', () => ({
|
||||
useAuth: () => mockAuthValue,
|
||||
}))
|
||||
jest.mock('../src/lib/preferences-context', () => ({
|
||||
useMobilePreferences: () => mockPreferencesValue,
|
||||
}))
|
||||
jest.mock('../src/features/history/history-cache', () => ({
|
||||
loadHistoryCache: jest.fn(async () => null),
|
||||
}))
|
||||
jest.mock('../src/features/history/history-service', () => {
|
||||
class MockHistoryServiceError extends Error {
|
||||
code: string
|
||||
|
||||
constructor(code: string, message: string) {
|
||||
super(message)
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
return {
|
||||
HistoryServiceError: MockHistoryServiceError,
|
||||
getHistoryDetail: (userId: string, historyId: string) => mockGetHistoryDetail(userId, historyId),
|
||||
createAudioPlaybackUrl: (userId: string, audioFile: unknown) =>
|
||||
mockCreateAudioPlaybackUrl(userId, audioFile),
|
||||
updateHistoryRevisionSafe: jest.fn(),
|
||||
deleteHistoryRevisionSafe: jest.fn(),
|
||||
}
|
||||
})
|
||||
|
||||
import HistoryDetailScreen from '../src/screens/HistoryDetailScreen'
|
||||
|
||||
const SAMPLE_DETAIL: HistoryDetail = {
|
||||
entry: {
|
||||
id: HISTORY_ID,
|
||||
user_id: USER_ID,
|
||||
title: 'Sample Memo',
|
||||
original_text: 'Original transcript',
|
||||
polished_text: 'Polished transcript',
|
||||
focused_app: null,
|
||||
focused_app_name: null,
|
||||
focused_app_window_title: null,
|
||||
mode: 'dictation',
|
||||
status: 'completed',
|
||||
error_code: null,
|
||||
audio_storage_key: 'audio/sample.wav',
|
||||
duration: 12,
|
||||
detected_language: 'ko',
|
||||
mic_device: null,
|
||||
word_count: 2,
|
||||
stt_model: 'whisper',
|
||||
llm_model: null,
|
||||
stt_latency_ms: null,
|
||||
llm_latency_ms: null,
|
||||
app_version: '1.16.5',
|
||||
summary_text: null,
|
||||
is_favorite: false,
|
||||
revision: 1,
|
||||
created_at: '2026-11-14T00:00:00.000Z',
|
||||
updated_at: '2026-11-14T00:00:00.000Z',
|
||||
},
|
||||
audioFiles: [
|
||||
{
|
||||
id: AUDIO_ID,
|
||||
user_id: USER_ID,
|
||||
history_id: HISTORY_ID,
|
||||
meeting_id: null,
|
||||
storage_bucket: 'audio-files',
|
||||
storage_key: 'audio/sample.wav',
|
||||
original_name: 'sample.wav',
|
||||
mime_type: 'audio/wav',
|
||||
size_bytes: 2048,
|
||||
duration_ms: 12_000,
|
||||
checksum_sha256: 'abc',
|
||||
upload_status: 'uploaded',
|
||||
retention_until: null,
|
||||
created_at: '2026-11-14T00:00:00.000Z',
|
||||
updated_at: '2026-11-14T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
jobs: [],
|
||||
}
|
||||
|
||||
describe('HistoryDetailScreen unmount audio & async cleanup', () => {
|
||||
beforeEach(() => {
|
||||
mockStartPlayer.mockClear()
|
||||
mockStopPlayer.mockClear()
|
||||
mockPausePlayer.mockClear()
|
||||
mockResumePlayer.mockClear()
|
||||
mockGetHistoryDetail.mockReset().mockResolvedValue(SAMPLE_DETAIL)
|
||||
mockCreateAudioPlaybackUrl.mockReset()
|
||||
mockGoBack.mockClear()
|
||||
})
|
||||
|
||||
test('HistoryDetailScreen_언마운트시_플레이어를중지하고진행중URL응답후재생을시작하지않음', async () => {
|
||||
let resolveSignedUrl: (url: string) => void = () => undefined
|
||||
mockCreateAudioPlaybackUrl.mockImplementation(
|
||||
() => new Promise<string>((resolve) => {
|
||||
resolveSignedUrl = resolve
|
||||
}),
|
||||
)
|
||||
|
||||
let renderer!: ReactTestRenderer
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
<HistoryDetailScreen
|
||||
route={{
|
||||
key: 'HistoryDetail-1',
|
||||
name: 'HistoryDetail',
|
||||
params: { historyId: HISTORY_ID },
|
||||
}}
|
||||
navigation={{ goBack: mockGoBack } as never}
|
||||
/>,
|
||||
)
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
})
|
||||
|
||||
const audioRow = renderer.root.findByProps({ testID: `history-audio-${AUDIO_ID}` })
|
||||
const playButton = audioRow.findAll(
|
||||
(node) => typeof node.props.onPress === 'function'
|
||||
&& node.props.accessibilityLabel === 'mobile.hist.audioPlay',
|
||||
)[0]
|
||||
|
||||
await act(async () => {
|
||||
playButton.props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
|
||||
expect(mockCreateAudioPlaybackUrl).toHaveBeenCalledTimes(1)
|
||||
|
||||
act(() => {
|
||||
renderer.unmount()
|
||||
})
|
||||
expect(mockStopPlayer).toHaveBeenCalledTimes(1)
|
||||
|
||||
await act(async () => {
|
||||
resolveSignedUrl('https://storage.example/signed.wav')
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(mockStartPlayer).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue