Skip to content

Commit

Permalink
[Maps] fix tile layer attibution text and attribution link validation…
Browse files Browse the repository at this point in the history
… errors (elastic#73160) (elastic#73173)

* [Maps] fix tile layer attibution text and attribution link validation errors

* clean up jest test

* tslint

* one more tslint
  • Loading branch information
nreese authored Jul 24, 2020
1 parent 64fe509 commit 476f6f0
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 59 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export const tmsLayerWizardConfig: LayerWizard = {
}),
icon: 'grid',
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: XYZTMSSourceConfig) => {
const onSourceConfigChange = (sourceConfig: XYZTMSSourceConfig | null) => {
if (!sourceConfig) {
previewLayers([]);
return;
}

const layerDescriptor = TileLayer.createDescriptor({
sourceDescriptor: XYZTMSSource.createDescriptor(sourceConfig),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { shallow } from 'enzyme';
import { XYZTMSEditor } from './xyz_tms_editor';

const onSourceConfigChange = () => {};

test('should render', () => {
const component = shallow(<XYZTMSEditor onSourceConfigChange={onSourceConfigChange} />);
expect(component).toMatchSnapshot();
});

describe('attribution validation', () => {
test('should provide validation error when attribution text is provided without attribution url', () => {
const component = shallow(<XYZTMSEditor onSourceConfigChange={onSourceConfigChange} />);
component.setState({ attributionText: 'myAttribtionLabel' });
expect(component).toMatchSnapshot();
});

test('should provide validation error when attribution url is provided without attribution text', () => {
const component = shallow(<XYZTMSEditor onSourceConfigChange={onSourceConfigChange} />);
component.setState({ attributionUrl: 'http://mySource' });
expect(component).toMatchSnapshot();
});

test('should provide no validation errors when attribution text and attribution url are provided', () => {
const component = shallow(<XYZTMSEditor onSourceConfigChange={onSourceConfigChange} />);
component.setState({ attributionText: 'myAttribtionLabel' });
component.setState({ attributionUrl: 'http://mySource' });
expect(component).toMatchSnapshot();
});
});
Loading

0 comments on commit 476f6f0

Please sign in to comment.