<commit_before>'use strict';

const {shallow, mount} = require('enzyme');
const Animate = require('../../lib/Animate');
const generateRandomSeries = require('../helpers/generateRandomSeries');
const later = require('../helpers/later');

const series1 = generateRandomSeries(3, 5, {type: 'object'});
const series2 = generateRandomSeries(3, 5, {type: 'object'});

describe('Animate', () => {

    it('should render g element and takes a series object', () => {
        const wrapper = shallow(<Animate series={series1} className='animate'>
            <span />
        </Animate>);
        const g = wrapper.find('g');
        expect(g.length).toEqual(1);
        expect(g.prop('className')).toEqual('animate');
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
    });

    pit('should interpolate props', () => {
        const wrapper = mount(<Animate
            series={series1}
            minX={0} maxX={2} minY={0} maxY={100}
            layerWidth={100} layerHeight={100}
            duration={100}>
            <span />
        </Animate>);
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
        jest.useRealTimers();
        wrapper.setProps({
            series: series2,
            minX: 1,
            maxX: 3,
            minY: -50,
            maxY: 50,
            layerWidth: 50,
            layerHeight: 150
        });

        return later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).not.toEqual(series1);
            expect(expectedSeries).not.toEqual(series2);
            if (series1[0].data[0].y < series2[0].data[0].y) {
                expect(expectedSeries[0].data[0].y).toBeGreaterThan(series1[0].data[0].y);
                expect(expectedSeries[0].data[0].y).toBeLessThan(series2[0].data[0].y);
            } else {
                expect(expectedSeries[0].data[0].y).toBeLessThan(series1[0].data[0].y);
                expect(expectedSeries[0].data[0].y).toBeGreaterThan(series2[0].data[0].y);
            }
            expect(span.prop('minX')).toBeGreaterThan(0);
            expect(span.prop('maxX')).toBeGreaterThan(2);
            expect(span.prop('minY')).toBeLessThan(0);
            expect(span.prop('maxY')).toBeLessThan(100);
            expect(span.prop('layerWidth')).toBeLessThan(100);
            expect(span.prop('layerHeight')).toBeGreaterThan(100);

        }, 50).then(() => later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).toEqual(series2);
            expect(span.prop('minX')).toEqual(1);
            expect(span.prop('maxX')).toEqual(3);
            expect(span.prop('minY')).toEqual(-50);
            expect(span.prop('maxY')).toEqual(50);
            expect(span.prop('layerWidth')).toEqual(50);
            expect(span.prop('layerHeight')).toEqual(150);

        }, 100));
    });

    pit('should log FPS metrics', () => {
        const wrapper = mount(<Animate
            series={series1}
            logFPS={true}
            duration={10}>
            <span />
        </Animate>);
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
        jest.useRealTimers();
        let consoleWarn = console.warn;
        console.warn = jasmine.createSpy('console.warn');
        wrapper.setProps({series: series2});

        return later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).toEqual(series2);
            expect(console.warn).toHaveBeenCalled();
            const timer = wrapper.find(Animate).node._timer;
            spyOn(timer, 'stop');
            wrapper.unmount();
            expect(timer.stop).toHaveBeenCalledTimes(1);
            console.warn = consoleWarn;
        }, 50);
    });

});<commit_msg>update unit tests for Animate<commit_after>'use strict';

const {shallow, mount} = require('enzyme');
const Animate = require('../../lib/Animate');
const generateRandomSeries = require('../helpers/generateRandomSeries');
const later = require('../helpers/later');

const series1 = generateRandomSeries(3, 5, {type: 'object'});
const series2 = generateRandomSeries(3, 5, {type: 'object'});

describe('Animate', () => {

    it('should render g element and takes a series object', () => {
        const wrapper = shallow(<Animate series={series1} className='animate'>
            <span />
        </Animate>);
        const g = wrapper.find('g');
        expect(g.length).toEqual(1);
        expect(g.prop('className')).toEqual('animate');
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
    });

    pit('should interpolate props', () => {
        const wrapper = mount(<Animate
            series={series1}
            minX={0} maxX={2} minY={0} maxY={100}
            layerWidth={100} layerHeight={100}
            duration={100}>
            <span />
        </Animate>);
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
        jest.useRealTimers();
        wrapper.setProps({
            series: series2,
            minX: 1,
            maxX: 3,
            minY: -50,
            maxY: 50,
            layerWidth: 50,
            layerHeight: 150
        });

        return later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).not.toEqual(series1);
            expect(expectedSeries).not.toEqual(series2);
            if (series1[0].data[0].y < series2[0].data[0].y) {
                expect(expectedSeries[0].data[0].y).not.toBeLessThan(series1[0].data[0].y);
                expect(expectedSeries[0].data[0].y).not.toBeGreaterThan(series2[0].data[0].y);
            } else {
                expect(expectedSeries[0].data[0].y).not.toBeGreaterThan(series1[0].data[0].y);
                expect(expectedSeries[0].data[0].y).not.toBeLessThan(series2[0].data[0].y);
            }
            expect(span.prop('minX')).not.toBeLessThan(0);
            expect(span.prop('maxX')).not.toBeLessThan(2);
            expect(span.prop('minY')).not.toBeGreaterThan(0);
            expect(span.prop('maxY')).not.toBeGreaterThan(100);
            expect(span.prop('layerWidth')).not.toBeGreaterThan(100);
            expect(span.prop('layerHeight')).not.toBeLessThan(100);

        }, 50).then(() => later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).toEqual(series2);
            expect(span.prop('minX')).toEqual(1);
            expect(span.prop('maxX')).toEqual(3);
            expect(span.prop('minY')).toEqual(-50);
            expect(span.prop('maxY')).toEqual(50);
            expect(span.prop('layerWidth')).toEqual(50);
            expect(span.prop('layerHeight')).toEqual(150);

        }, 100));
    });

    pit('should log FPS metrics', () => {
        const wrapper = mount(<Animate
            series={series1}
            logFPS={true}
            duration={10}>
            <span />
        </Animate>);
        const expectedSeries = wrapper.find('span').prop('series');
        expect(expectedSeries).toEqual(series1);
        jest.useRealTimers();
        let consoleWarn = console.warn;
        console.warn = jasmine.createSpy('console.warn');
        wrapper.setProps({series: series2});

        return later(() => {
            const span = wrapper.find('span');
            const expectedSeries = span.prop('series');
            expect(expectedSeries).toEqual(series2);
            expect(console.warn).toHaveBeenCalled();
            console.warn = consoleWarn;
        }, 50);
    });

    pit('should stop timer on unmount', () => {
        const wrapper = mount(<Animate
            series={series1}
            duration={1}>
            <span />
        </Animate>);

        jest.useRealTimers();
        wrapper.setProps({series: series2});

        return later(() => {
            const timer = wrapper.find(Animate).node._timer;
            spyOn(timer, 'stop');
            wrapper.unmount();
            expect(timer.stop).toHaveBeenCalledTimes(1);
        }, 30);
    });

});
{'fraction_non_alphanumeric': 0.16742930892878094, 'fraction_numerical': 0.024991200281590988, 'mean_word_length': 2.262150784538844, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797933', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2431, 'n_words': 368}