|  | 
|  | 1 | +import Clip from '../../../../src/animation/Clip'; | 
|  | 2 | +import easingFuncs from '../../../../src/animation/easing'; | 
|  | 3 | + | 
|  | 4 | +describe('clip', function () { | 
|  | 5 | +    const life = 2000; | 
|  | 6 | +    const interval = 200; | 
|  | 7 | +    const delay = 300; | 
|  | 8 | +    /** '2022/12/22 00:42:45' */ | 
|  | 9 | +    const now = 1671640965219; | 
|  | 10 | +    it('normal clip call onframe correct', () => { | 
|  | 11 | +        const onframe = jest.fn(); | 
|  | 12 | +        const attClip = new Clip({ | 
|  | 13 | +            life, | 
|  | 14 | +            onframe | 
|  | 15 | +        }); | 
|  | 16 | +        attClip.step(now, 100); | 
|  | 17 | +        attClip.step(now + interval, 100); | 
|  | 18 | +        attClip.step(now + interval + life, 100); | 
|  | 19 | +        expect(onframe).toHaveBeenNthCalledWith(1, 0); | 
|  | 20 | +        expect(onframe).toHaveBeenNthCalledWith(2, interval / life); | 
|  | 21 | +        expect(onframe).toHaveBeenNthCalledWith(3, 1); | 
|  | 22 | +    }); | 
|  | 23 | + | 
|  | 24 | +    it('delay clip call onframe correct', () => { | 
|  | 25 | +        const onframe = jest.fn(); | 
|  | 26 | + | 
|  | 27 | +        const attClip = new Clip({ | 
|  | 28 | +            life, | 
|  | 29 | +            onframe, | 
|  | 30 | +            delay | 
|  | 31 | +        }); | 
|  | 32 | +        attClip.step(now, 100); | 
|  | 33 | +        attClip.step(now + interval, 100); | 
|  | 34 | +        attClip.step(now + interval + delay, 100); | 
|  | 35 | +        expect(onframe).toHaveBeenNthCalledWith(1, 0); | 
|  | 36 | +        expect(onframe).toHaveBeenNthCalledWith(2, 0); | 
|  | 37 | +        expect(onframe).toHaveBeenNthCalledWith(3, interval / life); | 
|  | 38 | +    }); | 
|  | 39 | + | 
|  | 40 | +    it('loop clip call onframe correct', () => { | 
|  | 41 | +        const onframe = jest.fn(); | 
|  | 42 | +        const onrestart = jest.fn(); | 
|  | 43 | + | 
|  | 44 | +        const attClip = new Clip({ | 
|  | 45 | +            life, | 
|  | 46 | +            onframe, | 
|  | 47 | +            loop: true, | 
|  | 48 | +            onrestart | 
|  | 49 | +        }); | 
|  | 50 | +        attClip.step(now, 100); | 
|  | 51 | +        attClip.step(now + interval, 100); | 
|  | 52 | +        attClip.step(now + interval + life, 100); | 
|  | 53 | +        attClip.step(now + interval + life + 100, 100); | 
|  | 54 | +        expect(onframe).toHaveBeenNthCalledWith(1, 0); | 
|  | 55 | +        expect(onframe).toHaveBeenNthCalledWith(2, interval / life); | 
|  | 56 | +        expect(onframe).toHaveBeenNthCalledWith(3, 1); | 
|  | 57 | +        expect(onframe).toHaveBeenNthCalledWith(4, (interval + 100) / life); | 
|  | 58 | +        expect(onrestart).toBeCalledTimes(1); | 
|  | 59 | +    }); | 
|  | 60 | + | 
|  | 61 | +    it('clip pause correct', () => { | 
|  | 62 | +        const onframe = jest.fn(); | 
|  | 63 | +        const onrestart = jest.fn(); | 
|  | 64 | + | 
|  | 65 | +        const attClip = new Clip({ | 
|  | 66 | +            life, | 
|  | 67 | +            onframe, | 
|  | 68 | +            loop: true, | 
|  | 69 | +            onrestart | 
|  | 70 | +        }); | 
|  | 71 | +        attClip.pause(); | 
|  | 72 | +        attClip.step(now, interval); | 
|  | 73 | +        attClip.step(now + interval, interval); | 
|  | 74 | +        attClip.resume(); | 
|  | 75 | +        // pause two interval | 
|  | 76 | +        attClip.step(now + interval + interval + interval, interval); | 
|  | 77 | +        expect(onframe).toBeCalledTimes(1); | 
|  | 78 | +        expect(onframe).toHaveBeenNthCalledWith(1, interval / life); | 
|  | 79 | +    }); | 
|  | 80 | + | 
|  | 81 | +    const buildInEasing = Object.keys(easingFuncs) as Array<keyof typeof easingFuncs>; | 
|  | 82 | + | 
|  | 83 | +    test.each(buildInEasing)('setEasing buildIn %s correct', (easingName) => { | 
|  | 84 | +        const onframe = jest.fn(); | 
|  | 85 | +        const onrestart = jest.fn(); | 
|  | 86 | + | 
|  | 87 | +        const attClip = new Clip({ | 
|  | 88 | +            life, | 
|  | 89 | +            onframe, | 
|  | 90 | +            onrestart | 
|  | 91 | +        }); | 
|  | 92 | +        attClip.setEasing(easingName); | 
|  | 93 | +        /** init */ | 
|  | 94 | +        attClip.step(now, interval); | 
|  | 95 | +        attClip.step(now + interval, interval); | 
|  | 96 | +        attClip.step(now + 2 * interval, interval); | 
|  | 97 | +        expect(onframe).toBeCalledTimes(3); | 
|  | 98 | +        expect(onframe).toHaveBeenNthCalledWith(1, easingFuncs[easingName](0)); | 
|  | 99 | +        expect(onframe).toHaveBeenNthCalledWith(2, easingFuncs[easingName](interval / life)); | 
|  | 100 | +        expect(onframe).toHaveBeenNthCalledWith(3, easingFuncs[easingName](2 * interval / life)); | 
|  | 101 | +    }); | 
|  | 102 | +}); | 
0 commit comments