From cbbfdad98c14f036cb1e27c314e96206ef97ffe9 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 6 Sep 2023 12:46:55 +0200 Subject: [PATCH 1/8] [TS migration] Migrate 'Permissions.js' lib to TypeScript --- src/libs/Permissions.js | 108 ---------------------------------------- src/libs/Permissions.ts | 69 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 108 deletions(-) delete mode 100644 src/libs/Permissions.js create mode 100644 src/libs/Permissions.ts diff --git a/src/libs/Permissions.js b/src/libs/Permissions.js deleted file mode 100644 index f37cd5bb5bf3..000000000000 --- a/src/libs/Permissions.js +++ /dev/null @@ -1,108 +0,0 @@ -import _ from 'underscore'; -import CONST from '../CONST'; - -/** - * @private - * @param {Array} betas - * @returns {Boolean} - */ -function canUseAllBetas(betas) { - return _.contains(betas, CONST.BETAS.ALL); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseChronos(betas) { - return _.contains(betas, CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUsePayWithExpensify(betas) { - return _.contains(betas, CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseDefaultRooms(betas) { - return _.contains(betas, CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); -} - -/** - * IOU Send feature is temporarily disabled. - * - * @returns {Boolean} - */ -function canUseIOUSend() { - return false; -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseWallet(betas) { - return _.contains(betas, CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseCommentLinking(betas) { - return _.contains(betas, CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); -} - -/** - * We're requiring you to be added to the policy rooms beta on dev, - * since contributors have been reporting a number of false issues related to the feature being under development. - * See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q - * @param {Array} betas - * @returns {Boolean} - */ -function canUsePolicyRooms(betas) { - return _.contains(betas, CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseTasks(betas) { - return _.contains(betas, CONST.BETAS.TASKS) || canUseAllBetas(betas); -} - -/** - * @param {Array} betas - * @returns {Boolean} - */ -function canUseCustomStatus(betas) { - return _.contains(betas, CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); -} - -/** - * Link previews are temporarily disabled. - * @returns {Boolean} - */ -function canUseLinkPreviews() { - return false; -} - -export default { - canUseChronos, - canUsePayWithExpensify, - canUseDefaultRooms, - canUseIOUSend, - canUseWallet, - canUseCommentLinking, - canUsePolicyRooms, - canUseTasks, - canUseCustomStatus, - canUseLinkPreviews, -}; diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts new file mode 100644 index 000000000000..29df07920b7b --- /dev/null +++ b/src/libs/Permissions.ts @@ -0,0 +1,69 @@ +import CONST from '../CONST'; + +function canUseAllBetas(betas: string[]): boolean { + return betas.includes(CONST.BETAS.ALL); +} + +function canUseChronos(betas: string[]): boolean { + return betas.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); +} + +function canUsePayWithExpensify(betas: string[]): boolean { + return betas.includes(CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); +} + +function canUseDefaultRooms(betas: string[]): boolean { + return betas.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); +} + +/** + * IOU Send feature is temporarily disabled. + */ +function canUseIOUSend(): boolean { + return false; +} + +function canUseWallet(betas: string[]): boolean { + return betas.includes(CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); +} + +function canUseCommentLinking(betas: string[]): boolean { + return betas.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); +} + +/** + * We're requiring you to be added to the policy rooms beta on dev, + * since contributors have been reporting a number of false issues related to the feature being under development. + * See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q + */ +function canUsePolicyRooms(betas: string[]): boolean { + return betas.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); +} + +function canUseTasks(betas: string[]): boolean { + return betas.includes(CONST.BETAS.TASKS) || canUseAllBetas(betas); +} + +function canUseCustomStatus(betas: string[]): boolean { + return betas.includes(CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); +} + +/** + * Link previews are temporarily disabled. + */ +function canUseLinkPreviews(): boolean { + return false; +} + +export default { + canUseChronos, + canUsePayWithExpensify, + canUseDefaultRooms, + canUseIOUSend, + canUseWallet, + canUseCommentLinking, + canUsePolicyRooms, + canUseTasks, + canUseCustomStatus, + canUseLinkPreviews, +}; From 53bd99cfad648e3ff8e2f0c4b49017f01822ad76 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 12 Sep 2023 15:30:01 +0200 Subject: [PATCH 2/8] Migrate __mocks__ to typescript --- src/libs/__mocks__/Log.js | 9 --------- src/libs/__mocks__/Log.ts | 9 +++++++++ src/libs/__mocks__/{Permissions.js => Permissions.ts} | 9 ++++----- 3 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/libs/__mocks__/Log.js create mode 100644 src/libs/__mocks__/Log.ts rename src/libs/__mocks__/{Permissions.js => Permissions.ts} (57%) diff --git a/src/libs/__mocks__/Log.js b/src/libs/__mocks__/Log.js deleted file mode 100644 index 179a665d2bd9..000000000000 --- a/src/libs/__mocks__/Log.js +++ /dev/null @@ -1,9 +0,0 @@ -// Set up manual mocks for any Logging methods that are supposed hit the 'server', -// this is needed because before, the Logging queue would get flushed while tests were running, -// causing unexpected calls to HttpUtils.xhr() which would cause mock mismatches and flaky tests. -export default { - info: (message) => console.debug(`[info] ${message} (mocked)`), - alert: (message) => console.debug(`[alert] ${message} (mocked)`), - warn: (message) => console.debug(`[warn] ${message} (mocked)`), - hmmm: (message) => console.debug(`[hmmm] ${message} (mocked)`), -}; diff --git a/src/libs/__mocks__/Log.ts b/src/libs/__mocks__/Log.ts new file mode 100644 index 000000000000..39336db1fa51 --- /dev/null +++ b/src/libs/__mocks__/Log.ts @@ -0,0 +1,9 @@ +// Set up manual mocks for any Logging methods that are supposed hit the 'server', +// this is needed because before, the Logging queue would get flushed while tests were running, +// causing unexpected calls to HttpUtils.xhr() which would cause mock mismatches and flaky tests. +export default { + info: (message: string) => console.debug(`[info] ${message} (mocked)`), + alert: (message: string) => console.debug(`[alert] ${message} (mocked)`), + warn: (message: string) => console.debug(`[warn] ${message} (mocked)`), + hmmm: (message: string) => console.debug(`[hmmm] ${message} (mocked)`), +}; diff --git a/src/libs/__mocks__/Permissions.js b/src/libs/__mocks__/Permissions.ts similarity index 57% rename from src/libs/__mocks__/Permissions.js rename to src/libs/__mocks__/Permissions.ts index fffaea5793d4..e1763ee2de34 100644 --- a/src/libs/__mocks__/Permissions.js +++ b/src/libs/__mocks__/Permissions.ts @@ -1,4 +1,3 @@ -import _ from 'underscore'; import CONST from '../../CONST'; /** @@ -10,8 +9,8 @@ import CONST from '../../CONST'; export default { ...jest.requireActual('../Permissions'), - canUseDefaultRooms: (betas) => _.contains(betas, CONST.BETAS.DEFAULT_ROOMS), - canUsePolicyRooms: (betas) => _.contains(betas, CONST.BETAS.POLICY_ROOMS), - canUseIOUSend: (betas) => _.contains(betas, CONST.BETAS.IOU_SEND), - canUseCustomStatus: (betas) => _.contains(betas, CONST.BETAS.CUSTOM_STATUS), + canUseDefaultRooms: (betas: string[]) => betas.includes(CONST.BETAS.DEFAULT_ROOMS), + canUsePolicyRooms: (betas: string[]) => betas.includes(CONST.BETAS.POLICY_ROOMS), + canUseIOUSend: (betas: string[]) => betas.includes(CONST.BETAS.IOU_SEND), + canUseCustomStatus: (betas: string[]) => betas.includes(CONST.BETAS.CUSTOM_STATUS), }; From db6f0660308f06a1d0a46358a21e086babedfc07 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 12 Sep 2023 15:32:05 +0200 Subject: [PATCH 3/8] Convert type string[] to OnyxTypes.Beta[] --- src/libs/Permissions.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 29df07920b7b..955419514302 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -1,18 +1,19 @@ import CONST from '../CONST'; +import * as OnyxTypes from '../types/onyx'; -function canUseAllBetas(betas: string[]): boolean { +function canUseAllBetas(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.ALL); } -function canUseChronos(betas: string[]): boolean { +function canUseChronos(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); } -function canUsePayWithExpensify(betas: string[]): boolean { +function canUsePayWithExpensify(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); } -function canUseDefaultRooms(betas: string[]): boolean { +function canUseDefaultRooms(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); } @@ -23,11 +24,11 @@ function canUseIOUSend(): boolean { return false; } -function canUseWallet(betas: string[]): boolean { +function canUseWallet(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); } -function canUseCommentLinking(betas: string[]): boolean { +function canUseCommentLinking(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); } @@ -36,15 +37,15 @@ function canUseCommentLinking(betas: string[]): boolean { * since contributors have been reporting a number of false issues related to the feature being under development. * See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q */ -function canUsePolicyRooms(betas: string[]): boolean { +function canUsePolicyRooms(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); } -function canUseTasks(betas: string[]): boolean { +function canUseTasks(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.TASKS) || canUseAllBetas(betas); } -function canUseCustomStatus(betas: string[]): boolean { +function canUseCustomStatus(betas: OnyxTypes.Beta[]): boolean { return betas.includes(CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); } From a847a314c7ad03cd1f66b5fab3e7d056a089480b Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 12 Sep 2023 18:44:06 +0200 Subject: [PATCH 4/8] Change mocks types --- src/libs/__mocks__/Permissions.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/__mocks__/Permissions.ts b/src/libs/__mocks__/Permissions.ts index e1763ee2de34..ecaafce6bf50 100644 --- a/src/libs/__mocks__/Permissions.ts +++ b/src/libs/__mocks__/Permissions.ts @@ -1,4 +1,5 @@ import CONST from '../../CONST'; +import * as OnyxTypes from '../../types/onyx'; /** * This module is mocked in tests because all the permission methods call canUseAllBetas() and that will @@ -9,8 +10,8 @@ import CONST from '../../CONST'; export default { ...jest.requireActual('../Permissions'), - canUseDefaultRooms: (betas: string[]) => betas.includes(CONST.BETAS.DEFAULT_ROOMS), - canUsePolicyRooms: (betas: string[]) => betas.includes(CONST.BETAS.POLICY_ROOMS), - canUseIOUSend: (betas: string[]) => betas.includes(CONST.BETAS.IOU_SEND), - canUseCustomStatus: (betas: string[]) => betas.includes(CONST.BETAS.CUSTOM_STATUS), + canUseDefaultRooms: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.DEFAULT_ROOMS), + canUsePolicyRooms: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.POLICY_ROOMS), + canUseIOUSend: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.IOU_SEND), + canUseCustomStatus: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.CUSTOM_STATUS), }; From 28c07c3aad6285b4f4ac41c6c711c2501de115b7 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Mon, 18 Sep 2023 15:18:46 +0200 Subject: [PATCH 5/8] Migrate Log.js --- ios/Podfile.lock | 8 ++++---- src/libs/{Log.js => Log.ts} | 34 ++++++++++++++++------------------ src/libs/__mocks__/Log.js | 9 --------- src/libs/__mocks__/Log.ts | 9 +++++++++ 4 files changed, 29 insertions(+), 31 deletions(-) rename src/libs/{Log.js => Log.ts} (70%) delete mode 100644 src/libs/__mocks__/Log.js create mode 100644 src/libs/__mocks__/Log.ts diff --git a/ios/Podfile.lock b/ios/Podfile.lock index aeb1887223cd..b2e555dcfae6 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -593,7 +593,7 @@ PODS: - React-Core - react-native-pdf (6.7.1): - React-Core - - react-native-performance (4.0.0): + - react-native-performance (5.1.0): - React-Core - react-native-plaid-link-sdk (10.0.0): - Plaid (~> 4.1.0) @@ -815,7 +815,7 @@ PODS: - RNScreens (3.21.0): - React-Core - React-RCTImage - - RNSVG (13.9.0): + - RNSVG (13.13.0): - React-Core - SDWebImage (5.11.1): - SDWebImage/Core (= 5.11.1) @@ -1255,7 +1255,7 @@ SPEC CHECKSUMS: react-native-netinfo: ccbe1085dffd16592791d550189772e13bf479e2 react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df react-native-pdf: 7c0e91ada997bac8bac3bb5bea5b6b81f5a3caae - react-native-performance: 224bd53e6a835fda4353302cf891d088a0af7406 + react-native-performance: cef2b618d47b277fb5c3280b81a3aad1e72f2886 react-native-plaid-link-sdk: 9eb0f71dad94b3bdde649c7a384cba93024af46c react-native-quick-sqlite: bcc7a7a250a40222f18913a97cd356bf82d0a6c4 react-native-render-html: 96c979fe7452a0a41559685d2f83b12b93edac8c @@ -1300,7 +1300,7 @@ SPEC CHECKSUMS: RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c RNReanimated: 020859659f64be2d30849a1fe88c821a7c3e0cbf RNScreens: d037903436160a4b039d32606668350d2a808806 - RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315 + RNSVG: ed492aaf3af9ca01bc945f7a149d76d62e73ec82 SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 diff --git a/src/libs/Log.js b/src/libs/Log.ts similarity index 70% rename from src/libs/Log.js rename to src/libs/Log.ts index e51fb74aedd5..cf139eec2682 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.ts @@ -1,45 +1,43 @@ // Making an exception to this rule here since we don't need an "action" for Log and Log should just be used directly. Creating a Log // action would likely cause confusion about which one to use. But most other API methods should happen inside an action file. /* eslint-disable rulesdir/no-api-in-views */ +import {Merge} from 'type-fest'; import Logger from 'expensify-common/lib/Logger'; import getPlatform from './getPlatform'; import pkg from '../../package.json'; import requireParameters from './requireParameters'; import * as Network from './Network'; -let timeout = null; +let timeout: NodeJS.Timeout; -/** - * @param {Object} parameters - * @param {String} parameters.expensifyCashAppVersion - * @param {Object[]} parameters.logPacket - * @returns {Promise} - */ -function LogCommand(parameters) { +type LogCommandParameters = { + expensifyCashAppVersion: string; + logPacket: string; +}; + +function LogCommand(parameters: LogCommandParameters): Promise<{requestID: string}> { const commandName = 'Log'; requireParameters(['logPacket', 'expensifyCashAppVersion'], parameters, commandName); // Note: We are forcing Log to run since it requires no authToken and should only be queued when we are offline. // Non-cancellable request: during logout, when requests are cancelled, we don't want to cancel any remaining logs - return Network.post(commandName, {...parameters, forceNetworkRequest: true, canCancel: false}); + return Network.post(commandName, {...parameters, forceNetworkRequest: true, canCancel: false}) as Promise<{requestID: string}>; } +// eslint-disable-next-line +type ServerLoggingCallbackOptions = {api_setCookie: boolean; logPacket: string}; +type RequestParams = Merge; + /** * Network interface for logger. - * - * @param {Logger} logger - * @param {Object} params - * @param {Object} params.parameters - * @param {String} params.message - * @return {Promise} */ -function serverLoggingCallback(logger, params) { - const requestParams = params; +function serverLoggingCallback(logger: Logger, params: ServerLoggingCallbackOptions): Promise<{requestID: string}> { + const requestParams = params as RequestParams; requestParams.shouldProcessImmediately = false; requestParams.shouldRetry = false; requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${pkg.version}`; if (requestParams.parameters) { - requestParams.parameters = JSON.stringify(params.parameters); + requestParams.parameters = JSON.stringify(requestParams.parameters); } clearTimeout(timeout); timeout = setTimeout(() => logger.info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); diff --git a/src/libs/__mocks__/Log.js b/src/libs/__mocks__/Log.js deleted file mode 100644 index 179a665d2bd9..000000000000 --- a/src/libs/__mocks__/Log.js +++ /dev/null @@ -1,9 +0,0 @@ -// Set up manual mocks for any Logging methods that are supposed hit the 'server', -// this is needed because before, the Logging queue would get flushed while tests were running, -// causing unexpected calls to HttpUtils.xhr() which would cause mock mismatches and flaky tests. -export default { - info: (message) => console.debug(`[info] ${message} (mocked)`), - alert: (message) => console.debug(`[alert] ${message} (mocked)`), - warn: (message) => console.debug(`[warn] ${message} (mocked)`), - hmmm: (message) => console.debug(`[hmmm] ${message} (mocked)`), -}; diff --git a/src/libs/__mocks__/Log.ts b/src/libs/__mocks__/Log.ts new file mode 100644 index 000000000000..39336db1fa51 --- /dev/null +++ b/src/libs/__mocks__/Log.ts @@ -0,0 +1,9 @@ +// Set up manual mocks for any Logging methods that are supposed hit the 'server', +// this is needed because before, the Logging queue would get flushed while tests were running, +// causing unexpected calls to HttpUtils.xhr() which would cause mock mismatches and flaky tests. +export default { + info: (message: string) => console.debug(`[info] ${message} (mocked)`), + alert: (message: string) => console.debug(`[alert] ${message} (mocked)`), + warn: (message: string) => console.debug(`[warn] ${message} (mocked)`), + hmmm: (message: string) => console.debug(`[hmmm] ${message} (mocked)`), +}; From a6f3498357c0300e9991a067a1e1eb8be10b3c3e Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 19 Sep 2023 10:47:30 +0200 Subject: [PATCH 6/8] Small changes --- ios/Podfile.lock | 8 ++++---- src/libs/Permissions.ts | 24 ++++++++++++------------ src/libs/__mocks__/Permissions.ts | 10 +++++----- tests/ui/UnreadIndicatorsTest.js | 2 ++ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b2e555dcfae6..aeb1887223cd 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -593,7 +593,7 @@ PODS: - React-Core - react-native-pdf (6.7.1): - React-Core - - react-native-performance (5.1.0): + - react-native-performance (4.0.0): - React-Core - react-native-plaid-link-sdk (10.0.0): - Plaid (~> 4.1.0) @@ -815,7 +815,7 @@ PODS: - RNScreens (3.21.0): - React-Core - React-RCTImage - - RNSVG (13.13.0): + - RNSVG (13.9.0): - React-Core - SDWebImage (5.11.1): - SDWebImage/Core (= 5.11.1) @@ -1255,7 +1255,7 @@ SPEC CHECKSUMS: react-native-netinfo: ccbe1085dffd16592791d550189772e13bf479e2 react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df react-native-pdf: 7c0e91ada997bac8bac3bb5bea5b6b81f5a3caae - react-native-performance: cef2b618d47b277fb5c3280b81a3aad1e72f2886 + react-native-performance: 224bd53e6a835fda4353302cf891d088a0af7406 react-native-plaid-link-sdk: 9eb0f71dad94b3bdde649c7a384cba93024af46c react-native-quick-sqlite: bcc7a7a250a40222f18913a97cd356bf82d0a6c4 react-native-render-html: 96c979fe7452a0a41559685d2f83b12b93edac8c @@ -1300,7 +1300,7 @@ SPEC CHECKSUMS: RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c RNReanimated: 020859659f64be2d30849a1fe88c821a7c3e0cbf RNScreens: d037903436160a4b039d32606668350d2a808806 - RNSVG: ed492aaf3af9ca01bc945f7a149d76d62e73ec82 + RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315 SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index b45984f90780..aa99d355dd88 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -1,19 +1,19 @@ import CONST from '../CONST'; -import * as OnyxTypes from '../types/onyx'; +import Beta from '../types/onyx/Beta'; -function canUseAllBetas(betas: OnyxTypes.Beta[]): boolean { +function canUseAllBetas(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.ALL); } -function canUseChronos(betas: OnyxTypes.Beta[]): boolean { +function canUseChronos(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); } -function canUsePayWithExpensify(betas: OnyxTypes.Beta[]): boolean { +function canUsePayWithExpensify(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); } -function canUseDefaultRooms(betas: OnyxTypes.Beta[]): boolean { +function canUseDefaultRooms(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); } @@ -24,11 +24,11 @@ function canUseIOUSend(): boolean { return false; } -function canUseWallet(betas: OnyxTypes.Beta[]): boolean { +function canUseWallet(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); } -function canUseCommentLinking(betas: OnyxTypes.Beta[]): boolean { +function canUseCommentLinking(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); } @@ -37,23 +37,23 @@ function canUseCommentLinking(betas: OnyxTypes.Beta[]): boolean { * since contributors have been reporting a number of false issues related to the feature being under development. * See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q */ -function canUsePolicyRooms(betas: OnyxTypes.Beta[]): boolean { +function canUsePolicyRooms(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); } -function canUseTasks(betas: OnyxTypes.Beta[]): boolean { +function canUseTasks(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.TASKS) || canUseAllBetas(betas); } -function canUseCustomStatus(betas: OnyxTypes.Beta[]): boolean { +function canUseCustomStatus(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); } -function canUseCategories(betas: OnyxTypes.Beta[]): boolean { +function canUseCategories(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.NEW_DOT_CATEGORIES) || canUseAllBetas(betas); } -function canUseTags(betas: OnyxTypes.Beta[]): boolean { +function canUseTags(betas: Beta[]): boolean { return betas.includes(CONST.BETAS.NEW_DOT_TAGS) || canUseAllBetas(betas); } diff --git a/src/libs/__mocks__/Permissions.ts b/src/libs/__mocks__/Permissions.ts index ecaafce6bf50..2c062590573e 100644 --- a/src/libs/__mocks__/Permissions.ts +++ b/src/libs/__mocks__/Permissions.ts @@ -1,5 +1,5 @@ import CONST from '../../CONST'; -import * as OnyxTypes from '../../types/onyx'; +import Beta from '../../types/onyx/Beta'; /** * This module is mocked in tests because all the permission methods call canUseAllBetas() and that will @@ -10,8 +10,8 @@ import * as OnyxTypes from '../../types/onyx'; export default { ...jest.requireActual('../Permissions'), - canUseDefaultRooms: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.DEFAULT_ROOMS), - canUsePolicyRooms: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.POLICY_ROOMS), - canUseIOUSend: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.IOU_SEND), - canUseCustomStatus: (betas: OnyxTypes.Beta[]) => betas.includes(CONST.BETAS.CUSTOM_STATUS), + canUseDefaultRooms: (betas: Beta[]) => betas.includes(CONST.BETAS.DEFAULT_ROOMS), + canUsePolicyRooms: (betas: Beta[]) => betas.includes(CONST.BETAS.POLICY_ROOMS), + canUseIOUSend: (betas: Beta[]) => betas.includes(CONST.BETAS.IOU_SEND), + canUseCustomStatus: (betas: Beta[]) => betas.includes(CONST.BETAS.CUSTOM_STATUS), }; diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index 1666ffb87400..e08acc7653cc 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -132,7 +132,9 @@ function signInAndGetAppWithUnreadChat() { return waitForPromisesToResolveWithAct() .then(() => { const hintText = Localize.translateLocal('loginForm.loginForm'); + console.log(`hintText = `, hintText); const loginForm = screen.queryAllByLabelText(hintText); + console.log(`loginForm = `, loginForm); expect(loginForm).toHaveLength(1); return TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'); From d237efaeb35d90f2ccd8736797eedb6707596acc Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 19 Sep 2023 10:53:45 +0200 Subject: [PATCH 7/8] Remove console.logs --- tests/ui/UnreadIndicatorsTest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index e08acc7653cc..1666ffb87400 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -132,9 +132,7 @@ function signInAndGetAppWithUnreadChat() { return waitForPromisesToResolveWithAct() .then(() => { const hintText = Localize.translateLocal('loginForm.loginForm'); - console.log(`hintText = `, hintText); const loginForm = screen.queryAllByLabelText(hintText); - console.log(`loginForm = `, loginForm); expect(loginForm).toHaveLength(1); return TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'); From 934a366f8c7408819ec1ad6fe9de0a10f1980880 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 19 Sep 2023 11:19:09 +0200 Subject: [PATCH 8/8] Fix tests --- src/libs/Permissions.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index aa99d355dd88..05322472a407 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -2,19 +2,19 @@ import CONST from '../CONST'; import Beta from '../types/onyx/Beta'; function canUseAllBetas(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.ALL); + return betas?.includes(CONST.BETAS.ALL); } function canUseChronos(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); } function canUsePayWithExpensify(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.PAY_WITH_EXPENSIFY) || canUseAllBetas(betas); } function canUseDefaultRooms(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas); } /** @@ -25,11 +25,11 @@ function canUseIOUSend(): boolean { } function canUseWallet(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.BETA_EXPENSIFY_WALLET) || canUseAllBetas(betas); } function canUseCommentLinking(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas); } /** @@ -38,23 +38,23 @@ function canUseCommentLinking(betas: Beta[]): boolean { * See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q */ function canUsePolicyRooms(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas); } function canUseTasks(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.TASKS) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.TASKS) || canUseAllBetas(betas); } function canUseCustomStatus(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.CUSTOM_STATUS) || canUseAllBetas(betas); } function canUseCategories(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.NEW_DOT_CATEGORIES) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.NEW_DOT_CATEGORIES) || canUseAllBetas(betas); } function canUseTags(betas: Beta[]): boolean { - return betas.includes(CONST.BETAS.NEW_DOT_TAGS) || canUseAllBetas(betas); + return betas?.includes(CONST.BETAS.NEW_DOT_TAGS) || canUseAllBetas(betas); } /**