react-spatial
Version:
Components to build React map apps.
77 lines (69 loc) • 2.56 kB
JavaScript
import React from 'react';
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'jest-canvas-mock';
import Copyright from './Copyright';
import ConfigReader from '../../ConfigReader';
import LayerService from '../../LayerService';
configure({ adapter: new Adapter() });
var initLayerService = function () {
var data = [
{
name: 'OSM Baselayer',
copyright: 'OSM Contributors',
data: {
type: 'xyz',
url: 'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png',
},
},
{
name: 'OSM Baselayer Hot',
copyright: 'Hot OSM Contributors',
data: {
type: 'xyz',
url: 'https://c.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
},
},
{
name: 'OpenTopoMap',
copyright: 'Some Copyright',
data: {
type: 'xyz',
url: 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png',
},
} ];
var layers = ConfigReader.readConfig(data);
return new LayerService(layers);
};
describe('Copyright', function () {
test('is empty if no layers are visible', function () {
var layerService = initLayerService();
var component = mount(React.createElement( Copyright, { layerService: layerService }));
expect(component.html()).toBe(null);
});
test('displays the correct copyright', function () {
var layerService = initLayerService();
layerService.getLayersAsFlatArray()[1].setVisible(true);
var component = mount(React.createElement( Copyright, { layerService: layerService }));
expect(component.text()).toBe('© Hot OSM Contributors');
});
test('displays a custom copyright', function () {
var layerService = initLayerService();
layerService.getLayersAsFlatArray()[1].setVisible(true);
var component = mount(
React.createElement( Copyright, {
layerService: layerService, format: function (copyrights) { return ("Number of copyrights: " + (copyrights.length)); } })
);
expect(component.text()).toBe('Number of copyrights: 1');
});
test('listens to change events on a new LayerService', function () {
var layerService = initLayerService();
var component = mount(React.createElement( Copyright, { layerService: layerService }));
var newLayerService = initLayerService();
var spy = jest.spyOn(LayerService.prototype, 'on');
component.setProps({ layerService: newLayerService });
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0]).toBe('change:visible');
});
});
//# sourceMappingURL=Copyright.test.js.map