Skip to content

Commit

Permalink
feat(deploy_beta): убрано property nativeFeaturesFts и все что с ним …
Browse files Browse the repository at this point in the history
…связано
  • Loading branch information
Aliaksandr Pashkevich committed Feb 15, 2024
1 parent 2b6c5bc commit 1f6456f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 76 deletions.
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ export const versionToIosAppId = {
export const nativeFeaturesFromVersion: NativeFeaturesFromVersion = {
android: {
linksInBrowser: {
nativeFeatureFtKey: 'linksInBrowserAndroid',
fromVersion: '11.71.0',
},
geolocation: { fromVersion: '11.71.0' },
},
ios: {
linksInBrowser: {
nativeFeatureFtKey: 'linksInBrowserIos',
fromVersion: '13.3.0',
},
geolocation: { fromVersion: '0.0.0' },
Expand Down
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { HandleRedirect, NativeNavigationAndTitle } from './native-navigation-an
import type {
Environment,
NativeFeatureKey,
NativeFeaturesFts,
NativeParams,
WebViewWindow,
} from './types';
Expand Down Expand Up @@ -50,7 +49,6 @@ export class BridgeToNative {
private _handleRedirect: HandleRedirect;

constructor(
public nativeFeaturesFts: NativeFeaturesFts = {'linksInBrowserAndroid': true, 'linksInBrowserIos': true},
handleRedirect: HandleRedirect,
nativeParams?: NativeParams,
) {
Expand Down Expand Up @@ -108,13 +106,9 @@ export class BridgeToNative {
* @param feature Название функциональности, которую нужно проверить.
*/
public canUseNativeFeature(feature: NativeFeatureKey) {
const { nativeFeatureFtKey, fromVersion } =
const { fromVersion } =
nativeFeaturesFromVersion[this.environment][feature];

if (nativeFeatureFtKey && !this.nativeFeaturesFts[nativeFeatureFtKey]) {
return false;
}

return this.isCurrentVersionHigherOrEqual(fromVersion);
}

Expand Down
5 changes: 1 addition & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ export type NativeParams = {
originalWebviewParams: string;
};

type NativeFeatureFtKey = 'linksInBrowserAndroid' | 'linksInBrowserIos';
export type NativeFeaturesFts = Record<NativeFeatureFtKey, boolean>;

export type NativeFeatureKey =
// Возможность работы с геолокацией.
| 'geolocation'
// Возможность открыть ссылку в браузере.
| 'linksInBrowser';

type NativeFeaturesParams = Readonly<
Record<NativeFeatureKey, { nativeFeatureFtKey?: NativeFeatureFtKey; fromVersion: string }>
Record<NativeFeatureKey, { fromVersion: string }>
>;
export type NativeFeaturesFromVersion = Readonly<{
android: NativeFeaturesParams;
Expand Down
62 changes: 21 additions & 41 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BridgeToNative } from '../src';
import { PREVIOUS_B2N_STATE_STORAGE_KEY } from '../src/constants';
import { mockSessionStorage } from '../src/mock/mock-session-storage';
import { WebViewWindow } from '../src/types';
import {mockWindowLocation} from '../src/mock/mock-window-location';

const mockedNativeFallbacksInstance = {};
const mockedNativeNavigationAndTitleInstance = {
Expand All @@ -28,11 +29,6 @@ jest.mock('../src/native-navigation-and-title', () => ({
}));

describe('BridgeToNative', () => {
const defaultAmFeaturesFts = {
linksInBrowserAndroid: true,
linksInBrowserIos: true,
};

const defaultAmParams = {
appVersion: '12.0.0',
theme: 'light',
Expand All @@ -50,9 +46,6 @@ describe('BridgeToNative', () => {
nextPageId: null,
};

// const { getItem, setItem, removeItem } = mockSessionStorage({
// [PREVIOUS_B2N_STATE_STORAGE_KEY]: savedBridgeToAmState,
// });
const { getItem, setItem } = mockSessionStorage(
PREVIOUS_B2N_STATE_STORAGE_KEY,
savedBridgeToAmState,
Expand All @@ -69,7 +62,7 @@ describe('BridgeToNative', () => {

BridgeToNative.prototype['restorePreviousState'] = jest.fn();

const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative(mockedHandleRedirect, {
...defaultAmParams,
title: 'Initial Title',
});
Expand All @@ -85,7 +78,6 @@ describe('BridgeToNative', () => {
describe('method `saveCurrentState`', () => {
it('should save current state into sessionStorage and call `AmNavigationAndTitle.saveCurrentState`', () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -112,7 +104,6 @@ describe('BridgeToNative', () => {
// JSON.parse = jest.fn().mockImplementationOnce(() => savedBridgeToAmState);

const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand Down Expand Up @@ -153,7 +144,7 @@ describe('BridgeToNative', () => {

describe('constructor', () => {
it('should pass `initialAmTitle` to `AmNavigationAndTitle` constructor', () => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
title: 'Initial Title',
});
Expand All @@ -170,11 +161,11 @@ describe('BridgeToNative', () => {
describe('public props', () => {
it('should save theme used by AM in `theme` property', () => {
const inst1 = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
const inst2 = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst2 = new BridgeToNative(mockedHandleRedirect, {
...defaultAmParams,
theme: 'dark',
});
Expand All @@ -186,7 +177,7 @@ describe('BridgeToNative', () => {
it('should save original AM query params in `originalWebviewParams` property', () => {
const originalWebviewParamsExample =
'device_uuid=8441576F-A09F-41E9-89A7-EE1FA486C20A&device_id=2E32AFD5-F50B-4B2F-B758-CAE59DF2BF6C&applicationId=1842D0AA-0008-4941-93E0-4FD80E087841&device_os_version=com.aconcierge.app&device_app_version=iOS 16.1&scope=12.26.0&device_boot_time=openid mobile-bank';
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
originalWebviewParams: originalWebviewParamsExample,
});
Expand All @@ -195,7 +186,7 @@ describe('BridgeToNative', () => {
});

it('should save nextPageId in `nextPageId` property and send it into `AmNavigationAndTitle` constructor', () => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
title: 'Test',
nextPageId: 7,
Expand All @@ -213,7 +204,7 @@ describe('BridgeToNative', () => {

it('should provide `NativeFallbacks` instance', () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -223,7 +214,7 @@ describe('BridgeToNative', () => {

it('should provide `AmNavigationAndTitle` instance', () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -240,7 +231,7 @@ describe('BridgeToNative', () => {

it('should provide `AndroidBridge` property', () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -250,7 +241,7 @@ describe('BridgeToNative', () => {

it('should set `environment` property correctly', () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -260,7 +251,6 @@ describe('BridgeToNative', () => {

it('should not provide application type using `iosAppId` property', () => {
const ins = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -272,7 +262,7 @@ describe('BridgeToNative', () => {
describe('iOS environment', () => {
it('should not provide `AndroidBridge` property', () => {
const ins = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -282,7 +272,7 @@ describe('BridgeToNative', () => {

it('should set `environment` property correctly', () => {
const ins = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -303,7 +293,7 @@ describe('BridgeToNative', () => {
])(
'should detect app scheme for version %s correctly and save it in `iosAppId` property',
(appVersion, expected) => {
const ins = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const ins = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion,
});
Expand All @@ -313,12 +303,12 @@ describe('BridgeToNative', () => {
);

it('should use `iosAppId` parameter as value for `iosApplicationId` while parameter exists', () => {
const inst1 = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst1 = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion: '0.0.0',
iosAppId: 'kittycash',
});
const inst2 = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst2 = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion: '12.22.0',
iosAppId: 'kittycash',
Expand All @@ -345,24 +335,14 @@ describe('BridgeToNative', () => {
androidEnvFlag = true;
}

const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion,
});

expect(inst.canUseNativeFeature('linksInBrowser')).toBe(expected);
},
);

it('should return `false` for feature while FT is off', () => {
const inst = new BridgeToNative(
{ ...defaultAmFeaturesFts, linksInBrowserIos: false },
mockedHandleRedirect,
{ ...defaultAmParams, appVersion: '14.0.0' },
);

expect(inst.canUseNativeFeature('linksInBrowser')).toBeFalsy();
});
});

describe('method `closeWebview`', () => {
Expand All @@ -389,7 +369,7 @@ describe('BridgeToNative', () => {
])(
'should compare current version `%s` with `%s` and return `%s`',
(currentVersion, versionToCompare, result) => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,

appVersion: currentVersion,
Expand All @@ -405,7 +385,7 @@ describe('BridgeToNative', () => {
androidEnvFlag = true;

const inst = new BridgeToNative(
defaultAmFeaturesFts,

mockedHandleRedirect,
defaultAmParams,
);
Expand All @@ -430,7 +410,7 @@ describe('BridgeToNative', () => {
])(
'should detect app scheme for version `%s` as `%s` while parameter is not passed',
(version, appId) => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion: version,
});
Expand All @@ -440,7 +420,7 @@ describe('BridgeToNative', () => {
);

it('should use app scheme from parameter', () => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative( mockedHandleRedirect, {
...defaultAmParams,
appVersion: '1.0.0',
});
Expand Down
13 changes: 2 additions & 11 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import { BridgeToNative } from '../src';

describe('BridgeToNative integration testing', () => {
const defaultAmFeaturesFts = {
linksInBrowserAndroid: true,
linksInBrowserIos: true,
};

const defaultAmParams = {
appVersion: '12.0.0',
theme: 'light',
Expand Down Expand Up @@ -57,7 +52,7 @@ describe('BridgeToNative integration testing', () => {
});

it('should use AM interface correctly when moving forward and then backward', async () => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative(mockedHandleRedirect, {
...defaultAmParams,
title: 'Initial Title',
});
Expand Down Expand Up @@ -116,7 +111,6 @@ describe('BridgeToNative integration testing', () => {

it('should act and use AM interface correctly when using `goBackAFewSteps`', async () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand Down Expand Up @@ -150,7 +144,6 @@ describe('BridgeToNative integration testing', () => {

it('should act and use AM interface correctly when using `setInitialView`', async () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand Down Expand Up @@ -179,7 +172,7 @@ describe('BridgeToNative integration testing', () => {

describe('iOS environment', () => {
it('should use AM interface correctly when moving forward and then backward', async () => {
const inst = new BridgeToNative(defaultAmFeaturesFts, mockedHandleRedirect, {
const inst = new BridgeToNative(mockedHandleRedirect, {
...defaultAmParams,
title: 'Initial Title',
});
Expand Down Expand Up @@ -246,7 +239,6 @@ describe('BridgeToNative integration testing', () => {

it('should act and use AM interface correctly when using `goBackAFewSteps`', async () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand Down Expand Up @@ -282,7 +274,6 @@ describe('BridgeToNative integration testing', () => {

it('should act and use AM interface correctly when using `setInitialView`', async () => {
const inst = new BridgeToNative(
defaultAmFeaturesFts,
mockedHandleRedirect,
defaultAmParams,
);
Expand Down
Loading

0 comments on commit 1f6456f

Please sign in to comment.