mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-13 08:22:03 +00:00
Les modifications en cours d'une fiche ne sont plus perdues quand on change de personne, ferme la fiche, sort du mode modification, ouvre un souvenir, ajoute une personne ou envoie les contributions. - La fiche enregistre par le même chemin que « Enregistrer » (onSave), pour la personne quittée. Un échec ou une validation la garde ouverte avec le message d'erreur. - Invité en contribution : les changements vont dans le brouillon, puis partent avec « Envoyer ». - Un petit message confirme l'enregistrement. Rien n'est enregistré quand rien n'a changé, ni en démo. - Un second enregistrement pendant l'envoi reçoit la même promesse (utils/saveOnLeave.js), sans double appel. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
import { describe, expect, it, vi } from 'vitest'
|
||
import { runOnce } from './saveOnLeave.js'
|
||
|
||
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
|
||
|
||
describe('runOnce (enregistrement de fiche)', () => {
|
||
it('un second appel pendant l’envoi reçoit le même résultat, sans second envoi', async () => {
|
||
const ref = { current: null }
|
||
const send = vi.fn(async () => { await tick(); return 'saved' })
|
||
const first = runOnce(ref, send)
|
||
const second = runOnce(ref, send)
|
||
expect(second).toBe(first)
|
||
expect(await first).toBe('saved')
|
||
expect(send).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('une fois l’envoi terminé, un nouvel appel enregistre à nouveau (nouvelle modification)', async () => {
|
||
const ref = { current: null }
|
||
const send = vi.fn(async () => 'saved')
|
||
await runOnce(ref, send)
|
||
expect(ref.current).toBeNull()
|
||
await runOnce(ref, send)
|
||
expect(send).toHaveBeenCalledTimes(2)
|
||
})
|
||
|
||
it('un échec se propage au résultat et libère le verrou pour une nouvelle tentative', async () => {
|
||
const ref = { current: null }
|
||
const send = vi.fn()
|
||
.mockImplementationOnce(async () => { throw new Error('réseau') })
|
||
.mockImplementationOnce(async () => 'saved')
|
||
await expect(runOnce(ref, send)).rejects.toThrow('réseau')
|
||
expect(ref.current).toBeNull()
|
||
expect(await runOnce(ref, send)).toBe('saved')
|
||
})
|
||
})
|