5180 fichiers 38.5 Mo 0 téléchargements 244 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / hooks / notification / useNotification.autoclose.test.ts
useNotification.autoclose.test.ts 1.8 Ko Télécharger le fichier
/* @vitest-environment jsdom */
import { describe, expect, it } from 'vitest';
import { NotificationAlertItem } from '../../api';
import { getAutoCloseSeconds, prependSingleAlert } from './useNotification';

describe('Notification auto close delay', () => {
    it('reads the delay the server sent with the notification', () => {
        expect(getAutoCloseSeconds(new Map([['timeout', '120']]))).toBe(120);
    });

    it('leaves notifications without a delay open until they are closed by hand', () => {
        expect(getAutoCloseSeconds(new Map())).toBeNull();
    });

    it('ignores a delay that is not a positive number of seconds', () => {
        expect(getAutoCloseSeconds(new Map([['timeout', 'soon']]))).toBeNull();
        expect(getAutoCloseSeconds(new Map([['timeout', '0']]))).toBeNull();
        expect(getAutoCloseSeconds(new Map([['timeout', '-30']]))).toBeNull();
    });
});

describe('Single alert groups', () => {
    const alert = (type: string) => new NotificationAlertItem(['message'], type);

    it('replaces the previous hotel event announcement instead of stacking', () => {
        const first = alert('hotel.event');
        const unrelated = alert('default');
        const second = alert('hotel.event');

        expect(prependSingleAlert([first, unrelated], second)).toEqual([second, unrelated]);
    });

    it('lets a closing announcement replace the event it closes', () => {
        const open = alert('hotel.event');
        const closed = alert('hotel.event.ended');

        expect(prependSingleAlert([open], closed)).toEqual([closed]);
    });

    it('leaves every other alert stacking as before', () => {
        const first = alert('default');
        const second = alert('default');

        expect(prependSingleAlert([first], second)).toEqual([second, first]);
    });
});
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser