test: stabilize smoke lane and timer-heavy tests

This commit is contained in:
Test
2026-04-08 10:22:47 +02:00
parent 6b1a44cdfd
commit cfa07a82cc
3 changed files with 22 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { render, screen, fireEvent, act } from '@testing-library/react'
import { TypeCustomizePopover } from './TypeCustomizePopover'
import { resolveIcon, ICON_OPTIONS } from '../utils/iconRegistry'
@@ -156,18 +156,23 @@ describe('TypeCustomizePopover', () => {
it('calls onChangeTemplate after debounce', async () => {
vi.useFakeTimers()
renderPopover()
const textarea = screen.getByTestId('template-textarea')
fireEvent.change(textarea, { target: { value: '## Debounced' } })
try {
renderPopover()
const textarea = screen.getByTestId('template-textarea')
fireEvent.change(textarea, { target: { value: '## Debounced' } })
// Should not be called immediately
expect(onChangeTemplate).not.toHaveBeenCalled()
// Should not be called immediately
expect(onChangeTemplate).not.toHaveBeenCalled()
// Fast-forward past debounce
vi.advanceTimersByTime(600)
expect(onChangeTemplate).toHaveBeenCalledWith('## Debounced')
// Fast-forward past debounce and flush the resulting state update.
await act(async () => {
vi.advanceTimersByTime(600)
})
vi.useRealTimers()
expect(onChangeTemplate).toHaveBeenCalledWith('## Debounced')
} finally {
vi.useRealTimers()
}
})
it('treats null template as empty string', () => {

View File

@@ -1,5 +1,5 @@
import '@testing-library/jest-dom/vitest'
import { vi } from 'vitest'
import { afterEach, vi } from 'vitest'
import { createElement, type ReactNode, type ComponentType } from 'react'
// Stub fetch to prevent jsdom@28 + Node 22 undici incompatibility.
@@ -57,6 +57,11 @@ vi.mock('@tauri-apps/plugin-opener', () => ({
openUrl: vi.fn(),
}))
afterEach(() => {
vi.clearAllTimers()
vi.useRealTimers()
})
// Mock react-day-picker: Calendar component uses DayPicker which needs real DOM APIs not available in jsdom
vi.mock('react-day-picker', () => ({
DayPicker: () => null,

View File

@@ -142,7 +142,7 @@ test('rename note updates filename on disk', async ({ page }) => {
// 6. Wikilink update on rename — other files' [[Note B]] updated
// ---------------------------------------------------------------------------
test('rename note updates wikilinks in other files @smoke', async ({ page }) => {
test('rename note updates wikilinks in other files', async ({ page }) => {
// Open Note B and rename it
await openNote(page, 'Note B')
await renameActiveNote(page, 'Note B Updated')