@@ -3,8 +3,11 @@ import React from 'react';
33import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
44import OptionListContextProvider , { useOptionsList } from '@components/OptionListContextProvider' ;
55import useOnyx from '@hooks/useOnyx' ;
6- import { createOptionList } from '@libs/OptionsListUtils' ;
6+ import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap' ;
7+ import type { OptionList , SearchOption } from '@libs/OptionsListUtils' ;
8+ import { createOptionFromReport , createOptionList } from '@libs/OptionsListUtils' ;
79import ONYXKEYS from '@src/ONYXKEYS' ;
10+ import type { Report } from '@src/types/onyx' ;
811
912jest . mock ( '@libs/OptionsListUtils' , ( ) => {
1013 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -19,13 +22,16 @@ jest.mock('@libs/OptionsListUtils', () => {
1922} ) ;
2023
2124jest . mock ( '@hooks/useOnyx' , ( ) => jest . fn ( ) ) ;
25+ jest . mock ( '@hooks/usePrivateIsArchivedMap' , ( ) => jest . fn ( ) ) ;
2226jest . mock ( '@components/OnyxListItemProvider' , ( ) => ( {
2327 usePersonalDetails : jest . fn ( ) ,
2428} ) ) ;
2529
2630const mockCreateOptionList = createOptionList as jest . MockedFunction < typeof createOptionList > ;
31+ const mockCreateOptionFromReport = createOptionFromReport as jest . MockedFunction < typeof createOptionFromReport > ;
2732const mockUseOnyx = useOnyx as jest . MockedFunction < typeof useOnyx > ;
2833const mockUsePersonalDetails = usePersonalDetails as jest . MockedFunction < typeof usePersonalDetails > ;
34+ const mockUsePrivateIsArchivedMap = usePrivateIsArchivedMap as jest . MockedFunction < typeof usePrivateIsArchivedMap > ;
2935
3036const wrapper : React . FC < { children : React . ReactNode } > = ( { children} ) => < OptionListContextProvider > { children } </ OptionListContextProvider > ;
3137
@@ -49,6 +55,7 @@ describe('OptionListContextProvider', () => {
4955
5056 mockCreateOptionList . mockReturnValue ( { reports : [ ] , personalDetails : [ ] } ) ;
5157 mockUsePersonalDetails . mockReturnValue ( { } ) ;
58+ mockUsePrivateIsArchivedMap . mockReturnValue ( { } ) ;
5259
5360 mockUseOnyx . mockImplementation ( ( ( key : string ) => {
5461 if ( key === ONYXKEYS . DERIVED . REPORT_ATTRIBUTES ) {
@@ -114,4 +121,54 @@ describe('OptionListContextProvider', () => {
114121
115122 expect ( mockCreateOptionList ) . toHaveBeenCalledTimes ( 1 ) ;
116123 } ) ;
124+
125+ it ( 'passes privateIsArchived to createOptionFromReport when personal details change' , ( ) => {
126+ const reportID = '1' ;
127+ const accountID = '12345' ;
128+ const reportKey = `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ;
129+ const report = {
130+ reportID,
131+ participants : { [ accountID ] : { notificationPreference : 'always' } } ,
132+ } ;
133+
134+ const archivedKey = `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ reportID } ` ;
135+ mockUsePrivateIsArchivedMap . mockReturnValue ( { [ archivedKey ] : 'true' } ) ;
136+
137+ const initialPersonalDetails = { [ accountID ] : { accountID : Number ( accountID ) , firstName : 'John' , lastName : 'Doe' , login : 'john@test.com' , displayName : 'John Doe' } } ;
138+ mockUsePersonalDetails . mockReturnValue ( initialPersonalDetails ) ;
139+
140+ onyxState = {
141+ ...onyxState ,
142+ [ ONYXKEYS . COLLECTION . REPORT ] : { [ reportKey ] : report } ,
143+ } ;
144+ onyxSourceValues = {
145+ ...onyxSourceValues ,
146+ [ ONYXKEYS . COLLECTION . REPORT ] : { [ reportKey ] : report } ,
147+ } ;
148+
149+ const mockReportOption = { reportID, item : report , text : 'John Doe' , keyForList : reportID } as unknown as SearchOption < Report > ;
150+ mockCreateOptionList . mockReturnValue ( {
151+ reports : [ mockReportOption ] ,
152+ personalDetails : [ ] ,
153+ } as OptionList ) ;
154+ mockCreateOptionFromReport . mockReturnValue ( mockReportOption ) ;
155+
156+ const { result, rerender} = renderHook ( ( { shouldInitialize} ) => useOptionsList ( { shouldInitialize} ) , {
157+ initialProps : { shouldInitialize : false } ,
158+ wrapper,
159+ } ) ;
160+
161+ act ( ( ) => {
162+ result . current . initializeOptions ( ) ;
163+ } ) ;
164+
165+ mockCreateOptionFromReport . mockClear ( ) ;
166+
167+ // Change personal details to trigger the update effect
168+ const updatedPersonalDetails = { [ accountID ] : { accountID : Number ( accountID ) , firstName : 'Jane' , lastName : 'Doe' , login : 'john@test.com' , displayName : 'Jane Doe' } } ;
169+ mockUsePersonalDetails . mockReturnValue ( updatedPersonalDetails ) ;
170+ rerender ( { shouldInitialize : false } ) ;
171+
172+ expect ( mockCreateOptionFromReport ) . toHaveBeenCalledWith ( report , updatedPersonalDetails , expect . any ( Number ) , 'true' , undefined , { showPersonalDetails : true } ) ;
173+ } ) ;
117174} ) ;
0 commit comments