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

Don't use report for isArchived check #52805

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

srikarparsi
Copy link
Contributor

@srikarparsi srikarparsi commented Nov 20, 2024

Explanation of Change

Fixed Issues

$ #54590
PROPOSAL:

Tests

  1. Create a workspace
  2. Delete the workspace
  3. Ensure the workspace chat is
    • Moved to the bottom of the LHN
    • Has "(archived)" appended to the report title
    • Has an archived banner instead of the composer
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari image
MacOS: Desktop

@srikarparsi srikarparsi self-assigned this Nov 20, 2024
@srikarparsi
Copy link
Contributor Author

Have to fix the jest unit tests, I think we can do this by calling Onyx.set with the private_isArchived key inside the reportNameValuePairs collection

@srikarparsi
Copy link
Contributor Author

srikarparsi commented Dec 26, 2024

Update: The main problem here is the Jest unit tests. For example, Sidebar test is current failing. But running

Onyx.merge("reportNameValuePairs_<reportID>", {private_isArchived: "something"});

does change the text in the sidebar to include (archived)

Screen.Recording.2024-12-27.at.1.08.46.AM.mov

@srikarparsi
Copy link
Contributor Author

srikarparsi commented Dec 26, 2024

Hi @allgandalf, could you please take a look at this comment when you have a chance. I've been working on this PR on the side but looking to prioritize some other backend tasks so wanted to get some frontend expertise :)

This PR should set the foundation for using the reportNameValuePairs collection in the frontend. More context about that is in the linked issue

Screen.Recording.2024-12-27.at.1.56.42.AM.mov

@allgandalf
Copy link
Contributor

I will take a look and update you

@srikarparsi
Copy link
Contributor Author

srikarparsi commented Dec 26, 2024

Looking into a bit more, running Onyx.merge for the reportNameValuePairs collection from the console only seems to work for workspace chats, not other reports like DMs. Whereas Onyx.merge for the reports collection works on DMs as well (in staging).

Also, the archived chat does not float to the bottom of the LHN even when the chat isn't pinned, so looks like there's places where we're not listening to reportNameValuePairs changing but listening to reports changing.

@allgandalf
Copy link
Contributor

I will comment on the above breifly,

About the failing es lint, i think for this PR, lets ignore this workflow, our PR is already touching many parts. what do you think ? the failing es lint is because we don’t removr default assertione like policyId ?? -1

@srikarparsi
Copy link
Contributor Author

srikarparsi commented Dec 26, 2024

Yup, lets not worry about the failing lint for now, we can revisit whether or not we want to fix those once the jest tests are passing. The diff is pretty big as you said.

@srikarparsi
Copy link
Contributor Author

Hi @allgandalf! Have you had a chance to look at this?

@srikarparsi
Copy link
Contributor Author

Hi @allgandalf, did you get a chance to look at this today? Looking to merge in the next couple of days

@allgandalf
Copy link
Contributor

Oops, sorry this slipped my radar, I will surely prioritize this one today

@allgandalf
Copy link
Contributor

Working on updates here

@allgandalf
Copy link
Contributor

SidebarTest.ts

import {screen} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import DateUtils from '@libs/DateUtils';
import CONST from '@src/CONST';
import * as Localize from '@src/libs/Localize';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction';
import type {ReportNameValuePairsCollectionDataSet} from '@src/types/onyx/ReportNameValuePairs';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';

// Be sure to include the mocked Permissions and Expensicons libraries or else the beta tests won't work
jest.mock('@src/libs/Permissions');
jest.mock('@src/hooks/useActiveWorkspaceFromNavigationState');
jest.mock('@src/hooks/useIsCurrentRouteHome');
jest.mock('@src/components/Icon/Expensicons');

const TEST_USER_ACCOUNT_ID = 1;
const TEST_USER_LOGIN = '[email protected]';

describe('Sidebar', () => {
    beforeAll(() =>
        Onyx.init({
            keys: ONYXKEYS,
            safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
        }),
    );

    beforeEach(() => {
        // Wrap Onyx each onyx action with waitForBatchedUpdates
        wrapOnyxWithWaitForBatchedUpdates(Onyx);
        // Initialize the network key for OfflineWithFeedback
        return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN).then(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}));
    });

    // Clear out Onyx after each test so that each test starts with a clean slate
    afterEach(() => {
        Onyx.clear();
    });

    describe('archived chats', () => {
        it('renders the archive reason as the preview message of the chat', () => {
            const report = {
                ...LHNTestUtils.getFakeReport([1, 2], 3, true),
                chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
                lastMessageText: 'test',
            };

            const action = {
                ...LHNTestUtils.getFakeReportAction('[email protected]', 3),
                actionName: 'CLOSED',
                originalMessage: {
                    reason: CONST.REPORT.ARCHIVE_REASON.DEFAULT,
                },
            };

            const reportNameValuePairs = {
                // eslint-disable-next-line @typescript-eslint/naming-convention
                private_isArchived: DateUtils.getDBTime(),
            };

            // Given the user is in all betas
            const betas = [CONST.BETAS.DEFAULT_ROOMS];
            return (
                waitForBatchedUpdates()
                    .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0'))
                    // When Onyx is updated with the data and the sidebar re-renders
                    .then(() => {
                        const reportCollection: ReportCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
                        };

                        const reportAction: ReportActionsCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action},
                        } as ReportActionsCollectionDataSet;

                        const reportNameValuePairsCollection: ReportNameValuePairsCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]: reportNameValuePairs,
                        };

                        return Onyx.multiSet({
                            [ONYXKEYS.BETAS]: betas,
                            [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
                            [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
                            [ONYXKEYS.IS_LOADING_APP]: false,
                            ...reportNameValuePairsCollection,
                            ...reportCollection,
                            ...reportAction,
                        });
                    })
                    .then(() => {
                        const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
                        const displayNames = screen.queryAllByLabelText(hintText);
                        expect(displayNames.at(0)).toHaveTextContent('Report (archived)');

                        const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
                        const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText);
                        expect(messagePreviewTexts.at(0)).toHaveTextContent('This chat room has been archived.');
                    })
            );
        });
        it('renders the policy deleted archive reason as the preview message of the chat', () => {
            const report = {
                ...LHNTestUtils.getFakeReport([1, 2], 3, true),
                policyName: 'Vikings Policy',
                chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
                statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
                stateNum: CONST.REPORT.STATE_NUM.APPROVED,
                // eslint-disable-next-line @typescript-eslint/naming-convention
                private_isArchived: DateUtils.getDBTime(),
                lastMessageText: 'test',
            };
            const action = {
                ...LHNTestUtils.getFakeReportAction('[email protected]', 3),
                actionName: 'CLOSED',
                originalMessage: {
                    policyName: 'Vikings Policy',
                    reason: 'policyDeleted',
                },
            };

            const reportNameValuePairs = {
                // eslint-disable-next-line @typescript-eslint/naming-convention
                private_isArchived: DateUtils.getDBTime(),
            };

            // Given the user is in all betas
            const betas = [CONST.BETAS.DEFAULT_ROOMS];
            return (
                waitForBatchedUpdates()
                    .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0'))
                    // When Onyx is updated with the data and the sidebar re-renders
                    .then(() => {
                        const reportCollection: ReportCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
                        };

                        const reportAction: ReportActionsCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action},
                        } as ReportActionsCollectionDataSet;

                        const reportNameValuePairsCollection: ReportNameValuePairsCollectionDataSet = {
                            [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]: reportNameValuePairs,
                        };

                        return Onyx.multiSet({
                            [ONYXKEYS.BETAS]: betas,
                            [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
                            [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
                            [ONYXKEYS.IS_LOADING_APP]: false,
                            ...reportNameValuePairsCollection,
                            ...reportCollection,
                            ...reportAction,
                        });
                    })
                    .then(() => {
                        const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
                        const displayNames = screen.queryAllByLabelText(hintText);
                        expect(displayNames.at(0)).toHaveTextContent('Report (archived)');

                        const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
                        const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText);
                        expect(messagePreviewTexts.at(0)).toHaveTextContent('This chat is no longer active because Vikings Policy is no longer an active workspace.');
                    })
            );
        });
    });
});

@allgandalf
Copy link
Contributor

we have some conflicts here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants