<commit_before>import chai from 'chai';
import Scene from '../src/scene';
import {LeafletLayer} from '../src/leaflet_layer';
import sampleScene from './fixtures/sample-scene';
let assert = chai.assert;

let map = L.map(
    document.createElement('div'),
    { maxZoom: 20, inertia: false, keyboard: false}
);
map.setView([0, 0], 0);

let makeOne = () => {
    return new LeafletLayer({
        vectorTileSource: sampleScene.tileSource,
        vectorLayers: sampleScene.layers,
        vectorStyles: sampleScene.styles
    });
};

describe('Leaflet plugin', () => {

    // leaflet calls it .initialize()
    describe('.constructor()', () => {
        let subject;

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

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

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

        it('wires up the scene', () => {
            assert.instanceOf(subject.scene, Scene);
        });
    });

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

        beforeEach((done) => {
            subject = makeOne();
            sinon.spy(map, 'getContainer');
            subject.on('init', function() {
                done();
            });
            subject.addTo(map);
        });

        afterEach(() => {
            subject.remove();
            map.getContainer.restore();
        });

        it('calls the map\'s .getContainer() method', () => {
            sinon.assert.called(map.getContainer);
        });

    });

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

        beforeEach((done) => {
            subject = makeOne();
            scene = subject.scene;

            sinon.spy(L.GridLayer.prototype, 'onRemove');
            sinon.spy(scene, 'destroy');

            subject.on('init', () => {
                subject.remove();
            });

            map.on('layerremove', () => {
                done();
            });

            subject.addTo(map);
        });

        afterEach(() => {
            L.GridLayer.prototype.onRemove.restore();
        });

        // it('calls the .super', () => {
        //     assert.isTrue(L.GridLayer.prototype.onRemove.called);
        // });

        it('destroys the scene', () => {
            assert.isTrue(scene.destroy.called);
            assert.isNull(subject.scene);
        });
    });

    describe('.createTile(coords, done)', () => {
        let subject;
        let coords = { x: 9647, y: 12320, z: 15 };

        beforeEach(() => {
            subject = makeOne();
            sinon.spy(subject.scene, 'loadTile');<commit_msg>leaflet layer remove test<commit_after>import chai from 'chai';
import Scene from '../src/scene';
import {LeafletLayer} from '../src/leaflet_layer';
import sampleScene from './fixtures/sample-scene';
let assert = chai.assert;

let map = L.map(
    document.createElement('div'),
    { maxZoom: 20, inertia: false, keyboard: false}
);
map.setView([0, 0], 0);

let makeOne = () => {
    return new LeafletLayer({
        vectorTileSource: sampleScene.tileSource,
        vectorLayers: sampleScene.layers,
        vectorStyles: sampleScene.styles
    });
};

describe('Leaflet plugin', () => {

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

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

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

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

        it('wires up the scene', () => {
            assert.instanceOf(subject.scene, Scene);
        });
    });

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

        beforeEach((done) => {
            subject = makeOne();
            sinon.spy(map, 'getContainer');
            subject.on('init', function() {
                done();
            });
            subject.addTo(map);
        });

        afterEach(() => {
            subject.remove();
            map.getContainer.restore();
        });

        it('calls the map\'s .getContainer() method', () => {
            sinon.assert.called(map.getContainer);
        });

    });

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

        beforeEach((done) => {
            subject = makeOne();
            scene = subject.scene;

            sinon.spy(L.GridLayer.prototype, 'onRemove');
            sinon.spy(scene, 'destroy');

            subject.on('init', () => {
                subject.remove();
            });

            subject.on('remove', () => {
                done();
            });

            subject.addTo(map);
        });

        afterEach(() => {
            L.GridLayer.prototype.onRemove.restore();
        });

        it('calls the .super', () => {
            assert.isTrue(L.GridLayer.prototype.onRemove.called);
        });

        it('destroys the scene', () => {
            assert.isTrue(scene.destroy.called);
            assert.isNull(subject.scene);
        });
    });

    describe('.createTile(coords, done)', () => {
        let subject;
        let coords = { x: 9647, y: 12320, z: 15 };

        beforeEach(() => {
            subject = makeOne();
            sinon.spy(subject.scene, 'loadTile');
{'fraction_non_alphanumeric': 0.17036063110443275, 'fraction_numerical': 0.006010518407212622, 'mean_word_length': 1.7099236641221374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '894345', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1469, 'n_words': 270}