Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][TS migration] Migrate multiple test to typescript #37396

Merged
merged 23 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1a63d65
[TS migration] Migrate compare, currencyUtilsTest, IOUUtilsTest, Side…
ruben-rebelo Feb 28, 2024
703bd25
[TS migration] Fixed compare
ruben-rebelo Feb 28, 2024
6b655b5
[TS migratio] Lint
ruben-rebelo Feb 29, 2024
fc7dcb7
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 1, 2024
af3fd55
[TS migration][G3] Feedback
ruben-rebelo Mar 1, 2024
8022a87
[TS migration][G3] Lint fix
ruben-rebelo Mar 1, 2024
1825d3a
[TS migration][G3] Fixed lint issue
ruben-rebelo Mar 4, 2024
3f02374
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 4, 2024
de50342
[TS migration][G3] TS fix
ruben-rebelo Mar 4, 2024
e6cdbd9
[TS migration][G3] Feedback
ruben-rebelo Mar 8, 2024
000491f
[TS migration][G3] Feedback
ruben-rebelo Mar 12, 2024
cca9a8d
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 12, 2024
fd7802b
[TS migration][G3] Feedback
ruben-rebelo Mar 12, 2024
873493f
[TS migration][G3] Updated response type
ruben-rebelo Mar 12, 2024
a4468ed
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 15, 2024
e8d3ec6
[TS migration][G3] Lint
ruben-rebelo Mar 15, 2024
a034537
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 21, 2024
c884890
[TS migration][G3] TS issue fixes
ruben-rebelo Mar 21, 2024
a0ded82
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 22, 2024
9dfd4cf
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 25, 2024
ecbdff6
Merge branch 'main' into ts-migration/group3-tests
ruben-rebelo Mar 26, 2024
3dc33fc
[TS migration][G3] TS fixes
ruben-rebelo Mar 26, 2024
3b081fd
[TS migration][G3] Fixed unit test
ruben-rebelo Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {ValueOf} from 'type-fest';
import type {FileObject} from '@components/AttachmentModal';
import type {AvatarSource} from '@libs/UserUtils';
import type CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import type * as OnyxCommon from './OnyxCommon';
import type {Decision, Reaction} from './OriginalMessage';
Expand Down Expand Up @@ -227,5 +229,7 @@ type ReportAction = ReportActionBase & OriginalMessage;

type ReportActions = Record<string, ReportAction>;

type ReportActionCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>;

export default ReportAction;
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage};
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionCollectionDataSet};
18 changes: 17 additions & 1 deletion src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type {KeysOfUnion, ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type {Participant, Split} from './IOU';
import type * as OnyxCommon from './OnyxCommon';
import type RecentWaypoint from './RecentWaypoint';
Expand Down Expand Up @@ -224,5 +226,19 @@ type AdditionalTransactionChanges = {

type TransactionChanges = Partial<Transaction> & AdditionalTransactionChanges;

type TransactionCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.TRANSACTION>;

export default Transaction;
export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, ReceiptErrors, TransactionPendingFieldsKey, TransactionChanges, TaxRate, ReceiptSource};
export type {
WaypointCollection,
Comment,
Receipt,
Waypoint,
ReceiptError,
ReceiptErrors,
TransactionPendingFieldsKey,
TransactionChanges,
TaxRate,
ReceiptSource,
TransactionCollectionDataSet,
};
53 changes: 13 additions & 40 deletions tests/e2e/compare/compare.js → tests/e2e/compare/compare.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import _ from 'underscore';
import type {Stats} from '../measure/math';
import getStats from '../measure/math';
import * as math from './math';
import type {Entry} from './output/console';
import printToConsole from './output/console';
import writeToMarkdown from './output/markdown';

type Metric = Record<string, number[]>;

/*
* base implementation from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/compare.ts
* This module reads from the baseline and compare files and compares the results.
Expand All @@ -25,14 +28,7 @@ const PROBABILITY_CONSIDERED_SIGNIFICANCE = 0.02;
*/
const DURATION_DIFF_THRESHOLD_SIGNIFICANCE = 100;

/**
*
* @param {string} name
* @param {Object} compare
* @param {Object} baseline
* @returns {Object}
*/
function buildCompareEntry(name, compare, baseline) {
function buildCompareEntry(name: string, compare: Stats, baseline: Stats): Entry {
const diff = compare.mean - baseline.mean;
const relativeDurationDiff = diff / baseline.mean;

Expand All @@ -53,20 +49,15 @@ function buildCompareEntry(name, compare, baseline) {

/**
* Compare results between baseline and current entries and categorize.
*
* @param {Object} compareEntries
* @param {Object} baselineEntries
* @returns {Object}
*/
function compareResults(compareEntries, baselineEntries) {
function compareResults(compareEntries: Metric, baselineEntries: Metric) {
// Unique test scenario names
const names = [...new Set([..._.keys(compareEntries), ..._.keys(baselineEntries || {})])];
const baselineKeys = Object.keys(baselineEntries ?? {});
const names = Array.from(new Set([...baselineKeys]));

const compared = [];
const added = [];
const removed = [];
const compared: Entry[] = [];
mountiny marked this conversation as resolved.
Show resolved Hide resolved

names.forEach((name) => {
names.forEach((name: string) => {
const current = compareEntries[name];
const baseline = baselineEntries[name];

Expand All @@ -75,38 +66,20 @@ function compareResults(compareEntries, baselineEntries) {

if (baseline && current) {
compared.push(buildCompareEntry(name, deltaStats, currentStats));
} else if (current) {
added.push({
name,
current,
});
} else if (baseline) {
removed.push({
name,
baseline,
});
}
});

const significance = _.chain(compared)
.filter((item) => item.isDurationDiffOfSignificance)
.value();
const meaningless = _.chain(compared)
.filter((item) => !item.isDurationDiffOfSignificance)
.value();
const significance = compared.filter((item) => item.isDurationDiffOfSignificance);

added.sort((a, b) => b.current.mean - a.current.mean);
removed.sort((a, b) => b.baseline.mean - a.baseline.mean);
const meaningless = compared.filter((item) => !item.isDurationDiffOfSignificance);

return {
significance,
meaningless,
added,
removed,
};
}

export default (main, delta, outputFile, outputFormat = 'all') => {
export default (main: Metric, delta: Metric, outputFile: string, outputFormat = 'all') => {
// IMPORTANT NOTE: make sure you are passing the delta/compare results first, then the main/baseline results:
const outputData = compareResults(delta, main);

Expand Down
1 change: 0 additions & 1 deletion tests/e2e/measure/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ const getStats = (entries: Entries): Stats => {
};

export default getStats;

export type {Stats};
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import CONST from '../../src/CONST';
import * as CurrencyUtils from '../../src/libs/CurrencyUtils';
import LocaleListener from '../../src/libs/Localize/LocaleListener';
import ONYXKEYS from '../../src/ONYXKEYS';
import CONST from '@src/CONST';
import * as CurrencyUtils from '@src/libs/CurrencyUtils';
import LocaleListener from '@src/libs/Localize/LocaleListener';
import ONYXKEYS from '@src/ONYXKEYS';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
// This file can get outdated. In that case, you can follow these steps to update it:
// - open your browser console and navigate to the Network tab
Expand All @@ -13,7 +12,7 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
// - update currencyList.json
import currencyList from './currencyList.json';

const currencyCodeList = _.keys(currencyList);
const currencyCodeList = Object.keys(currencyList);
const AVAILABLE_LOCALES = [CONST.LOCALES.EN, CONST.LOCALES.ES];

describe('CurrencyUtils', () => {
Expand All @@ -37,7 +36,7 @@ describe('CurrencyUtils', () => {
describe('getLocalizedCurrencySymbol', () => {
test.each(AVAILABLE_LOCALES)('Returns non empty string for all currencyCode with preferredLocale %s', (prefrredLocale) =>
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, prefrredLocale).then(() => {
_.forEach(currencyCodeList, (currencyCode) => {
currencyCodeList.forEach((currencyCode: string) => {
const localizedSymbol = CurrencyUtils.getLocalizedCurrencySymbol(currencyCode);

expect(localizedSymbol).toBeTruthy();
Expand Down
42 changes: 22 additions & 20 deletions tests/unit/IOUUtilsTest.js → tests/unit/IOUUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Onyx from 'react-native-onyx';
import * as IOUUtils from '../../src/libs/IOUUtils';
import * as ReportUtils from '../../src/libs/ReportUtils';
import * as TransactionUtils from '../../src/libs/TransactionUtils';
import ONYXKEYS from '../../src/ONYXKEYS';
import * as IOUUtils from '@src/libs/IOUUtils';
import * as ReportUtils from '@src/libs/ReportUtils';
import * as TransactionUtils from '@src/libs/TransactionUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {TransactionCollectionDataSet} from '@src/types/onyx/Transaction';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import currencyList from './currencyList.json';

Expand All @@ -25,34 +26,35 @@ describe('IOUUtils', () => {
});

test('Requesting money offline in a different currency will show the pending conversion message', () => {
const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, 1, 'USD');
const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, '1', 'USD');
const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID);
const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID);
const MergeQueries: TransactionCollectionDataSet = {};
MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = usdPendingTransaction;
MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`] = aedPendingTransaction;

return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, {
[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`]: usdPendingTransaction,
[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: aedPendingTransaction,
}).then(() => {
return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, MergeQueries).then(() => {
// We requested money offline in a different currency, we don't know the total of the iouReport until we're back online
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(true);
});
});

test('Requesting money online in a different currency will not show the pending conversion message', () => {
const iouReport = ReportUtils.buildOptimisticIOUReport(2, 3, 100, 1, 'USD');
const iouReport = ReportUtils.buildOptimisticIOUReport(2, 3, 100, '1', 'USD');
const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID);
const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID);

return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, {
[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`]: {
...usdPendingTransaction,
pendingAction: null,
},
[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: {
...aedPendingTransaction,
pendingAction: null,
},
}).then(() => {
const MergeQueries: TransactionCollectionDataSet = {};
MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = {
...usdPendingTransaction,
pendingAction: null,
};
MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`] = {
...aedPendingTransaction,
pendingAction: null,
};

return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, MergeQueries).then(() => {
// We requested money online in a different currency, we know the iouReport total and there's no need to show the pending conversion message
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(false);
});
Expand Down
Loading
Loading