Skip to content

Commit

Permalink
test: add some for backgroundlayer (#591)
Browse files Browse the repository at this point in the history
* add tests for Backgroundlayer

* linting
  • Loading branch information
ferdicus authored and kristfal committed Jan 10, 2020
1 parent 4a93b5a commit cc508f6
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 14 deletions.
52 changes: 52 additions & 0 deletions __tests__/components/BackgroundLayer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import {render} from 'react-native-testing-library';

import BackgroundLayer from '../../javascript/components/BackgroundLayer';

export const NATIVE_MODULE_NAME = 'RCTMGLBackgroundLayer';

describe('BackgroundLayer', () => {
test('renders correctly with default props', () => {
const {queryByTestId} = render(<BackgroundLayer />);

const backgroundLayer = queryByTestId('rctmglBackgroundLayer');
const {props} = backgroundLayer;

expect(props.sourceID).toStrictEqual('DefaultSourceID');
});

test('renders correctly with custom props', () => {
const testProps = {
id: 'customId',
sourceID: 'customSourceId',
sourceLayerID: 'customSourceLayerId',
aboveLayerID: 'customAboveLayerId',
belowLayerID: 'customBelowLayerId',
layerIndex: 0,
filter: ['==', 'arbitraryFilter', true],
minZoomLevel: 3,
maxZoomLevel: 8,
style: {visibility: 'none'},
};

const {queryByTestId} = render(<BackgroundLayer {...testProps} />);
const backgroundLayer = queryByTestId('rctmglBackgroundLayer');
const {props} = backgroundLayer;

expect(props.id).toStrictEqual(testProps.id);
expect(props.sourceID).toStrictEqual(testProps.sourceID);
expect(props.sourceLayerID).toStrictEqual(testProps.sourceLayerID);
expect(props.aboveLayerID).toStrictEqual(testProps.aboveLayerID);
expect(props.belowLayerID).toStrictEqual(testProps.belowLayerID);
expect(props.layerIndex).toStrictEqual(testProps.layerIndex);
expect(props.filter).toStrictEqual(testProps.filter);
expect(props.minZoomLevel).toStrictEqual(testProps.minZoomLevel);
expect(props.maxZoomLevel).toStrictEqual(testProps.maxZoomLevel);
expect(props.reactStyle).toStrictEqual({
visibility: {
styletype: 'constant',
stylevalue: {type: 'string', value: testProps.style.visibility},
},
});
});
});
5 changes: 4 additions & 1 deletion __tests__/modules/offline/OfflineCreatePackOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ describe('OfflineCreatePackOptions', () => {
const options = {
name: 'test',
styleURL: 'mapbox://fake-style-url',
bounds: [[0, 1], [2, 3]],
bounds: [
[0, 1],
[2, 3],
],
minZoom: 1,
maxZoom: 22,
metadata: {
Expand Down
5 changes: 4 additions & 1 deletion __tests__/modules/offline/OfflinePack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import OfflinePack from '../../../javascript/modules/offline/OfflinePack';

describe('OfflinePack', () => {
const fakeNativePack = {
bounds: [[0, 1], [2, 3]],
bounds: [
[0, 1],
[2, 3],
],
metadata: '{"name":"test"}',
};

Expand Down
5 changes: 4 additions & 1 deletion __tests__/modules/offline/offlineManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe('offlineManager', () => {
const packOptions = {
name: 'test',
styleURL: 'mapbox://fake-style-url',
bounds: [[0, 1], [2, 3]],
bounds: [
[0, 1],
[2, 3],
],
minZoom: 1,
maxZoom: 22,
};
Expand Down
5 changes: 4 additions & 1 deletion __tests__/modules/snapshot/SnapshotOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ describe('SnapshotOptions', () => {

it('should create options with bounds', () => {
const expectedOptions = {
bounds: [[1, 2], [3, 4]],
bounds: [
[1, 2],
[3, 4],
],
width: 400,
height: 600,
styleURL: NativeModules.MGLModule.StyleURL.Light,
Expand Down
30 changes: 24 additions & 6 deletions __tests__/utils/BridgeValue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ describe('BridgeValue', () => {
const bridgeValue = new BridgeValue([1, 2]);
expect(bridgeValue.toJSON()).toEqual({
type: 'array',
value: [{type: 'number', value: 1}, {type: 'number', value: 2}],
value: [
{type: 'number', value: 1},
{type: 'number', value: 2},
],
});
});

Expand All @@ -24,7 +27,10 @@ describe('BridgeValue', () => {
const bridgeValue = new BridgeValue([true, false]);
expect(bridgeValue.toJSON()).toEqual({
type: 'array',
value: [{type: 'boolean', value: true}, {type: 'boolean', value: false}],
value: [
{type: 'boolean', value: true},
{type: 'boolean', value: false},
],
});
});

Expand All @@ -40,7 +46,10 @@ describe('BridgeValue', () => {
{
type: 'hashmap',
value: [
[{type: 'string', value: 'prop1'}, {type: 'number', value: 1}],
[
{type: 'string', value: 'prop1'},
{type: 'number', value: 1},
],
],
},
{
Expand All @@ -55,7 +64,10 @@ describe('BridgeValue', () => {
{
type: 'hashmap',
value: [
[{type: 'string', value: 'prop3'}, {type: 'boolean', value: false}],
[
{type: 'string', value: 'prop3'},
{type: 'boolean', value: false},
],
],
},
],
Expand Down Expand Up @@ -144,8 +156,14 @@ describe('BridgeValue', () => {
expect(bridgeValue.toJSON()).toEqual({
type: 'hashmap',
value: [
[{type: 'string', value: 'prop1'}, {type: 'string', value: 'value1'}],
[{type: 'string', value: 'prop2'}, {type: 'number', value: 2}],
[
{type: 'string', value: 'prop1'},
{type: 'string', value: 'value1'},
],
[
{type: 'string', value: 'prop2'},
{type: 'number', value: 2},
],
],
});
});
Expand Down
8 changes: 7 additions & 1 deletion javascript/components/BackgroundLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class BackgroundLayer extends AbstractLayer {
};

render() {
return <RCTMGLBackgroundLayer ref="nativeLayer" {...this.baseProps} />;
return (
<RCTMGLBackgroundLayer
testID="rctmglBackgroundLayer"
ref="nativeLayer"
{...this.baseProps}
/>
);
}
}

Expand Down
4 changes: 1 addition & 3 deletions javascript/utils/BridgeValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export default class BridgeValue {
value = this.rawValue;
} else {
throw new Error(
`[value - ${
this.rawValue
}] BridgeValue must be a primitive/array/object`,
`[value - ${this.rawValue}] BridgeValue must be a primitive/array/object`,
);
}

Expand Down

0 comments on commit cc508f6

Please sign in to comment.