Skip to content

Commit

Permalink
feat: [#175060613] Modify screenshot deny logic android (#2250)
Browse files Browse the repository at this point in the history
* [#175060613] use blacklist to deny screenshot  on screens

* [#175060613] insert wallet_add_card screen in the black list

* [#175060613] remove screen in white list

* [#175060613] update test according to new logic

* [#175060613] update re-computation test

Co-authored-by: fabriziofff <[email protected]>
Co-authored-by: Matteo Boschi <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2020
1 parent 3986236 commit 2e17847
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
22 changes: 10 additions & 12 deletions ts/store/reducers/__tests__/allowedSnapshotScreens.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { bonusVacanzeEnabled } from "../../../config";
import { navigateToBonusActivationCompleted } from "../../../features/bonus/bonusVacanze/navigation/action";
import BONUSVACANZE_ROUTES from "../../../features/bonus/bonusVacanze/navigation/routes";
import ROUTES from "../../../navigation/routes";
import { applicationChangeState } from "../../actions/application";
import { setDebugModeEnabled } from "../../actions/debug";
import {
isAllowedSnapshotCurrentScreen,
screenWhiteList
screenBlackList
} from "../allowedSnapshotScreens";
import { appReducer } from "../index";
import { GlobalState } from "../types";
Expand All @@ -20,12 +21,9 @@ jest.mock("react-native-share", () => ({

describe("allowed Snapshot Screens Selector test", () => {
it("Test high level composition", () => {
// with a screen not snapshottable, expected false
// with a blacklisted screen, expected false
expect(
isAllowedSnapshotCurrentScreen.resultFunc(
"NOT_SNAPSHOTTABLE_SCREEN",
false
)
isAllowedSnapshotCurrentScreen.resultFunc(ROUTES.WALLET_ADD_CARD, false)
).toBeFalsy();
// with the debug mode enabled, expected true
expect(
Expand All @@ -49,11 +47,11 @@ describe("allowed Snapshot Screens Selector test", () => {
).toBeTruthy();
}
});
it("Test all allowed screens", () => {
screenWhiteList.forEach(screen => {
it("Test all blacklisted screens", () => {
screenBlackList.forEach(screen => {
expect(
isAllowedSnapshotCurrentScreen.resultFunc(screen, false)
).toBeTruthy();
).toBeFalsy();
expect(
isAllowedSnapshotCurrentScreen.resultFunc(screen, true)
).toBeTruthy();
Expand All @@ -65,12 +63,12 @@ describe("allowed Snapshot Screens Selector test", () => {
undefined,
applicationChangeState("active")
);
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeFalsy();
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeFalsy();
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeTruthy();
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeTruthy();
// with the same state, only one computation is expected
expect(isAllowedSnapshotCurrentScreen.recomputations()).toBe(1);
globalState = appReducer(globalState, setDebugModeEnabled(false));
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeFalsy();
expect(isAllowedSnapshotCurrentScreen(globalState)).toBeTruthy();
// with a change of state but the same values, no new computation are expected
expect(isAllowedSnapshotCurrentScreen.recomputations()).toBe(1);
globalState = appReducer(globalState, setDebugModeEnabled(true));
Expand Down
17 changes: 3 additions & 14 deletions ts/store/reducers/allowedSnapshotScreens.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { createSelector } from "reselect";
import { bonusVacanzeEnabled } from "../../config";
import BONUSVACANZE_ROUTES from "../../features/bonus/bonusVacanze/navigation/routes";
import ROUTES from "../../navigation/routes";
import { isDebugModeEnabledSelector } from "./debug";
import { plainNavigationCurrentRouteSelector } from "./navigation";

const defaultScreenWhiteList: ReadonlyArray<string> = [
ROUTES.WALLET_HOME,
ROUTES.WALLET_TRANSACTION_DETAILS
];
const defaultScreenBlackList: ReadonlyArray<string> = [ROUTES.WALLET_ADD_CARD];

const screenBonusVacanzaWhiteList: ReadonlyArray<string> = [
BONUSVACANZE_ROUTES.BONUS_ACTIVE_DETAIL_SCREEN
];

export const screenWhiteList = bonusVacanzeEnabled
? new Set([...defaultScreenWhiteList, ...screenBonusVacanzaWhiteList])
: new Set(defaultScreenWhiteList);
export const screenBlackList = new Set(defaultScreenBlackList);

/**
* Return {true} if the current screen can be snapshotted (android only).
Expand All @@ -25,5 +14,5 @@ export const screenWhiteList = bonusVacanzeEnabled
export const isAllowedSnapshotCurrentScreen = createSelector(
[plainNavigationCurrentRouteSelector, isDebugModeEnabledSelector],
(currentRoute, debugEnabled) =>
debugEnabled ? true : screenWhiteList.has(currentRoute)
debugEnabled ? true : !screenBlackList.has(currentRoute)
);

0 comments on commit 2e17847

Please sign in to comment.