Skip to content

Commit

Permalink
Merge pull request #30634 from margelo/perunt/e2e-chat-opening
Browse files Browse the repository at this point in the history
E2E chat opening
  • Loading branch information
dangrous authored Dec 14, 2023
2 parents 70e7ec3 + 7c438ac commit 1199383
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ const CONST = {
TIMING: {
CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action',
SEARCH_RENDER: 'search_render',
CHAT_RENDER: 'chat_render',
HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render',
REPORT_INITIAL_RENDER: 'report_initial_render',
SWITCH_REPORT: 'switch_report',
Expand Down
1 change: 1 addition & 0 deletions src/libs/E2E/reactNativeLaunchingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (!Metrics.canCapturePerformanceMetrics()) {
const tests: Tests = {
[E2EConfig.TEST_NAMES.AppStartTime]: require('./tests/appStartTimeTest.e2e').default,
[E2EConfig.TEST_NAMES.OpenSearchPage]: require('./tests/openSearchPageTest.e2e').default,
[E2EConfig.TEST_NAMES.ChatOpening]: require('./tests/chatOpeningTest.e2e').default,
[E2EConfig.TEST_NAMES.ReportTyping]: require('./tests/reportTypingTest.e2e').default,
};

Expand Down
62 changes: 62 additions & 0 deletions src/libs/E2E/tests/chatOpeningTest.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import E2ELogin from '@libs/E2E/actions/e2eLogin';
import mockReport from '@libs/E2E/apiMocks/openReport';
import E2EClient from '@libs/E2E/client';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

type ReportValue = {
reportID: string;
};

type OnyxData = {
value: ReportValue;
};

type MockReportResponse = {
onyxData: OnyxData[];
};

const test = () => {
// check for login (if already logged in the action will simply resolve)
console.debug('[E2E] Logging in for chat opening');
const report = mockReport() as MockReportResponse;

const {reportID} = report.onyxData[0].value;

E2ELogin().then((neededLogin) => {
if (neededLogin) {
// we don't want to submit the first login to the results
return E2EClient.submitTestDone();
}

console.debug('[E2E] Logged in, getting chat opening metrics and submitting them…');
Performance.subscribeToMeasurements((entry) => {
if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
console.debug(`[E2E] Sidebar loaded, navigating to report…`);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID));
return;
}
console.debug(`[E2E] Entry: ${JSON.stringify(entry)}`);
if (entry.name !== CONST.TIMING.CHAT_RENDER) {
return;
}

console.debug(`[E2E] Submitting!`);
E2EClient.submitTestResults({
name: 'Chat opening',
duration: entry.duration,
})
.then(() => {
console.debug('[E2E] Done with chat opening, exiting…');
E2EClient.submitTestDone();
})
.catch((err) => {
console.debug('[E2E] Error while submitting test results:', err);
});
});
});
};

export default test;
10 changes: 10 additions & 0 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Timing from '@libs/actions/Timing';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import reportWithoutHasDraftSelector from '@libs/OnyxSelectors/reportWithoutHasDraftSelector';
import Performance from '@libs/Performance';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import personalDetailsPropType from '@pages/personalDetailsPropType';
Expand Down Expand Up @@ -164,6 +166,11 @@ function ReportScreen({
const [listHeight, setListHeight] = useState(0);
const [scrollPosition, setScrollPosition] = useState({});

if (firstRenderRef.current) {
Timing.start(CONST.TIMING.CHAT_RENDER);
Performance.markStart(CONST.TIMING.CHAT_RENDER);
}

const reportID = getReportID(route);
const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}];
Expand Down Expand Up @@ -283,6 +290,9 @@ function ReportScreen({
);

useEffect(() => {
Timing.end(CONST.TIMING.CHAT_RENDER);
Performance.markEnd(CONST.TIMING.CHAT_RENDER);

fetchReportIfNeeded();
ComposerActions.setShouldShowComposeInput(true);
return () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TEST_NAMES = {
AppStartTime: 'App start time',
OpenSearchPage: 'Open search page TTI',
ReportTyping: 'Report typing',
ChatOpening: 'Chat opening',
};

/**
Expand Down Expand Up @@ -78,5 +79,8 @@ module.exports = {
autoFocus: true,
},
},
[TEST_NAMES.ChatOpening]: {
name: TEST_NAMES.ChatOpening,
},
},
};

0 comments on commit 1199383

Please sign in to comment.