<commit_before>import React from 'react';
import L from 'leaflet';
import { shallow } from 'enzyme';
import NonTiledLayer from './NonTiledLayer';

jest.mock('leaflet');

describe('NonTiledLayer', () => {
  let wrapper;
  let wrapperInstance;
  const props = {
    url: 'https://wms-url',
    rotationAngle: 0,
    layers: ['wms-layer'],
    opacity: 100
  };

  beforeEach(() => {
    L.nonTiledLayer = {
      wms: jest.fn()
    };

    wrapper = shallow(
      <NonTiledLayer
        {...props}
      />, {
        context: {
          layerContainer: {
            addLayer: jest.fn()
          }
        }
      }
    );
    wrapperInstance = wrapper.instance();
  });

  it('should render everything', () => {
    expect(L.nonTiledLayer.wms).toHaveBeenCalledTimes(1);
    expect(L.nonTiledLayer.wms).toHaveBeenCalledWith(
      props.url,
      {
        rotationAngle: 0,
        layers: ['wms-layer'],
        opacity: 100
      }
    );
  });

  it('should update the layers when the property is changed', () => {
    wrapperInstance.leafletElement = {
      _wmsUrl: 'http://old-wms-url',
      wmsParams: { layers: ['old-layer'] },
      setUrl: jest.fn()
    };

    const fromProps = {
      url: 'http://old-wms-url',
      layers: ['old-layer']
    };
    const toProps = {
      url: 'http://new-wms-url',
      layers: ['new-layer']
    };

    wrapperInstance.updateLeafletElement(fromProps, toProps);
    // eslint-disable-next-line no-underscore-dangle
    expect(wrapperInstance.leafletElement._wmsUrl).toEqual(toProps.url);
  });

  it('should hide the layer', () => {
    wrapperInstance.leafletElement = {
      setOpacity: jest.fn()
    };

    const fromProps = {
      opacity: 100
    };
    const toProps = {
      opacity: 0
    };

    wrapperInstance.updateLeafletElement(fromProps, toProps);
    expect(wrapperInstance.leafletElement.setOpacity).toHaveBeenCalledWith(toProps.opacity);
  });
});

function renderComponent() {
  return shallow(
    <NonTiledLayer
      url="url"
      params={{ test: '123' }}
    />, {
      context: {
        layerContainer: {
          addLayer: jest.fn()
        }
      }
    }
  );
}

describe('NonTiledLayer', () => {
  const props = {
    opacity: 100,
    url: 'https://pano.amsterdam.nl',
    params: {
      mission_type: 'bi',
      mission_year: 2017
    }
  };

  it('should rerender everything when props change', () => {
    const wrapper = renderComponent();
    const setParamsMock = jest.fn();

    wrapper.instance().leafletElement = {
      setParams: setParamsMock,
      setOpacity: jest.fn(),
      setUrl: jest.fn(),
      wmsParams: {}
    };

    wrapper.instance().updateLeafletElement({ props }, { props });
    expect(setParamsMock).not.toHaveBeenCalled();

    wrapper.instance().updateLeafletElement({ props }, { ...props, params: { mission_type: 'WOZ', mission_year: 2018 } });
    expect(setParamsMock).toHaveBeenCalled();
  });

  it('should rerender everything when props change', () => {
    const wrapper = renderComponent();
    const setParamsMock = jest.fn();

    wrapper.instance().leafletElement = {
      setParams: setParamsMock,
      setOpacity: jest.fn(),
      setUrl: jest.fn()
    };

    wrapper.instance().updateLeafletElement({ props }, { props });
    expect(setParamsMock).not.toHaveBeenCalled();

    wrapper.instance().updateLeafletElement({ props }, { ...props, params: { mission_type: 'WOZ', mission_year: 2018 } });
    expect(setParamsMock).toHaveBeenCalled();
  });
});<commit_msg>Unittests fixed<commit_after>import React from 'react';
import L from 'leaflet';
import { shallow } from 'enzyme';
import NonTiledLayer from './NonTiledLayer';

jest.mock('leaflet');

describe('NonTiledLayer', () => {
  let wrapper;
  let wrapperInstance;
  const props = {
    url: 'https://wms-url',
    rotationAngle: 0,
    layers: ['wms-layer'],
    opacity: 100
  };

  beforeEach(() => {
    L.nonTiledLayer = {
      wms: jest.fn()
    };

    wrapper = shallow(
      <NonTiledLayer
        {...props}
      />, {
        context: {
          layerContainer: {
            addLayer: jest.fn()
          }
        }
      }
    );
    wrapperInstance = wrapper.instance();
  });

  it('should render everything', () => {
    expect(L.nonTiledLayer.wms).toHaveBeenCalledTimes(1);
    expect(L.nonTiledLayer.wms).toHaveBeenCalledWith(
      props.url,
      {
        rotationAngle: 0,
        layers: ['wms-layer'],
        opacity: 100
      }
    );
  });

  it('should update the layers when the property is changed', () => {
    wrapperInstance.leafletElement = {
      _wmsUrl: 'http://old-wms-url',
      wmsParams: { layers: ['old-layer'] },
      setUrl: jest.fn()
    };

    const fromProps = {
      url: 'http://old-wms-url',
      layers: ['old-layer']
    };
    const toProps = {
      url: 'http://new-wms-url',
      layers: ['new-layer']
    };

    wrapperInstance.updateLeafletElement(fromProps, toProps);
    // eslint-disable-next-line no-underscore-dangle
    expect(wrapperInstance.leafletElement._wmsUrl).toEqual(toProps.url);
  });

  it('should hide the layer', () => {
    wrapperInstance.leafletElement = {
      setOpacity: jest.fn()
    };

    const fromProps = {
      opacity: 100
    };
    const toProps = {
      opacity: 0
    };

    wrapperInstance.updateLeafletElement(fromProps, toProps);
    expect(wrapperInstance.leafletElement.setOpacity).toHaveBeenCalledWith(toProps.opacity);
  });
});

function renderComponent() {
  return shallow(
    <NonTiledLayer
      url="url"
      params={{ test: '123' }}
    />, {
      context: {
        layerContainer: {
          addLayer: jest.fn()
        }
      }
    }
  );
}

describe('NonTiledLayer', () => {
  const props = {
    opacity: 100,
    url: 'https://pano.amsterdam.nl',
    params: {
      mission_type: 'bi',
      mission_year: 2017
    }
  };

  it('should rerender everything when props change', () => {
    const wrapper = renderComponent();
    const setParamsMock = jest.fn();

    wrapper.instance().leafletElement = {
      setParams: setParamsMock,
      setOpacity: jest.fn(),
      setUrl: jest.fn(),
      wmsParams: {}
    };

    wrapper.instance().updateLeafletElement({ props }, { props });
    expect(setParamsMock).not.toHaveBeenCalled();

    wrapper.instance().updateLeafletElement({ props }, { ...props, params: { mission_type: 'WOZ', mission_year: 2018 } });
    expect(setParamsMock).toHaveBeenCalled();
  });
});
{'fraction_non_alphanumeric': 0.15538342370255614, 'fraction_numerical': 0.00898528272656855, 'mean_word_length': 2.5668508287292817, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 4, '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': '5760245', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2035, 'n_words': 369}