From cc508f6ea880de26999ec0cb37ab83dd859532e8 Mon Sep 17 00:00:00 2001
From: Kid Commit <26439946+ferdicus@users.noreply.github.com>
Date: Fri, 10 Jan 2020 14:24:42 +0100
Subject: [PATCH] test: add some for backgroundlayer (#591)
* add tests for Backgroundlayer
* linting
---
__tests__/components/BackgroundLayer.test.js | 52 +++++++++++++++++++
.../offline/OfflineCreatePackOptions.test.js | 5 +-
__tests__/modules/offline/OfflinePack.test.js | 5 +-
.../modules/offline/offlineManager.test.js | 5 +-
.../modules/snapshot/SnapshotOptions.test.js | 5 +-
__tests__/utils/BridgeValue.test.js | 30 ++++++++---
javascript/components/BackgroundLayer.js | 8 ++-
javascript/utils/BridgeValue.js | 4 +-
8 files changed, 100 insertions(+), 14 deletions(-)
create mode 100644 __tests__/components/BackgroundLayer.test.js
diff --git a/__tests__/components/BackgroundLayer.test.js b/__tests__/components/BackgroundLayer.test.js
new file mode 100644
index 000000000..28896a083
--- /dev/null
+++ b/__tests__/components/BackgroundLayer.test.js
@@ -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();
+
+ 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();
+ 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},
+ },
+ });
+ });
+});
diff --git a/__tests__/modules/offline/OfflineCreatePackOptions.test.js b/__tests__/modules/offline/OfflineCreatePackOptions.test.js
index ff9a86b2d..b507296c7 100644
--- a/__tests__/modules/offline/OfflineCreatePackOptions.test.js
+++ b/__tests__/modules/offline/OfflineCreatePackOptions.test.js
@@ -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: {
diff --git a/__tests__/modules/offline/OfflinePack.test.js b/__tests__/modules/offline/OfflinePack.test.js
index 204c2a9b0..0e3704c78 100644
--- a/__tests__/modules/offline/OfflinePack.test.js
+++ b/__tests__/modules/offline/OfflinePack.test.js
@@ -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"}',
};
diff --git a/__tests__/modules/offline/offlineManager.test.js b/__tests__/modules/offline/offlineManager.test.js
index fed3ef88c..7e6937883 100644
--- a/__tests__/modules/offline/offlineManager.test.js
+++ b/__tests__/modules/offline/offlineManager.test.js
@@ -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,
};
diff --git a/__tests__/modules/snapshot/SnapshotOptions.test.js b/__tests__/modules/snapshot/SnapshotOptions.test.js
index 83aae150f..fa222777f 100644
--- a/__tests__/modules/snapshot/SnapshotOptions.test.js
+++ b/__tests__/modules/snapshot/SnapshotOptions.test.js
@@ -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,
diff --git a/__tests__/utils/BridgeValue.test.js b/__tests__/utils/BridgeValue.test.js
index cef34d1fa..be002e4eb 100644
--- a/__tests__/utils/BridgeValue.test.js
+++ b/__tests__/utils/BridgeValue.test.js
@@ -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},
+ ],
});
});
@@ -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},
+ ],
});
});
@@ -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},
+ ],
],
},
{
@@ -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},
+ ],
],
},
],
@@ -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},
+ ],
],
});
});
diff --git a/javascript/components/BackgroundLayer.js b/javascript/components/BackgroundLayer.js
index 4f3ffcbe7..3f690e0d3 100644
--- a/javascript/components/BackgroundLayer.js
+++ b/javascript/components/BackgroundLayer.js
@@ -74,7 +74,13 @@ class BackgroundLayer extends AbstractLayer {
};
render() {
- return ;
+ return (
+
+ );
}
}
diff --git a/javascript/utils/BridgeValue.js b/javascript/utils/BridgeValue.js
index 3272d960a..a4c21a2d6 100644
--- a/javascript/utils/BridgeValue.js
+++ b/javascript/utils/BridgeValue.js
@@ -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`,
);
}