<commit_before>import chai from 'chai';
let assert = chai.assert;
import Scene from '../src/scene';
import Tile from '../src/tile';
import sampleScene from './fixtures/sample-scene';


let nycLatLng = [-73.97229909896852, 40.76456761707639, 17];
let midtownTile = { x: 38603, y: 49255, z: 17 };
let midtownTileKey = `${midtownTile.x}/${midtownTile.y}/${midtownTile.z}`;


describe('Scene', function () {

    describe('.constructor()', () => {

        it.skip('returns a new instance', () => {
            let scene = new Scene({});
            assert.instanceOf(scene, Scene);
            scene.destroy();
        });

        describe('when given sensible defaults', () => {
            let scene;
            afterEach(() => {
                scene.destroy();
            });

            it('returns a instance', () => {
                scene = makeScene({});
                assert.instanceOf(scene, Scene);
            });
        });
    });



    describe('.loadQueuedTiles()', () => {
        let subject;

        beforeEach((done) => {
            let coords = midtownTile;

            subject = makeScene({});

            sinon.spy(subject, '_loadTile');

            subject.setCenter(...nycLatLng);
            subject.init().then(() => {
                subject.loadTile(coords);
                subject.loadQueuedTiles();
                done();
            });
        });

        afterEach(() => {
            subject.destroy();
            subject = null;
        });

        it('calls _loadTile with the queued tile', () => {
            sinon.assert.calledOnce(subject._loadTile);
        });
    });



    describe('._loadTile(coords, options)', () => {
        let subject,
            coord = midtownTile,
            div = document.createElement('div');

        beforeEach((done) => {
            subject = makeScene({});
            subject.setCenter(...nycLatLng);
            subject.init().then(done);
        });

        afterEach(() => {
            subject.destroy();
            subject = null;
        });

        describe('when the scene has not loaded the tile', () => {

            it('loads the tile', () => {
                let tile = subject._loadTile(coord, { debugElement: div });
                assert.instanceOf(tile, Tile);
            });

            it('caches the result in the scene object', () => {
                let tile = subject._loadTile(coord, { debugElement: div });
                let tiles = subject.tiles;
                assert.instanceOf(tiles[tile.key], Tile);
            });
        });

        describe('when the scene already have the tile', () => {
            let key = midtownTileKey;
            let tile;

            beforeEach(() => {
                subject.tiles[key] = {};
                sinon.spy(subject, 'cacheTile');
                tile = subject._loadTile(coord, { debugElement: div });
            });

            afterEach(() => {
                subject.cacheTile.restore();
                subject.tiles[key] = undefined;
            });

            it('updates the div', () => {
                assert.equal(div.getAttribute('data-tile-key'), key);
            });
        });

    });

    describe('.create(options)', () => {
        let subject;

        beforeEach(() => {
            subject = makeScene({});

        });

        afterEach( () => {
            subject.destroy();
            subject = null;
        });

        it('returns a new instance', () => {
            assert.instanceOf(subject, Scene);
        });

        it('correctly sets the value of the layers object', () => {
            assert.equal(subject.layer_source, sampleScene.layers);
        });

        it('correctly sets the value of the config object', () => {
            assert.equal(subject.config_source, sampleScene.config);
        });


    });

    describe('.init()', () => {

        describe('when the scene is not initialized', () => {
            let subject;
            beforeEach((done) => {
                subject = makeScene({});
                subject.init().then(done);

            });

            afterEach(() => {
                subject.destroy();
                subject = null;
            });

            it('correctly sets the value of the tile source', () => {

                let source = subject.sources.get('osm');

                assert.propertyVal(source, 'max_zoom', 20);
                assert.propertyVal(source, 'url_template', 'http://vector.mapzen.com/osm/all/{z}/{x}/{y}.json');
            });

            it('sets the initialized property', () => {
                assert.isTrue(subject.initialized);
            });

            it('sets the container property', () => {
                assert.instanceOf(subject.container, HTMLBodyElement);
            });

            it('sets the canvas property', () => {
                assert.instanceOf(subject.canvas, HTMLCanvasElement);
            });

            it('sets the gl property', () => {
                assert.instanceOf(subject.gl, WebGLRenderingContext);<commit_msg>Update the tests<commit_after>import chai from 'chai';
let assert = chai.assert;
import Scene from '../src/scene';
import Tile from '../src/tile';
import sampleScene from './fixtures/sample-scene';


let nycLatLng = [-73.97229909896852, 40.76456761707639, 17];
let midtownTile = { x: 38603, y: 49255, z: 17 };
let midtownTileKey = `${midtownTile.x}/${midtownTile.y}/${midtownTile.z}`;


describe('Scene', function () {

    describe('.constructor()', () => {

        it.skip('returns a new instance', () => {
            let scene = new Scene({});
            assert.instanceOf(scene, Scene);
            scene.destroy();
        });

        describe('when given sensible defaults', () => {
            let scene;
            afterEach(() => {
                scene.destroy();
            });

            it('returns a instance', () => {
                scene = makeScene({});
                assert.instanceOf(scene, Scene);
            });
        });
    });



    describe('.loadQueuedTiles()', () => {
        let subject;

        beforeEach((done) => {
            let coords = midtownTile;

            subject = makeScene({});

            sinon.spy(subject, '_loadTile');

            subject.setCenter(...nycLatLng);
            subject.init().then(() => {
                subject.loadTile(coords);
                subject.loadQueuedTiles();
                done();
            });
        });

        afterEach(() => {
            subject.destroy();
            subject = null;
        });

        it('calls _loadTile with the queued tile', () => {
            sinon.assert.calledOnce(subject._loadTile);
        });
    });



    describe('._loadTile(coords, options)', () => {
        let subject,
            coord = midtownTile,
            div = document.createElement('div');

        beforeEach((done) => {
            subject = makeScene({});
            subject.setCenter(...nycLatLng);
            subject.init().then(done);
        });

        afterEach(() => {
            subject.destroy();
            subject = null;
        });

        describe('when the scene has not loaded the tile', () => {

            it('loads the tile', () => {
                let tile = subject._loadTile(coord, { debugElement: div });
                assert.instanceOf(tile, Tile);
            });

            it('caches the result in the scene object', () => {
                let tile = subject._loadTile(coord, { debugElement: div });
                let tiles = subject.tiles;
                assert.instanceOf(tiles[tile.key], Tile);
            });
        });

        describe('when the scene already have the tile', () => {
            let key = midtownTileKey;
            let tile;

            beforeEach(() => {
                subject.tiles[key] = {};
                sinon.spy(subject, 'cacheTile');
                tile = subject._loadTile(coord, { debugElement: div });
            });

            afterEach(() => {
                subject.cacheTile.restore();
                subject.tiles[key] = undefined;
            });

            it('updates the div', () => {
                assert.equal(div.getAttribute('data-tile-key'), key);
            });
        });

    });

    describe('.create(options)', () => {
        let subject;

        beforeEach(() => {
            subject = makeScene({});

        });

        afterEach( () => {
            subject.destroy();
            subject = null;
        });

        it('returns a new instance', () => {
            assert.instanceOf(subject, Scene);
        });

        it('correctly sets the value of the layers object', () => {
            assert.equal(subject.layer_source, sampleScene.layers);
        });

        it('correctly sets the value of the config object', () => {
            assert.equal(subject.config_source, sampleScene.config);
        });


    });

    describe('.init()', () => {

        describe('when the scene is not initialized', () => {
            let subject;
            beforeEach((done) => {
                subject = makeScene({});
                subject.init().then(done);

            });

            afterEach(() => {
                subject.destroy();
                subject = null;
            });

            it('correctly sets the value of the tile source', () => {

                let source = subject.sources['osm'];

                assert.propertyVal(source, 'max_zoom', 20);
                assert.propertyVal(source, 'url_template', 'http://vector.mapzen.com/osm/all/{z}/{x}/{y}.json');
            });

            it('sets the initialized property', () => {
                assert.isTrue(subject.initialized);
            });

            it('sets the container property', () => {
                assert.instanceOf(subject.container, HTMLBodyElement);
            });

            it('sets the canvas property', () => {
                assert.instanceOf(subject.canvas, HTMLCanvasElement);
            });

            it('sets the gl property', () => {
                assert.instanceOf(subject.gl, WebGLRenderingContext);
{'fraction_non_alphanumeric': 0.15409642117716651, 'fraction_numerical': 0.009464655427388346, 'mean_word_length': 1.548743718592965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 73, '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': '2533122', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2560, 'n_words': 531}