Skip to content

Commit

Permalink
refactor example class name
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhdang198 committed Feb 19, 2024
1 parent 71a265f commit c3c89fa
Show file tree
Hide file tree
Showing 86 changed files with 515 additions and 515 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android/gradlew
android/gradlew.bat
android/local.properties

# maplibre-react-native
# vietmap-react-native
example
__tests__
coverage
Expand Down
6 changes: 3 additions & 3 deletions __tests__/interface.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import MapLibreGL from '../javascript';
import VietmapGL from '../javascript';

// Assert that all required Maplibre modules are accessible and exported
// Assert that all required Vietmap modules are accessible and exported
describe('Public Interface', () => {
it('should contain all expected components and utils', () => {
const actualKeys = Object.keys(MapLibreGL);
const actualKeys = Object.keys(VietmapGL);
const expectedKeys = [
// components
'MapView',
Expand Down
12 changes: 6 additions & 6 deletions __tests__/modules/location/locationManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LocationManager, {

import {NativeModules} from 'react-native';

const MapLibreGL = NativeModules.MGLModule;
const VietmapGL = NativeModules.MGLModule;
const MapLibreGLLocationManager = NativeModules.MGLLocationModule;

const location = {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('LocationManager', () => {

describe('#addListener', () => {
const myListener = jest.fn();
MapLibreGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};
VietmapGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};

afterEach(() => {
locationManager._listeners = [];
Expand Down Expand Up @@ -156,15 +156,15 @@ describe('LocationManager', () => {
});

test('starts native location manager and adds event emitter listener', () => {
MapLibreGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};
VietmapGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};

expect(locationManager._isListening).toStrictEqual(false);

locationManager.start();

expect(MapLibreGLLocationManager.start).toHaveBeenCalledTimes(1);
expect(LocationModuleEventEmitter.addListener).toHaveBeenCalledWith(
MapLibreGL.LocationCallbackName.Update,
VietmapGL.LocationCallbackName.Update,
locationManager.onUpdate,
);

Expand Down Expand Up @@ -198,7 +198,7 @@ describe('LocationManager', () => {

// native location manager has no #stop exposed in tests?
MapLibreGLLocationManager.stop = jest.fn();
MapLibreGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};
VietmapGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};

expect(locationManager._isListening).toStrictEqual(true);

Expand All @@ -216,7 +216,7 @@ describe('LocationManager', () => {

// native location manager has no #stop exposed in tests?
MapLibreGLLocationManager.stop = jest.fn();
MapLibreGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};
VietmapGL.LocationCallbackName = {Update: 'MapboxUserLocationUpdate'};

expect(locationManager._isListening).toStrictEqual(false);

Expand Down
88 changes: 44 additions & 44 deletions __tests__/modules/offline/offlineManager.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MapLibreGL from '../../../javascript';
import VietmapGL from '../../../javascript';
import {OfflineModuleEventEmitter} from '../../../javascript/modules/offline/offlineManager';

import {NativeModules, Platform} from 'react-native';
Expand All @@ -19,7 +19,7 @@ describe('offlineManager', () => {
type: 'offlinestatus',
payload: {
name: packOptions.name,
state: MapLibreGL.OfflinePackDownloadState.Active,
state: VietmapGL.OfflinePackDownloadState.Active,
progress: 50.0,
},
};
Expand All @@ -28,7 +28,7 @@ describe('offlineManager', () => {
type: 'offlinestatus',
payload: {
name: packOptions.name,
state: MapLibreGL.OfflinePackDownloadState.Complete,
state: VietmapGL.OfflinePackDownloadState.Complete,
progress: 100.0,
},
};
Expand All @@ -42,37 +42,37 @@ describe('offlineManager', () => {
};

afterEach(async () => {
const packs = await MapLibreGL.offlineManager.getPacks();
const packs = await VietmapGL.offlineManager.getPacks();
for (const pack of packs) {
await MapLibreGL.offlineManager.deletePack(pack.name);
await VietmapGL.offlineManager.deletePack(pack.name);
}

jest.clearAllMocks();
});

it('should create pack', async () => {
let offlinePack = await MapLibreGL.offlineManager.getPack(packOptions.name);
let offlinePack = await VietmapGL.offlineManager.getPack(packOptions.name);
expect(offlinePack).toBeFalsy();

await MapLibreGL.offlineManager.createPack(packOptions);
offlinePack = await MapLibreGL.offlineManager.getPack(packOptions.name);
await VietmapGL.offlineManager.createPack(packOptions);
offlinePack = await VietmapGL.offlineManager.getPack(packOptions.name);
expect(offlinePack).toBeTruthy();
});

it('should delete pack', async () => {
await MapLibreGL.offlineManager.createPack(packOptions);
let offlinePack = await MapLibreGL.offlineManager.getPack(packOptions.name);
await VietmapGL.offlineManager.createPack(packOptions);
let offlinePack = await VietmapGL.offlineManager.getPack(packOptions.name);
expect(offlinePack).toBeTruthy();

await MapLibreGL.offlineManager.deletePack(packOptions.name);
offlinePack = await MapLibreGL.offlineManager.getPack(packOptions.name);
await VietmapGL.offlineManager.deletePack(packOptions.name);
offlinePack = await VietmapGL.offlineManager.getPack(packOptions.name);
expect(offlinePack).toBeFalsy();
});

it('should set max tile count limit', () => {
const expectedLimit = 2000;
const spy = jest.spyOn(NativeModules.MGLOfflineModule, 'setTileCountLimit');
MapLibreGL.offlineManager.setTileCountLimit(expectedLimit);
VietmapGL.offlineManager.setTileCountLimit(expectedLimit);
expect(spy).toHaveBeenCalledWith(expectedLimit);
spy.mockRestore();
});
Expand All @@ -83,7 +83,7 @@ describe('offlineManager', () => {
NativeModules.MGLOfflineModule,
'setProgressEventThrottle',
);
MapLibreGL.offlineManager.setProgressEventThrottle(expectedThrottleValue);
VietmapGL.offlineManager.setProgressEventThrottle(expectedThrottleValue);
expect(spy).toHaveBeenCalledWith(expectedThrottleValue);
spy.mockRestore();
});
Expand All @@ -92,18 +92,18 @@ describe('offlineManager', () => {
it('should subscribe to native events', async () => {
const spy = jest.spyOn(OfflineModuleEventEmitter, 'addListener');
const noop = () => {};
await MapLibreGL.offlineManager.createPack(packOptions, noop, noop);
await VietmapGL.offlineManager.createPack(packOptions, noop, noop);
expect(spy).toHaveBeenCalledTimes(2);
spy.mockClear();
});

it('should call progress listener', async () => {
const listener = jest.fn();
await MapLibreGL.offlineManager.createPack(packOptions, listener);
const expectedOfflinePack = await MapLibreGL.offlineManager.getPack(
await VietmapGL.offlineManager.createPack(packOptions, listener);
const expectedOfflinePack = await VietmapGL.offlineManager.getPack(
packOptions.name,
);
MapLibreGL.offlineManager._onProgress(mockOnProgressEvent);
VietmapGL.offlineManager._onProgress(mockOnProgressEvent);
expect(listener).toHaveBeenCalledWith(
expectedOfflinePack,
mockOnProgressEvent.payload,
Expand All @@ -112,11 +112,11 @@ describe('offlineManager', () => {

it('should call error listener', async () => {
const listener = jest.fn();
await MapLibreGL.offlineManager.createPack(packOptions, null, listener);
const expectedOfflinePack = await MapLibreGL.offlineManager.getPack(
await VietmapGL.offlineManager.createPack(packOptions, null, listener);
const expectedOfflinePack = await VietmapGL.offlineManager.getPack(
packOptions.name,
);
MapLibreGL.offlineManager._onError(mockErrorEvent);
VietmapGL.offlineManager._onError(mockErrorEvent);
expect(listener).toHaveBeenCalledWith(
expectedOfflinePack,
mockErrorEvent.payload,
Expand All @@ -125,66 +125,66 @@ describe('offlineManager', () => {

it('should not call listeners after unsubscribe', async () => {
const listener = jest.fn();
await MapLibreGL.offlineManager.createPack(
await VietmapGL.offlineManager.createPack(
packOptions,
listener,
listener,
);
MapLibreGL.offlineManager.unsubscribe(packOptions.name);
MapLibreGL.offlineManager._onProgress(mockOnProgressEvent);
MapLibreGL.offlineManager._onError(mockErrorEvent);
VietmapGL.offlineManager.unsubscribe(packOptions.name);
VietmapGL.offlineManager._onProgress(mockOnProgressEvent);
VietmapGL.offlineManager._onError(mockErrorEvent);
expect(listener).not.toHaveBeenCalled();
});

it('should unsubscribe from native events', async () => {
const noop = () => {};

await MapLibreGL.offlineManager.createPack(packOptions, noop, noop);
MapLibreGL.offlineManager.unsubscribe(packOptions.name);
await VietmapGL.offlineManager.createPack(packOptions, noop, noop);
VietmapGL.offlineManager.unsubscribe(packOptions.name);

expect(
MapLibreGL.offlineManager.subscriptionProgress.remove,
VietmapGL.offlineManager.subscriptionProgress.remove,
).toHaveBeenCalledTimes(1);
expect(
MapLibreGL.offlineManager.subscriptionError.remove,
VietmapGL.offlineManager.subscriptionError.remove,
).toHaveBeenCalledTimes(1);
});

it('should unsubscribe event listeners once a pack download has completed', async () => {
const listener = jest.fn();
await MapLibreGL.offlineManager.createPack(
await VietmapGL.offlineManager.createPack(
packOptions,
listener,
listener,
);

expect(
MapLibreGL.offlineManager._hasListeners(
VietmapGL.offlineManager._hasListeners(
packOptions.name,
MapLibreGL.offlineManager._progressListeners,
VietmapGL.offlineManager._progressListeners,
),
).toBeTruthy();

expect(
MapLibreGL.offlineManager._hasListeners(
VietmapGL.offlineManager._hasListeners(
packOptions.name,
MapLibreGL.offlineManager._errorListeners,
VietmapGL.offlineManager._errorListeners,
),
).toBeTruthy();

MapLibreGL.offlineManager._onProgress(mockOnProgressCompleteEvent);
VietmapGL.offlineManager._onProgress(mockOnProgressCompleteEvent);

expect(
MapLibreGL.offlineManager._hasListeners(
VietmapGL.offlineManager._hasListeners(
packOptions.name,
MapLibreGL.offlineManager._progressListeners,
VietmapGL.offlineManager._progressListeners,
),
).toBeFalsy();

expect(
MapLibreGL.offlineManager._hasListeners(
VietmapGL.offlineManager._hasListeners(
packOptions.name,
MapLibreGL.offlineManager._errorListeners,
VietmapGL.offlineManager._errorListeners,
),
).toBeFalsy();
});
Expand All @@ -199,8 +199,8 @@ describe('offlineManager', () => {
const name = `test-${Date.now()}`;
const noop = () => {};
const options = {...packOptions, name};
await MapLibreGL.offlineManager.createPack(options);
await MapLibreGL.offlineManager.subscribe(name, noop, noop);
await VietmapGL.offlineManager.createPack(options);
await VietmapGL.offlineManager.subscribe(name, noop, noop);

expect(spy).toHaveBeenCalled();
spy.mockRestore();
Expand All @@ -212,7 +212,7 @@ describe('offlineManager', () => {
const name = `test-${Date.now()}`;
const noop = () => {};
const options = {...packOptions, name};
await MapLibreGL.offlineManager.createPack(options, noop, noop);
await VietmapGL.offlineManager.createPack(options, noop, noop);

expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
Expand All @@ -228,8 +228,8 @@ describe('offlineManager', () => {
const name = `test-${Date.now()}`;
const noop = () => {};
const options = {...packOptions, name};
await MapLibreGL.offlineManager.createPack(options);
await MapLibreGL.offlineManager.subscribe(name, noop, noop);
await VietmapGL.offlineManager.createPack(options);
await VietmapGL.offlineManager.subscribe(name, noop, noop);

expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
Expand Down
4 changes: 2 additions & 2 deletions __tests__/modules/snapshot/snapshotManager.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import MapLibreGL from '../../../javascript';
import VietmapGL from '../../../javascript';

describe('snapshotManager', () => {
it('should resolve uri', async () => {
const options = {centerCoordinate: [1, 2]};
const uri = await MapLibreGL.snapshotManager.takeSnap(options);
const uri = await VietmapGL.snapshotManager.takeSnap(options);
expect(uri).toEqual('file://test.png');
});
});
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "RNMaplibreExample",
"name": "RNVietmapExample",
"version": "1.0.0",
"private": true,
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import MapLibreGL from '@maplibre/maplibre-react-native';
import VietmapGL from '@maplibre/maplibre-react-native';
import {StyleSheet, Text, View, LogBox, SafeAreaView} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';

Expand All @@ -20,7 +20,7 @@ const styles = StyleSheet.create({
},
});

MapLibreGL.setAccessToken(null);
VietmapGL.setAccessToken(null);
Icon.loadFont();

class App extends React.Component {
Expand All @@ -36,7 +36,7 @@ class App extends React.Component {

async componentDidMount() {
if (IS_ANDROID) {
const isGranted = await MapLibreGL.requestAndroidLocationPermissions();
const isGranted = await VietmapGL.requestAndroidLocationPermissions();
this.setState({
isAndroidPermissionGranted: isGranted,
isFetchingAndroidPermission: false,
Expand Down
Loading

0 comments on commit c3c89fa

Please sign in to comment.