5180 fichiers 38.5 Mo 0 téléchargements 272 vues mis à jour il y a 6 heures ui
nitro-v36-with-renderer-v36 / src / api / octane / room / AddAnimationTickerCallback.test.ts
AddAnimationTickerCallback.test.ts 1.6 Ko Télécharger le fichier
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AddAnimationTickerCallback } from './AddAnimationTickerCallback';

const tickerMocks = vi.hoisted(() => ({ add: vi.fn(), remove: vi.fn() }));

vi.mock('@octane/renderer', () => ({
    GetConfiguration: () => ({ getValue: (_key: string, value: unknown) => value }),
    GetTicker: () => tickerMocks
}));

beforeEach(() => vi.clearAllMocks());

describe('AddAnimationTickerCallback', () => {
    it('fires on the first frame and then at the animation clock rate', () => {
        const callback = vi.fn();

        AddAnimationTickerCallback(callback);

        const update = tickerMocks.add.mock.calls[0][0] as (ticker: { deltaMS: number }) => void;

        update({ deltaMS: 0 });

        expect(callback).toHaveBeenCalledTimes(1);

        for (let frame = 0; frame < 60; frame++) update({ deltaMS: 1000 / 60 });

        expect(callback).toHaveBeenCalledTimes(25);
    });

    it('does not replay frames missed while the ticker was stalled', () => {
        const callback = vi.fn();

        AddAnimationTickerCallback(callback);

        const update = tickerMocks.add.mock.calls[0][0] as (ticker: { deltaMS: number }) => void;

        update({ deltaMS: 5000 });
        update({ deltaMS: 1 });

        expect(callback).toHaveBeenCalledTimes(1);
    });

    it('removes its ticker callback on unsubscribe', () => {
        const unsubscribe = AddAnimationTickerCallback(vi.fn());
        const update = tickerMocks.add.mock.calls[0][0];

        unsubscribe();

        expect(tickerMocks.remove).toHaveBeenCalledWith(update);
    });
});
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