ebcc5e0cea
Au passage consultation <-> edition d'un client, l'onglet courant (Information / Contact / Adresse / Comptabilite...) est conserve dans les deux sens, transmis via history.state (l'URL ne change pas — etat d'UI hors URL). - Nouveau util shared readHistoryTab : lit history.state.tab et le valide contre les onglets autorises (fallback Information : navigation directe, refresh, onglet hors role). - Consultation goEdit et edition goBack posent l'onglet courant ; chaque page initialise activeTab depuis l'historique. - Test unitaire du util (present/valide, hors-cles, absent, valeur non-string).
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect, afterEach } from 'vitest'
|
|
import { readHistoryTab } from '../historyTab'
|
|
|
|
const KEYS = ['information', 'contact', 'address', 'accounting']
|
|
|
|
describe('readHistoryTab', () => {
|
|
afterEach(() => {
|
|
window.history.replaceState(null, '')
|
|
})
|
|
|
|
it('retourne la cle d\'onglet quand elle est presente et valide', () => {
|
|
window.history.replaceState({ tab: 'address' }, '')
|
|
expect(readHistoryTab(KEYS)).toBe('address')
|
|
})
|
|
|
|
it('retourne null quand l\'onglet n\'est pas dans les cles valides (ex: role sans Comptabilite)', () => {
|
|
window.history.replaceState({ tab: 'accounting' }, '')
|
|
expect(readHistoryTab(['information', 'contact', 'address'])).toBeNull()
|
|
})
|
|
|
|
it('retourne null sans onglet dans l\'etat d\'historique (navigation directe / refresh)', () => {
|
|
window.history.replaceState(null, '')
|
|
expect(readHistoryTab(KEYS)).toBeNull()
|
|
|
|
window.history.replaceState({ foo: 'bar' }, '')
|
|
expect(readHistoryTab(KEYS)).toBeNull()
|
|
})
|
|
|
|
it('retourne null quand la valeur n\'est pas une chaine', () => {
|
|
window.history.replaceState({ tab: 42 }, '')
|
|
expect(readHistoryTab(KEYS)).toBeNull()
|
|
})
|
|
})
|