Skip to content

Commit

Permalink
apply suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JKobrynski committed Mar 4, 2024
1 parent 87fc66f commit 96d86cb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
19 changes: 1 addition & 18 deletions src/libs/E2E/client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import Config from '../../../tests/e2e/config';
import Routes from '../../../tests/e2e/server/routes';
import type {NetworkCacheMap, TestConfig} from './types';

type TestResult = {
/** Name of the test */
name: string;

/** The branch where test were running */
branch?: string;

/** Duration in milliseconds */
duration?: number;

/** Optional, if set indicates that the test run failed and has no valid results. */
error?: string;

/** Render count */
renderCount?: number;
};
import type {NetworkCacheMap, TestConfig, TestResult} from './types';

type NativeCommandPayload = {
text: string;
Expand Down
9 changes: 9 additions & 0 deletions src/libs/E2E/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ type TestConfig = {
};

type TestResult = {
/** Name of the test */
name: string;

/** The branch where test were running */
branch?: string;

/** Duration in milliseconds */
duration?: number;

/** Optional, if set indicates that the test run failed and has no valid results. */
error?: string;

/** Render count */
renderCount?: number;
};

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/config.dev.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {Config} from './config.local';

const packageName = 'com.expensify.chat.dev';
const appPath = './android/app/build/outputs/apk/development/debug/app-development-debug.apk';

type Config = Record<string, string | number>;

const config: Config = {
MAIN_APP_PACKAGE: packageName,
DELTA_APP_PACKAGE: packageName,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/config.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ const config: Config = {
};

export default config;
export type {Config};
10 changes: 5 additions & 5 deletions tests/e2e/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ const runTests = async (): Promise<void> => {
const server = createServerInstance();
await server.start();

type Result = Record<string, number[]>;
// Create a dict in which we will store the run durations for all tests
const results: Record<string, Record<string, unknown[]>> = {};
const results: Record<string, Result> = {};

// Collect results while tests are being executed
// server.addTestResultListener((testResult) => {
server.addTestResultListener((testResult) => {
if (testResult?.error != null) {
throw new Error(`Test '${testResult.name}' failed with error: ${testResult.error}`);
}
let result: number | undefined = 0;
let result = 0;

if (testResult?.duration) {
if (testResult?.duration !== undefined) {
if (testResult.duration < 0) {
return;
}
result = testResult.duration;
}
if (testResult?.renderCount) {
if (testResult?.renderCount !== undefined) {
result = testResult.renderCount;
}

Expand Down
30 changes: 15 additions & 15 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';
import {AppState, DeviceEventEmitter, Linking} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type Animated from 'react-native-reanimated';
import * as CollectionUtils from '@libs/CollectionUtils';
import DateUtils from '@libs/DateUtils';
import * as Localize from '@libs/Localize';
Expand Down Expand Up @@ -44,17 +45,16 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({
},
}));

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
jest.mock('react-native-reanimated', () => ({
...jest.requireActual('react-native-reanimated/mock'),
...jest.requireActual<typeof Animated>('react-native-reanimated/mock'),
createAnimatedPropAdapter: jest.fn,
useReducedMotion: jest.fn,
}));

/**
* We need to keep track of the transitionEnd callback so we can trigger it in our tests
*/
let transitionEndCB: () => void | undefined;
let transitionEndCB: () => void;

type ListenerMock = {
triggerTransitionEnd: () => void;
Expand Down Expand Up @@ -119,7 +119,8 @@ beforeAll(() => {
// fetch() never gets called so it does not need mocking) or we might have fetch throw an error to test error handling
// behavior. But here we just want to treat all API requests as a generic "success" and in the cases where we need to
// simulate data arriving we will just set it into Onyx directly with Onyx.merge() or Onyx.set() etc.
global.fetch = TestHelper.getGlobalFetchMock() as typeof global.fetch;
// @ts-expect-error -- TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated
global.fetch = TestHelper.getGlobalFetchMock();

Linking.setInitialURL('https://new.expensify.com/');
appSetup();
Expand Down Expand Up @@ -315,7 +316,7 @@ describe('Unread Indicators', () => {
const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator');
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
expect(unreadIndicator).toHaveLength(1);
const reportActionID = unreadIndicator?.[0]?.props?.['data-action-id'];
const reportActionID = unreadIndicator[0]?.props?.['data-action-id'];
expect(reportActionID).toBe('4');
// Scroll up and verify that the "New messages" badge appears
scrollUpToRevealNewMessagesBadge();
Expand Down Expand Up @@ -457,10 +458,10 @@ describe('Unread Indicators', () => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNameTexts = screen.queryAllByLabelText(hintText);
expect(displayNameTexts).toHaveLength(2);
expect(displayNameTexts?.[0]?.props?.style?.fontWeight).toBe(undefined);
expect(displayNameTexts?.[0]?.props?.children?.[0]).toBe('C User');
expect(displayNameTexts?.[1]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(displayNameTexts?.[1]?.props?.children?.[0]).toBe('B User');
expect(displayNameTexts[0]?.props?.style?.fontWeight).toBe(undefined);
expect(displayNameTexts[0]?.props?.children?.[0]).toBe('C User');
expect(displayNameTexts[1]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(displayNameTexts[1]?.props?.children?.[0]).toBe('B User');
}));

xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () =>
Expand All @@ -478,7 +479,7 @@ describe('Unread Indicators', () => {
const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator');
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
expect(unreadIndicator).toHaveLength(1);
const reportActionID = unreadIndicator?.[0]?.props?.['data-action-id'];
const reportActionID = unreadIndicator[0]?.props?.['data-action-id'];
expect(reportActionID).toBe('3');
// Scroll up and verify the new messages badge appears
scrollUpToRevealNewMessagesBadge();
Expand All @@ -491,8 +492,8 @@ describe('Unread Indicators', () => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNameTexts = screen.queryAllByLabelText(hintText);
expect(displayNameTexts).toHaveLength(1);
expect(displayNameTexts?.[0]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(displayNameTexts?.[0]?.props?.children?.[0]).toBe('B User');
expect(displayNameTexts[0]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(displayNameTexts[0]?.props?.children?.[0]).toBe('B User');

// Navigate to the report again and back to the sidebar
return navigateToSidebarOption(0);
Expand All @@ -503,8 +504,8 @@ describe('Unread Indicators', () => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNameTexts = screen.queryAllByLabelText(hintText);
expect(displayNameTexts).toHaveLength(1);
expect(displayNameTexts?.[0]?.props?.style?.fontWeight).toBe(undefined);
expect(displayNameTexts?.[0]?.props?.children?.[0]).toBe('B User');
expect(displayNameTexts[0]?.props?.style?.fontWeight).toBe(undefined);
expect(displayNameTexts[0]?.props?.children?.[0]).toBe('B User');

// Navigate to the report again and verify the new line indicator is missing
return navigateToSidebarOption(0);
Expand Down Expand Up @@ -586,7 +587,6 @@ describe('Unread Indicators', () => {
}));

it('Displays the correct chat message preview in the LHN when a comment is added then deleted', () => {
// let reportActions: Record<string, ReportAction>;
let reportActions: OnyxEntry<ReportActions>;
let lastReportAction: ReportAction | undefined;
Onyx.connect({
Expand Down

0 comments on commit 96d86cb

Please sign in to comment.