<commit_before>import Layer, {inView} from '../../../../../src/ol/layer/Layer.js';
import Map from '../../../../../src/ol/Map.js';
import RenderEvent from '../../../../../src/ol/render/Event.js';
import Source from '../../../../../src/ol/source/Source.js';
import {get as getProjection} from '../../../../../src/ol/proj.js';

describe('ol.layer.Layer', function () {
  describe('constructor (defaults)', function () {
    let layer;

    beforeEach(function () {
      layer = new Layer({
        source: new Source({
          projection: getProjection('EPSG:4326'),
        }),
      });
    });

    afterEach(function () {
      layer.dispose();
    });

    it('creates an instance', function () {
      expect(layer).to.be.a(Layer);
    });

    it('provides default opacity', function () {
      expect(layer.getOpacity()).to.be(1);
    });

    it('provides default visibility', function () {
      expect(layer.getVisible()).to.be(true);
    });

    it('provides default max resolution', function () {
      expect(layer.getMaxResolution()).to.be(Infinity);
    });

    it('provides default min resolution', function () {
      expect(layer.getMinResolution()).to.be(0);
    });

    it('provides default min zoom', function () {
      expect(layer.getMinZoom()).to.be(-Infinity);
    });

    it('provides default max zoom', function () {
      expect(layer.getMaxZoom()).to.be(Infinity);
    });

    it('provides default layerState', function () {
      expect(layer.getLayerState()).to.eql({
        layer: layer,
        opacity: 1,
        visible: true,
        managed: true,
        sourceState: 'ready',
        extent: undefined,
        zIndex: 0,
        maxResolution: Infinity,
        minResolution: 0,
        minZoom: -Infinity,
        maxZoom: Infinity,
      });
    });
  });

  describe('constructor (options)', function () {
    it('accepts options', function () {
      const layer = new Layer({
        source: new Source({
          projection: getProjection('EPSG:4326'),
        }),
        opacity: 0.5,
        visible: false,
        zIndex: 10,
        maxResolution: 500,
        minResolution: 0.25,
        minZoom: 1,
        maxZoom: 10,
        foo: 42,
      });

      expect(layer.getOpacity()).to.be(0.5);
      expect(layer.getVisible()).to.be(false);
      expect(layer.getMaxResolution()).to.be(500);
      expect(layer.getMinResolution()).to.be(0.25);
      expect(layer.getMinZoom()).to.be(1);
      expect(layer.getMaxZoom()).to.be(10);
      expect(layer.get('foo')).to.be(42);
      expect(layer.getLayerState()).to.eql({
        layer: layer,
        opacity: 0.5,
        visible: false,
        managed: true,
        sourceState: 'ready',
        extent: undefined,
        zIndex: 10,
        maxResolution: 500,
        minResolution: 0.25,
        minZoom: 1,
        maxZoom: 10,
      });

      layer.dispose();
    });

    it('assigns key-value pairs of `properties` to the object', function () {
      const o = new Layer({
        properties: {
          foo: 'bar',
        },
      });
      expect(o.get('foo')).to.be('bar');
      expect(o.get('properties')).to.be(undefined);
    });

    it('throws on non-numeric opacity', function () {
      function create() {
        new Layer({
          source: new Source({
            projection: 'EPSG:4326',<commit_msg>Verify that users can provide a properties property<commit_after>import Layer, {inView} from '../../../../../src/ol/layer/Layer.js';
import Map from '../../../../../src/ol/Map.js';
import RenderEvent from '../../../../../src/ol/render/Event.js';
import Source from '../../../../../src/ol/source/Source.js';
import {get as getProjection} from '../../../../../src/ol/proj.js';

describe('ol.layer.Layer', function () {
  describe('constructor (defaults)', function () {
    let layer;

    beforeEach(function () {
      layer = new Layer({
        source: new Source({
          projection: getProjection('EPSG:4326'),
        }),
      });
    });

    afterEach(function () {
      layer.dispose();
    });

    it('creates an instance', function () {
      expect(layer).to.be.a(Layer);
    });

    it('provides default opacity', function () {
      expect(layer.getOpacity()).to.be(1);
    });

    it('provides default visibility', function () {
      expect(layer.getVisible()).to.be(true);
    });

    it('provides default max resolution', function () {
      expect(layer.getMaxResolution()).to.be(Infinity);
    });

    it('provides default min resolution', function () {
      expect(layer.getMinResolution()).to.be(0);
    });

    it('provides default min zoom', function () {
      expect(layer.getMinZoom()).to.be(-Infinity);
    });

    it('provides default max zoom', function () {
      expect(layer.getMaxZoom()).to.be(Infinity);
    });

    it('provides default layerState', function () {
      expect(layer.getLayerState()).to.eql({
        layer: layer,
        opacity: 1,
        visible: true,
        managed: true,
        sourceState: 'ready',
        extent: undefined,
        zIndex: 0,
        maxResolution: Infinity,
        minResolution: 0,
        minZoom: -Infinity,
        maxZoom: Infinity,
      });
    });
  });

  describe('constructor (options)', function () {
    it('accepts options', function () {
      const layer = new Layer({
        source: new Source({
          projection: getProjection('EPSG:4326'),
        }),
        opacity: 0.5,
        visible: false,
        zIndex: 10,
        maxResolution: 500,
        minResolution: 0.25,
        minZoom: 1,
        maxZoom: 10,
        foo: 42,
      });

      expect(layer.getOpacity()).to.be(0.5);
      expect(layer.getVisible()).to.be(false);
      expect(layer.getMaxResolution()).to.be(500);
      expect(layer.getMinResolution()).to.be(0.25);
      expect(layer.getMinZoom()).to.be(1);
      expect(layer.getMaxZoom()).to.be(10);
      expect(layer.get('foo')).to.be(42);
      expect(layer.getLayerState()).to.eql({
        layer: layer,
        opacity: 0.5,
        visible: false,
        managed: true,
        sourceState: 'ready',
        extent: undefined,
        zIndex: 10,
        maxResolution: 500,
        minResolution: 0.25,
        minZoom: 1,
        maxZoom: 10,
      });

      layer.dispose();
    });

    it('assigns key-value pairs of `properties` to the object', function () {
      const o = new Layer({
        properties: {
          foo: 'bar',
        },
      });
      expect(o.get('foo')).to.be('bar');
      expect(o.get('properties')).to.be(undefined);
    });

    it('can have a `properties` property', function () {
      const o = new Layer({
        properties: {
          properties: {foo: 'bar'},
        },
      });
      expect(o.get('properties')).to.eql({foo: 'bar'});
    });

    it('throws on non-numeric opacity', function () {
      function create() {
        new Layer({
          source: new Source({
            projection: 'EPSG:4326',
{'fraction_non_alphanumeric': 0.18111254851228978, 'fraction_numerical': 0.01667385367256001, 'mean_word_length': 2.1328230526789733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7046237', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2103, 'n_words': 424}