diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..0a3d72c46 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + root: true, + extends: ["universe/native"], + ignorePatterns: ["build"], +}; diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..4b4fd8f99 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +# style: apply formatting via lint:fix +# https://github.com/maplibre/maplibre-react-native/pull/467 +017b3861ae8ac856a3b032ebea6497eff4420e1f \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e5432b5fe..826be06f7 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -18,11 +18,10 @@ Added `your feature` that allows ... - [ ] I have tested this on a device/simulator for each compatible OS -- [ ] I formatted JS and TS files with running `yarn lint:fix` in the root folder +- [ ] I formatted JS and TS files with running `yarn lint:eslint:fix` in the root folder - [ ] I have run tests via `yarn test` in the root folder - [ ] I updated the documentation with running `yarn generate` in the root folder - [ ] I mentioned this change in `CHANGELOG.md` -- [ ] I updated the typings files (`index.d.ts`) - [ ] I added/updated a sample (`/example`) ## Screenshot OR Video diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index c2f33b1ef..24c010fe4 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -24,14 +24,14 @@ jobs: - name: Install run: yarn install --immutable --check-cache - - name: Lint - run: yarn lint + - name: Lint with ESLint + run: yarn lint:eslint - - name: Typescript check - run: yarn typescript:check + - name: Lint with TSC + run: yarn lint:tsc - - name: Test - run: yarn unittest + - name: Run test with Jest + run: yarn test - name: Generate run: yarn generate diff --git a/CHANGELOG.md b/CHANGELOG.md index cdf3b3297..1ca91cb5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ PR Title ([#123](link to my pr)) ``` +fix: allow resetting contentInset with 0 ([#468](https://github.com/maplibre/maplibre-react-native/pull/468)) + ## 10.0.0-alpha.21 fix: Call requestProgress when getting pack status on IOS + example improvement [#445](https://github.com/maplibre/maplibre-react-native/pull/445) diff --git a/__tests__/__mocks__/react-native.mock.js b/__tests__/__mocks__/react-native.mock.js index bf83e302b..cdb8edaad 100644 --- a/__tests__/__mocks__/react-native.mock.js +++ b/__tests__/__mocks__/react-native.mock.js @@ -1,14 +1,16 @@ -jest.mock('react-native/Libraries/Image/resolveAssetSource', () => { - return () => ({uri: 'asset://test.png'}); +jest.mock("react-native/Libraries/Image/resolveAssetSource", () => { + return () => ({ uri: "asset://test.png" }); }); -jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter', () => { +jest.mock("react-native/Libraries/EventEmitter/NativeEventEmitter", () => { function MockEventEmitter() {} - MockEventEmitter.prototype.addListener = jest.fn(() => ({remove: jest.fn()})); + MockEventEmitter.prototype.addListener = jest.fn(() => ({ + remove: jest.fn(), + })); return { __esModule: true, default: MockEventEmitter, }; }); -jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); +jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper"); diff --git a/__tests__/components/BackgroundLayer.test.js b/__tests__/components/BackgroundLayer.test.js index febd9912c..2c5dfa3b1 100644 --- a/__tests__/components/BackgroundLayer.test.js +++ b/__tests__/components/BackgroundLayer.test.js @@ -1,37 +1,37 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import BackgroundLayer from '../../javascript/components/BackgroundLayer'; +import BackgroundLayer from "../../javascript/components/BackgroundLayer"; -describe('BackgroundLayer', () => { - test('renders correctly with default props', () => { - const {queryByTestId} = render( +describe("BackgroundLayer", () => { + test("renders correctly with default props", () => { + const { queryByTestId } = render( , ); - const backgroundLayer = queryByTestId('rctmlnBackgroundLayer'); - const {props} = backgroundLayer; + const backgroundLayer = queryByTestId("rctmlnBackgroundLayer"); + const { props } = backgroundLayer; - expect(props.sourceID).toStrictEqual('DefaultSourceID'); + expect(props.sourceID).toStrictEqual("DefaultSourceID"); }); - test('renders correctly with custom props', () => { + test("renders correctly with custom props", () => { const testProps = { - id: 'customId', - sourceID: 'customSourceId', - sourceLayerID: 'customSourceLayerId', - aboveLayerID: 'customAboveLayerId', - belowLayerID: 'customBelowLayerId', + id: "customId", + sourceID: "customSourceId", + sourceLayerID: "customSourceLayerId", + aboveLayerID: "customAboveLayerId", + belowLayerID: "customBelowLayerId", layerIndex: 0, - filter: ['==', 'arbitraryFilter', true], + filter: ["==", "arbitraryFilter", true], minZoomLevel: 3, maxZoomLevel: 8, - style: {visibility: 'none'}, + style: { visibility: "none" }, }; - const {queryByTestId} = render(); - const backgroundLayer = queryByTestId('rctmlnBackgroundLayer'); - const {props} = backgroundLayer; + const { queryByTestId } = render(); + const backgroundLayer = queryByTestId("rctmlnBackgroundLayer"); + const { props } = backgroundLayer; expect(props.id).toStrictEqual(testProps.id); expect(props.sourceID).toStrictEqual(testProps.sourceID); @@ -44,8 +44,8 @@ describe('BackgroundLayer', () => { expect(props.maxZoomLevel).toStrictEqual(testProps.maxZoomLevel); expect(props.reactStyle).toStrictEqual({ visibility: { - styletype: 'constant', - stylevalue: {type: 'string', value: testProps.style.visibility}, + styletype: "constant", + stylevalue: { type: "string", value: testProps.style.visibility }, }, }); }); diff --git a/__tests__/components/Callout.test.js b/__tests__/components/Callout.test.js index fa756eedb..ca1a55df7 100644 --- a/__tests__/components/Callout.test.js +++ b/__tests__/components/Callout.test.js @@ -1,41 +1,41 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; -import {View} from 'react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; +import { View } from "react-native"; -import Callout from '../../javascript/components/Callout'; +import Callout from "../../javascript/components/Callout"; -describe('Callout', () => { - test('renders with custom title', () => { - const testTitle = 'test title'; - const {getByText} = render(); +describe("Callout", () => { + test("renders with custom title", () => { + const testTitle = "test title"; + const { getByText } = render(); expect(getByText(testTitle)).toBeDefined(); }); - describe('_renderDefaultCallout', () => { - test('renders default children', () => { - const {getByTestId} = render(); + describe("_renderDefaultCallout", () => { + test("renders default children", () => { + const { getByTestId } = render(); - expect(getByTestId('callout')).toBeDefined(); - expect(getByTestId('title')).toBeDefined(); - expect(getByTestId('container')).toBeDefined(); + expect(getByTestId("callout")).toBeDefined(); + expect(getByTestId("title")).toBeDefined(); + expect(getByTestId("container")).toBeDefined(); }); - test('renders with custom styles', () => { + test("renders with custom styles", () => { const testProps = { - style: {height: 1}, - containerStyle: {height: 2}, - contentStyle: {height: 3}, - tipStyle: {height: 4}, - textStyle: {height: 5}, + style: { height: 1 }, + containerStyle: { height: 2 }, + contentStyle: { height: 3 }, + tipStyle: { height: 4 }, + textStyle: { height: 5 }, }; - const {getByTestId} = render(); + const { getByTestId } = render(); - const callout = getByTestId('callout'); - const container = getByTestId('container'); - const wrapper = getByTestId('wrapper'); - const tip = getByTestId('tip'); - const title = getByTestId('title'); + const callout = getByTestId("callout"); + const container = getByTestId("container"); + const wrapper = getByTestId("wrapper"); + const tip = getByTestId("tip"); + const title = getByTestId("title"); const calloutWrapperTestStyle = callout.props.style[0].height; const animatedViewTestStyle = container.props.style.height; @@ -53,30 +53,30 @@ describe('Callout', () => { }); }); - describe('_renderCustomCallout', () => { - test('renders custom children', () => { - const {getByTestId, queryByTestId} = render( + describe("_renderCustomCallout", () => { + test("renders custom children", () => { + const { getByTestId, queryByTestId } = render( - {'Foo Bar'} + Foo Bar , ); - expect(queryByTestId('title')).toBeNull(); - expect(getByTestId('TestChild')).toBeDefined(); + expect(queryByTestId("title")).toBeNull(); + expect(getByTestId("TestChild")).toBeDefined(); }); - test('renders with custom styles', () => { + test("renders with custom styles", () => { const testProps = { - style: {width: 1}, - containerStyle: {width: 2}, + style: { width: 1 }, + containerStyle: { width: 2 }, }; - const {getByTestId} = render( + const { getByTestId } = render( - {'Foo Bar'} + Foo Bar , ); - const callout = getByTestId('callout'); - const view = getByTestId('container'); + const callout = getByTestId("callout"); + const view = getByTestId("container"); const calloutWrapperTestStyle = callout.props.style[0].width; const animatedViewTestStyle = view.props.style.width; diff --git a/__tests__/components/Camera.test.js b/__tests__/components/Camera.test.js index 8b761bd1c..d785d0342 100644 --- a/__tests__/components/Camera.test.js +++ b/__tests__/components/Camera.test.js @@ -1,10 +1,10 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import Camera from '../../javascript/components/Camera'; +import Camera from "../../javascript/components/Camera"; const mockCameraNativeRef = React.createRef(); -jest.mock('../../javascript/hooks/useNativeRef', () => ({ +jest.mock("../../javascript/hooks/useNativeRef", () => ({ useNativeRef: () => { return mockCameraNativeRef; }, @@ -13,11 +13,11 @@ jest.mock('../../javascript/hooks/useNativeRef', () => ({ function renderCamera(props = {}) { const cameraRef = React.createRef(); - const {rerender} = render(); + const { rerender } = render(); const setNativePropsSpy = jest.spyOn( mockCameraNativeRef.current, - 'setNativeProps', + "setNativeProps", ); function rerenderCamera(newProps) { @@ -31,31 +31,31 @@ function renderCamera(props = {}) { }; } -describe('Camera', () => { +describe("Camera", () => { beforeEach(() => { jest.clearAllMocks(); }); - describe('render', () => { - test('renders correctly', () => { - const {getByTestId} = render(); + describe("render", () => { + test("renders correctly", () => { + const { getByTestId } = render(); - expect(getByTestId('Camera')).toBeDefined(); + expect(getByTestId("Camera")).toBeDefined(); }); - test('has proper default props', () => { - const {getByTestId} = render(); + test("has proper default props", () => { + const { getByTestId } = render(); - expect(getByTestId('Camera').props).toStrictEqual({ + expect(getByTestId("Camera").props).toStrictEqual({ children: undefined, - testID: 'Camera', + testID: "Camera", followUserLocation: undefined, followUserMode: undefined, followPitch: undefined, followHeading: undefined, followZoomLevel: undefined, stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 2000, @@ -74,29 +74,29 @@ describe('Camera', () => { }); }); - describe('updates', () => { + describe("updates", () => { test('updates when "followUserLocation" changes', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera({ + const { rerenderCamera, setNativePropsSpy } = renderCamera({ followUserLocation: false, }); - rerenderCamera({followUserLocation: true}); + rerenderCamera({ followUserLocation: true }); expect(setNativePropsSpy).toHaveBeenCalledWith({ followUserLocation: true, }); jest.resetAllMocks(); - rerenderCamera({followUserLocation: false, allowUpdates: false}); + rerenderCamera({ followUserLocation: false, allowUpdates: false }); expect(setNativePropsSpy).toHaveBeenCalledTimes(0); }); - test('updates when maxBounds change', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera(); + test("updates when maxBounds change", () => { + const { rerenderCamera, setNativePropsSpy } = renderCamera(); rerenderCamera({ - maxBounds: {ne: [-74.12641, 40.797968], sw: [-74.143727, 40.772177]}, + maxBounds: { ne: [-74.12641, 40.797968], sw: [-74.143727, 40.772177] }, }); expect(setNativePropsSpy).toHaveBeenCalledWith({ @@ -117,44 +117,44 @@ describe('Camera', () => { expect(setNativePropsSpy).toHaveBeenCalledTimes(0); }); - test('updates when minZoomLevel changes', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera(); - rerenderCamera({minZoomLevel: 5}); + test("updates when minZoomLevel changes", () => { + const { rerenderCamera, setNativePropsSpy } = renderCamera(); + rerenderCamera({ minZoomLevel: 5 }); expect(setNativePropsSpy).toHaveBeenCalledWith({ minZoomLevel: 5, }); jest.resetAllMocks(); - rerenderCamera({minZoomLevel: 3, allowUpdates: false}); + rerenderCamera({ minZoomLevel: 3, allowUpdates: false }); expect(setNativePropsSpy).toHaveBeenCalledTimes(0); }); - test('updates when maxZoomLevel changes', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera(); - rerenderCamera({maxZoomLevel: 5}); + test("updates when maxZoomLevel changes", () => { + const { rerenderCamera, setNativePropsSpy } = renderCamera(); + rerenderCamera({ maxZoomLevel: 5 }); expect(setNativePropsSpy).toHaveBeenCalledWith({ maxZoomLevel: 5, }); jest.resetAllMocks(); - rerenderCamera({maxZoomLevel: 2, allowUpdates: false}); + rerenderCamera({ maxZoomLevel: 2, allowUpdates: false }); expect(setNativePropsSpy).toHaveBeenCalledTimes(0); }); - test('updates when follow user props change', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera({ + test("updates when follow user props change", () => { + const { rerenderCamera, setNativePropsSpy } = renderCamera({ followUserLocation: true, }); rerenderCamera({ followUserLocation: true, - followUserMode: 'normal', + followUserMode: "normal", }); expect(setNativePropsSpy).toHaveBeenCalledWith({ - followUserMode: 'normal', + followUserMode: "normal", followHeading: undefined, followPitch: undefined, followZoomLevel: undefined, @@ -162,7 +162,7 @@ describe('Camera', () => { rerenderCamera({ followUserLocation: false, - followUserMode: 'compass', + followUserMode: "compass", }); // it only sends `followUserLocation` when it changes @@ -171,17 +171,17 @@ describe('Camera', () => { }); }); - test('updates when cameraConfig changes', () => { - const {rerenderCamera, setNativePropsSpy} = renderCamera(); + test("updates when cameraConfig changes", () => { + const { rerenderCamera, setNativePropsSpy } = renderCamera(); jest.resetAllMocks(); - rerenderCamera({animationMode: 'linear'}); + rerenderCamera({ animationMode: "linear" }); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { duration: 2000, heading: undefined, - mode: 'Ease', + mode: "Ease", paddingBottom: 0, paddingLeft: 0, paddingRight: 0, @@ -192,26 +192,26 @@ describe('Camera', () => { }); jest.resetAllMocks(); - rerenderCamera({allowUpdates: false, animationMode: 'flight'}); + rerenderCamera({ allowUpdates: false, animationMode: "flight" }); expect(setNativePropsSpy).toHaveBeenCalledTimes(0); }); }); - describe('methods', () => { - describe('#fitBounds', () => { + describe("methods", () => { + describe("#fitBounds", () => { const ne = [-63.12641, 39.797968]; const sw = [-74.143727, 40.772177]; test('works without provided "padding" and/ or "animationDuration"', () => { // FIXME: animationDuration and padding of null lead to malformed setCamera config - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.fitBounds(ne, sw, null, null); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 0, @@ -230,7 +230,7 @@ describe('Camera', () => { expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 0, @@ -249,7 +249,7 @@ describe('Camera', () => { expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 0, @@ -269,12 +269,12 @@ describe('Camera', () => { test.skip('throws when "ne" or "sw" are missing', () => {}); test('works with "padding" being a single number', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.fitBounds(ne, sw, 3, 500); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 500, @@ -290,12 +290,12 @@ describe('Camera', () => { }); test('works with "padding" being an array of two numbers', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.fitBounds(ne, sw, [3, 5], 500); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 500, @@ -311,12 +311,12 @@ describe('Camera', () => { }); test('works with "padding" being an array of four numbers', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.fitBounds(ne, sw, [3, 5, 8, 10], 500); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 500, @@ -332,19 +332,19 @@ describe('Camera', () => { }); }); - describe('#flyTo', () => { - test.skip('throws when no coordinates are provided', () => { + describe("#flyTo", () => { + test.skip("throws when no coordinates are provided", () => { // TODO: Refactor #flyTo to throw when coordinates aren't provided // This is a public method and people will call it with all sorts of data }); test('sets default "animationDuration" when called without it', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.flyTo([-111.8678, 40.2866]); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Flight', + mode: "Flight", pitch: undefined, heading: undefined, duration: 2000, @@ -360,12 +360,12 @@ describe('Camera', () => { }); test('calls "setCamera" with correct config', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.flyTo([-111.8678, 40.2866], 5000); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Flight', + mode: "Flight", pitch: undefined, heading: undefined, duration: 5000, @@ -381,18 +381,18 @@ describe('Camera', () => { }); }); - describe('#moveTo', () => { - test.skip('throws when no coordinates are provided', () => { + describe("#moveTo", () => { + test.skip("throws when no coordinates are provided", () => { // TODO: Refactor #moveTo to throw when coordinates aren't provided // This is a public method and people will call it with all sorts of data }); test('sets default "animationDuration" when called without it', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.moveTo([-111.8678, 40.2866]); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 0, @@ -407,12 +407,12 @@ describe('Camera', () => { }); }); - test('calls native camera with correct config', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + test("calls native camera with correct config", () => { + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.moveTo([-111.8678, 40.2866], 5000); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 5000, @@ -428,19 +428,19 @@ describe('Camera', () => { }); }); - describe('#zoomTo', () => { - test.skip('throws when no zoomLevel is provided', () => { + describe("#zoomTo", () => { + test.skip("throws when no zoomLevel is provided", () => { // TODO: Refactor #moveTo to throw when coordinates aren't provided // This is a public method and people will call it with all sorts of data }); test('sets default "animationDuration" when called without it', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.zoomTo(10); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Flight', + mode: "Flight", pitch: undefined, heading: undefined, duration: 2000, @@ -454,11 +454,11 @@ describe('Camera', () => { }); test('calls "_setCamera" with correct config', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.zoomTo(10, 3000); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Flight', + mode: "Flight", pitch: undefined, heading: undefined, duration: 3000, @@ -472,14 +472,14 @@ describe('Camera', () => { }); }); - describe('#setCamera', () => { + describe("#setCamera", () => { test('sets default config when called without "config', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); cameraRef.current.setCamera({}); expect(setNativePropsSpy).toHaveBeenCalledWith({ stop: { - mode: 'Ease', + mode: "Ease", pitch: undefined, heading: undefined, duration: 0, @@ -493,10 +493,10 @@ describe('Camera', () => { }); test('passes stopConfig to "setNativeProps"', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + const { setNativePropsSpy, cameraRef } = renderCamera(); const config = { animationDuration: 500, - animationMode: 'easeTo', + animationMode: "easeTo", bounds: { ne: [-63.12641, 39.797968], paddingBottom: 8, @@ -522,20 +522,20 @@ describe('Camera', () => { paddingTop: 3, duration: 500, heading: 100, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 11, }, }); }); - test('creates multiple stops when provided', () => { - const {setNativePropsSpy, cameraRef} = renderCamera(); + test("creates multiple stops when provided", () => { + const { setNativePropsSpy, cameraRef } = renderCamera(); const config = { stops: [ { animationDuration: 50, - animationMode: 'easeTo', + animationMode: "easeTo", bounds: { ne: [-63.12641, 39.797968], paddingBottom: 2, @@ -550,7 +550,7 @@ describe('Camera', () => { }, { animationDuration: 3000, - animationMode: 'flyTo', + animationMode: "flyTo", bounds: { ne: [-63.12641, 59.797968], paddingBottom: 8, @@ -565,7 +565,7 @@ describe('Camera', () => { }, { animationDuration: 500, - animationMode: 'easeTo', + animationMode: "easeTo", bounds: { ne: [-63.12641, 39.797968], paddingBottom: 8, @@ -595,7 +595,7 @@ describe('Camera', () => { paddingTop: 2, duration: 50, heading: 20, - mode: 'Ease', + mode: "Ease", pitch: 25, zoom: 16, }, @@ -608,7 +608,7 @@ describe('Camera', () => { paddingTop: 3, duration: 3000, heading: 40, - mode: 'Flight', + mode: "Flight", pitch: 45, zoom: 8, }, @@ -621,7 +621,7 @@ describe('Camera', () => { paddingTop: 3, duration: 500, heading: 100, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 11, }, @@ -631,7 +631,7 @@ describe('Camera', () => { }); }); - describe('#_createDefaultCamera', () => { + describe("#_createDefaultCamera", () => { test('returns null without "defaultSettings"', () => { const ref = React.createRef(); render(); @@ -652,7 +652,7 @@ describe('Camera', () => { '{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-111.8678,40.2866]}}', duration: 0, heading: undefined, - mode: 'None', + mode: "None", pitch: undefined, zoom: 16, paddingBottom: 0, @@ -666,7 +666,7 @@ describe('Camera', () => { }); }); - describe('#_createStopConfig', () => { + describe("#_createStopConfig", () => { const configWithoutBounds = { animationDuration: 2000, pitch: 45, @@ -676,7 +676,7 @@ describe('Camera', () => { const configWithBounds = { animationDuration: 500, - animationMode: 'easeTo', + animationMode: "easeTo", bounds: { ne: [-63.12641, 39.797968], paddingBottom: 8, @@ -691,19 +691,19 @@ describe('Camera', () => { }; test('returns null with "followUserLocation" prop and "!ignoreFollowUserLocation"', () => { - const {cameraRef} = renderCamera({followUserLocation: true}); + const { cameraRef } = renderCamera({ followUserLocation: true }); expect(cameraRef.current._createStopConfig()).toBe(null); }); test('returns correct "stopConfig" without bounds', () => { - const {cameraRef} = renderCamera(); + const { cameraRef } = renderCamera(); expect( cameraRef.current._createStopConfig(configWithoutBounds, true), ).toStrictEqual({ duration: 2000, heading: 110, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 9, paddingBottom: 0, @@ -715,7 +715,7 @@ describe('Camera', () => { // with centerCoordinate expect( cameraRef.current._createStopConfig( - {...configWithoutBounds, centerCoordinate: [-111.8678, 40.2866]}, + { ...configWithoutBounds, centerCoordinate: [-111.8678, 40.2866] }, true, ), ).toStrictEqual({ @@ -723,7 +723,7 @@ describe('Camera', () => { '{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-111.8678,40.2866]}}', duration: 2000, heading: 110, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 9, paddingBottom: 0, @@ -734,7 +734,7 @@ describe('Camera', () => { }); test('returns correct "stopConfig" with bounds', () => { - const {cameraRef} = renderCamera(); + const { cameraRef } = renderCamera(); expect( cameraRef.current._createStopConfig(configWithBounds, true), @@ -747,7 +747,7 @@ describe('Camera', () => { paddingTop: 3, duration: 500, heading: 100, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 11, }); @@ -755,7 +755,7 @@ describe('Camera', () => { // with centerCoordinate expect( cameraRef.current._createStopConfig( - {...configWithBounds, centerCoordinate: [-111.8678, 40.2866]}, + { ...configWithBounds, centerCoordinate: [-111.8678, 40.2866] }, true, ), ).toStrictEqual({ @@ -769,45 +769,45 @@ describe('Camera', () => { '{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-111.8678,40.2866]}}', duration: 500, heading: 100, - mode: 'Ease', + mode: "Ease", pitch: 45, zoom: 11, }); }); }); - describe('#_getNativeCameraMode', () => { + describe("#_getNativeCameraMode", () => { const ref = React.createRef(); render(); const camera = ref.current; test('returns "Flight" for "flyTo"', () => { expect( - camera._getNativeCameraMode({animationMode: 'flyTo'}), - ).toStrictEqual('Flight'); + camera._getNativeCameraMode({ animationMode: "flyTo" }), + ).toStrictEqual("Flight"); }); test('returns "None" for "moveTo"', () => { expect( - camera._getNativeCameraMode({animationMode: 'moveTo'}), - ).toStrictEqual('None'); + camera._getNativeCameraMode({ animationMode: "moveTo" }), + ).toStrictEqual("None"); }); test('returns "Ease" as default', () => { - expect(camera._getNativeCameraMode({})).toStrictEqual('Ease'); + expect(camera._getNativeCameraMode({})).toStrictEqual("Ease"); }); }); - describe('#_getMaxBounds', () => { + describe("#_getMaxBounds", () => { test('returns null if no "maxBounds"', () => { - const {cameraRef, rerenderCamera} = renderCamera(); + const { cameraRef, rerenderCamera } = renderCamera(); expect(cameraRef.current._getMaxBounds()).toStrictEqual(null); - rerenderCamera({maxBounds: {ne: [-74.12641, 40.797968]}}); + rerenderCamera({ maxBounds: { ne: [-74.12641, 40.797968] } }); expect(cameraRef.current._getMaxBounds()).toStrictEqual(null); - renderCamera({maxBounds: {sw: [-74.143727, 40.772177]}}); + renderCamera({ maxBounds: { sw: [-74.143727, 40.772177] } }); expect(cameraRef.current._getMaxBounds()).toStrictEqual(null); }); @@ -817,7 +817,7 @@ describe('Camera', () => { sw: [-74.143727, 40.772177], }; - const {cameraRef} = renderCamera({maxBounds}); + const { cameraRef } = renderCamera({ maxBounds }); expect(cameraRef.current._getMaxBounds()).toStrictEqual( '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-74.12641,40.797968]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-74.143727,40.772177]}}]}', diff --git a/__tests__/components/CircleLayer.test.js b/__tests__/components/CircleLayer.test.js index e63cd9b34..86746e7b1 100644 --- a/__tests__/components/CircleLayer.test.js +++ b/__tests__/components/CircleLayer.test.js @@ -1,34 +1,36 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import CircleLayer from '../../javascript/components/CircleLayer'; +import CircleLayer from "../../javascript/components/CircleLayer"; -describe('CircleLayer', () => { - test('renders correctly with default props', () => { - const {queryByTestId} = render(); - const circleLayer = queryByTestId('rctmlnCircleLayer'); - const {props} = circleLayer; +describe("CircleLayer", () => { + test("renders correctly with default props", () => { + const { queryByTestId } = render( + , + ); + const circleLayer = queryByTestId("rctmlnCircleLayer"); + const { props } = circleLayer; - expect(props.sourceID).toStrictEqual('DefaultSourceID'); + expect(props.sourceID).toStrictEqual("DefaultSourceID"); }); - test('renders correctly with custom props', () => { + test("renders correctly with custom props", () => { const customProps = { - id: 'customId', - sourceID: 'customSourceId', - sourceLayerID: 'customSourceLayerId', - aboveLayerID: 'customAboveLayerId', - belowLayerID: 'customBelowLayerId', + id: "customId", + sourceID: "customSourceId", + sourceLayerID: "customSourceLayerId", + aboveLayerID: "customAboveLayerId", + belowLayerID: "customBelowLayerId", layerIndex: 0, - filter: ['==', 'arbitraryFilter', true], + filter: ["==", "arbitraryFilter", true], minZoomLevel: 3, maxZoomLevel: 8, - style: {visibility: 'none'}, + style: { visibility: "none" }, }; - const {queryByTestId} = render(); - const circleLayer = queryByTestId('rctmlnCircleLayer'); - const {props} = circleLayer; + const { queryByTestId } = render(); + const circleLayer = queryByTestId("rctmlnCircleLayer"); + const { props } = circleLayer; expect(props.id).toStrictEqual(customProps.id); expect(props.sourceID).toStrictEqual(customProps.sourceID); @@ -41,8 +43,8 @@ describe('CircleLayer', () => { expect(props.maxZoomLevel).toStrictEqual(customProps.maxZoomLevel); expect(props.reactStyle).toStrictEqual({ visibility: { - styletype: 'constant', - stylevalue: {type: 'string', value: customProps.style.visibility}, + styletype: "constant", + stylevalue: { type: "string", value: customProps.style.visibility }, }, }); }); diff --git a/__tests__/components/HeatmapLayer.test.js b/__tests__/components/HeatmapLayer.test.js index 799594268..7b3388ec9 100644 --- a/__tests__/components/HeatmapLayer.test.js +++ b/__tests__/components/HeatmapLayer.test.js @@ -1,33 +1,33 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import HeatmapLayer from '../../javascript/components/HeatmapLayer'; +import HeatmapLayer from "../../javascript/components/HeatmapLayer"; -describe('HeatmapLayer', () => { - test('renders correctly with default props', () => { - const {UNSAFE_getByType} = render( +describe("HeatmapLayer", () => { + test("renders correctly with default props", () => { + const { UNSAFE_getByType } = render( , ); - const heatmapLayer = UNSAFE_getByType('RCTMLNHeatmapLayer'); - const {props} = heatmapLayer; - expect(props.sourceID).toStrictEqual('DefaultSourceID'); + const heatmapLayer = UNSAFE_getByType("RCTMLNHeatmapLayer"); + const { props } = heatmapLayer; + expect(props.sourceID).toStrictEqual("DefaultSourceID"); }); - test('renders correctly with custom props', () => { + test("renders correctly with custom props", () => { const testProps = { - id: 'customId', - sourceID: 'customSourceId', - sourceLayerID: 'customSourceLayerId', - aboveLayerID: 'customAboveLayerId', - belowLayerID: 'customBelowLayerId', + id: "customId", + sourceID: "customSourceId", + sourceLayerID: "customSourceLayerId", + aboveLayerID: "customAboveLayerId", + belowLayerID: "customBelowLayerId", layerIndex: 0, - filter: ['==', 'arbitraryFilter', true], + filter: ["==", "arbitraryFilter", true], minZoomLevel: 3, maxZoomLevel: 8, - style: {visibility: 'none'}, + style: { visibility: "none" }, }; - const {UNSAFE_getByType} = render(); - const {props} = UNSAFE_getByType('RCTMLNHeatmapLayer'); + const { UNSAFE_getByType } = render(); + const { props } = UNSAFE_getByType("RCTMLNHeatmapLayer"); expect(props.id).toStrictEqual(testProps.id); expect(props.sourceID).toStrictEqual(testProps.sourceID); @@ -40,8 +40,8 @@ describe('HeatmapLayer', () => { expect(props.maxZoomLevel).toStrictEqual(testProps.maxZoomLevel); expect(props.reactStyle).toStrictEqual({ visibility: { - styletype: 'constant', - stylevalue: {type: 'string', value: testProps.style.visibility}, + styletype: "constant", + stylevalue: { type: "string", value: testProps.style.visibility }, }, }); }); diff --git a/__tests__/components/Light.test.js b/__tests__/components/Light.test.js index e75a3ce02..6e567a66b 100644 --- a/__tests__/components/Light.test.js +++ b/__tests__/components/Light.test.js @@ -1,31 +1,31 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import Light from '../../javascript/components/Light'; +import Light from "../../javascript/components/Light"; -describe('Light', () => { - test('renders correctly', () => { - const {queryByTestId} = render(); - const light = queryByTestId('rctmlnLight'); +describe("Light", () => { + test("renders correctly", () => { + const { queryByTestId } = render(); + const light = queryByTestId("rctmlnLight"); expect(light).toBeDefined(); }); - test('renders correctly with custom styles', () => { + test("renders correctly with custom styles", () => { const testStyles = { position: [1234, 1234, 1234], - color: '#FA0000', // === ProcessedTestColor - anchor: 'map', + color: "#FA0000", // === ProcessedTestColor + anchor: "map", intensity: 1, }; const processedTestColor = 4294574080; - const {queryByTestId} = render(); + const { queryByTestId } = render(); - const customStyles = queryByTestId('rctmlnLight').props.reactStyle; - const {anchor} = customStyles; - const {color} = customStyles; - const {position} = customStyles; - const {intensity} = customStyles; + const customStyles = queryByTestId("rctmlnLight").props.reactStyle; + const { anchor } = customStyles; + const { color } = customStyles; + const { position } = customStyles; + const { intensity } = customStyles; expect(anchor.stylevalue.value).toStrictEqual(testStyles.anchor); expect(color.stylevalue.value).toStrictEqual(processedTestColor); diff --git a/__tests__/components/MapView.test.js b/__tests__/components/MapView.test.js index 7e678ed91..0877e49e8 100644 --- a/__tests__/components/MapView.test.js +++ b/__tests__/components/MapView.test.js @@ -1,13 +1,13 @@ -import * as React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import * as React from "react"; -import MapView from '../../javascript/components/MapView'; +import MapView from "../../javascript/components/MapView"; -describe('MapView', () => { - test('renders with testID', () => { - const expectedTestId = 'im used for identification in tests'; +describe("MapView", () => { + test("renders with testID", () => { + const expectedTestId = "im used for identification in tests"; - const {getByTestId} = render(); + const { getByTestId } = render(); expect(() => { getByTestId(expectedTestId); diff --git a/__tests__/components/Style.test.js b/__tests__/components/Style.test.js index 31c771f64..fd204912d 100644 --- a/__tests__/components/Style.test.js +++ b/__tests__/components/Style.test.js @@ -1,30 +1,30 @@ -import React from 'react'; -import {render} from '@testing-library/react-native'; +import { render } from "@testing-library/react-native"; +import React from "react"; -import VectorSource from '../../javascript/components/VectorSource'; -import RasterSource from '../../javascript/components/RasterSource'; -import ImageSource from '../../javascript/components/ImageSource'; -import ShapeSource from '../../javascript/components/ShapeSource'; -import Style from '../../javascript/components/Style'; -import HeatmapLayer from '../../javascript/components/HeatmapLayer'; -import CircleLayer from '../../javascript/components/CircleLayer'; -import SymbolLayer from '../../javascript/components/SymbolLayer'; -import RasterLayer from '../../javascript/components/RasterLayer'; -import LineLayer from '../../javascript/components/LineLayer'; -import FillLayer from '../../javascript/components/FillLayer'; -import FillExtrusionLayer from '../../javascript/components/FillExtrusionLayer'; -import BackgroundLayer from '../../javascript/components/BackgroundLayer'; +import BackgroundLayer from "../../javascript/components/BackgroundLayer"; +import CircleLayer from "../../javascript/components/CircleLayer"; +import FillExtrusionLayer from "../../javascript/components/FillExtrusionLayer"; +import FillLayer from "../../javascript/components/FillLayer"; +import HeatmapLayer from "../../javascript/components/HeatmapLayer"; +import ImageSource from "../../javascript/components/ImageSource"; +import LineLayer from "../../javascript/components/LineLayer"; +import RasterLayer from "../../javascript/components/RasterLayer"; +import RasterSource from "../../javascript/components/RasterSource"; +import ShapeSource from "../../javascript/components/ShapeSource"; +import Style from "../../javascript/components/Style"; +import SymbolLayer from "../../javascript/components/SymbolLayer"; +import VectorSource from "../../javascript/components/VectorSource"; -describe('Style', () => { - test('renders vectory source correctly', () => { +describe("Style", () => { + test("renders vectory source correctly", () => { const vectorSource = { - type: 'vector', - url: 'mapbox://mapbox.660ui7x6', - tiles: ['http://host1', 'http://host2'], + type: "vector", + url: "mapbox://mapbox.660ui7x6", + tiles: ["http://host1", "http://host2"], minzoom: 1, maxzoom: 22, - attribution: 'Copyright', - scheme: 'tms', + attribution: "Copyright", + scheme: "tms", }; const json = { @@ -34,9 +34,9 @@ describe('Style', () => { }, }; - const {UNSAFE_getByType} = render(