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

Co 1725 conversation message store refactor #750

Open
wants to merge 158 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
fdff547
feat(store): add message slice to search store
giuliano176 Dec 9, 2024
d0f53fd
refactor: rename MessagesStore to EmailsStore
giuliano176 Dec 9, 2024
8d134c7
fix(store): remove duplicate function implementation
giuliano176 Dec 9, 2024
1211bb6
refactor(store): rename search store folder to emails in zustand
giuliano176 Dec 9, 2024
bb58ce2
refactor: update zustand store imports
giuliano176 Dec 9, 2024
edde506
refactor: restructure emails store
giuliano176 Dec 9, 2024
63e8f58
refactor: move some store functions to a dedicated folder for readibi…
giuliano176 Dec 9, 2024
a128ee1
refactor: move store functions to a dedicated folder
giuliano176 Dec 9, 2024
c9c7a13
refactor(emails): rename hooks to utils and update imports
giuliano176 Dec 9, 2024
02fdb24
refactor(search): rename hooks to utils and update imports
keshavbhatt Dec 9, 2024
104f39f
refactor: (wip)
keshavbhatt Dec 9, 2024
1fb4946
WIP
giuliano176 Dec 10, 2024
9456c71
chore: wip
keshavbhatt Dec 10, 2024
e1ff11a
refactor: simplify useEffect condition in useMessageList
giuliano176 Dec 10, 2024
1ecb3d9
fix: read proper status in message list
giuliano176 Dec 10, 2024
4fc8173
refactor: remove ternary operators in message list
giuliano176 Dec 11, 2024
24c6ff1
fix: fix removal of ternary operator
giuliano176 Dec 11, 2024
f82eb72
feat(store): add useMessagesByIds utility function
giuliano176 Dec 11, 2024
d83cf1a
feat(ui): re-enable multiple selection actions panel
giuliano176 Dec 11, 2024
c80620a
refactor: rename store slices
keshavbhatt Dec 11, 2024
e6121b5
refactor: introduce delete messages from email store
keshavbhatt Dec 11, 2024
737abc0
chore: cast constant as const
giuliano176 Dec 11, 2024
41abd02
chore: rename useLoadMore to useLoadMoreForSearchSlice
giuliano176 Dec 11, 2024
8fd5079
feat: add load more functionality for messages
giuliano176 Dec 11, 2024
115b723
refactor: cleanup, remove ternary op
keshavbhatt Dec 11, 2024
ee1fd6d
refactor: cleanup, remove unused code and fix folder navigation
keshavbhatt Dec 11, 2024
efcd5f4
refactor: bring back DragItem in message list
keshavbhatt Dec 11, 2024
24a5008
refactor: extract DragItems to separate component
giuliano176 Dec 11, 2024
5d8fb83
feat: refactor useMessageList to use folder parameter
giuliano176 Dec 12, 2024
66facb3
refactor: remove deleteMessagesFromMessageSlice function
giuliano176 Dec 12, 2024
28e8f24
refactor: use msgActionSoapApi in useMsgMoveToTrash
giuliano176 Dec 12, 2024
a9bcc5a
fix: correct folderId usage in useMessageListByFolder
giuliano176 Dec 12, 2024
7f1d568
refactor: replace msgAction with msgActionSoapApi
giuliano176 Dec 12, 2024
3a095de
refactor: use msgActionSoapApi for mark not as spam action
keshavbhatt Dec 12, 2024
296704b
refactor: use msgActionSoapApi for flag message action
keshavbhatt Dec 12, 2024
bfe1400
refactor: use msgActionSoapApi for apply Tag action
keshavbhatt Dec 12, 2024
8b1ad77
refactor: use msgActionSoapApi for set as read action
keshavbhatt Dec 12, 2024
9ba661f
refactor: use msgActionSoapApi for mark as spam action
keshavbhatt Dec 12, 2024
27e8c7e
refactor: use msgActionSoapApi for unflag action
keshavbhatt Dec 12, 2024
43f209e
refactor: use msgActionSoapApi for set as unread action
keshavbhatt Dec 12, 2024
6f2d317
refactor: use msgActionSoapApi for set as read action from header
keshavbhatt Dec 12, 2024
6cc36f9
refactor: use msgActionSoapApi for move to trash action in share folder
keshavbhatt Dec 12, 2024
033581c
refactor: lint fix
keshavbhatt Dec 12, 2024
cfefcad
refactor: use msgActionSoapApi for move to trash action in share folder
keshavbhatt Dec 12, 2024
00fb254
refactor: use msgActionSoapApi for update action in read-receipt-modal
keshavbhatt Dec 12, 2024
c3c633f
refactor: use msgActionSoapApi for move action in move-conv-msg
keshavbhatt Dec 12, 2024
f970707
refactor: use msgActionSoapApi for trash action in mail-preview-content
keshavbhatt Dec 12, 2024
2fef56b
refactor: use msgActionSoapApi for move action in accordion-custom-co…
keshavbhatt Dec 12, 2024
93344d2
refactor: remove unused message-actions
keshavbhatt Dec 12, 2024
9978123
refactor: use msgActionSoapApi for delete action in delete-conv-modal
keshavbhatt Dec 12, 2024
7d86258
refactor: remove old msg-action in favor of new msgActionSoapApi
keshavbhatt Dec 12, 2024
cfdb9ea
refactor: fix some tests + some cleanup
keshavbhatt Dec 12, 2024
fea70c9
refactor: update state types in email utils
giuliano176 Dec 12, 2024
f9584a1
test(useMsgSetUnread): fix failing test
giuliano176 Dec 12, 2024
655c70d
refactor: remove outdated TODO comment in message list
giuliano176 Dec 12, 2024
8eeec3e
test(search-view): skip SearchView tests temporarily
giuliano176 Dec 12, 2024
ec7cb59
test(use-msg-set-read): add response to API interceptor
giuliano176 Dec 12, 2024
3093cc2
test(use-msg-set-unflag): add response to API interceptor
giuliano176 Dec 12, 2024
5c33407
test(use-msg-set-flag): add response to API interceptor
giuliano176 Dec 12, 2024
ea7531e
fix(tests): re-enable multi-sel-msg-primary-actions tests
giuliano176 Dec 12, 2024
7ddaae9
test(multi-sel-msg-secondary-actions): re-enable tests
giuliano176 Dec 12, 2024
7a4da47
test(share-folder-actions): add API interceptor setup
giuliano176 Dec 12, 2024
c18940d
test(message-list): re-enable and update tests
giuliano176 Dec 12, 2024
434fca6
test(change-signatures): use 'it' instead of 'test'
giuliano176 Dec 12, 2024
a0afb45
Merge branch 'devel' into CO-1725-conversation-message-store-refactor
giuliano176 Dec 12, 2024
dcf30e6
fix(tests): update API interceptor type in tests
giuliano176 Dec 12, 2024
33fc288
refactor: extract get-msg call to api service
keshavbhatt Dec 12, 2024
d61675e
fix(search-view): add missing MsgAction response
giuliano176 Dec 13, 2024
c0a22a1
chore: fix lint issues
keshavbhatt Dec 13, 2024
63b70fe
test: add test for use-message-list-by-folder hook
keshavbhatt Dec 13, 2024
8fefe23
refactor: simplify the api response handling
keshavbhatt Dec 13, 2024
1880eac
refactor: optimize tag application logic
giuliano176 Dec 13, 2024
bc544c0
refactor: update DeleteConvConfirm export style
giuliano176 Dec 13, 2024
004ca8a
refactor: remove unused FC import and update export
giuliano176 Dec 13, 2024
e0d094e
feat(hooks): refactor debounced message request
giuliano176 Dec 16, 2024
ff94c14
type: fix type used in handleApiResponse callback
giuliano176 Dec 16, 2024
cf767ea
feat(test): add test for incomplete message retrieval
giuliano176 Dec 16, 2024
22e0919
feat(tests): add unit tests for message list hooks
giuliano176 Dec 16, 2024
5c25dd0
feat(tests): add unit tests for setMessages function
giuliano176 Dec 16, 2024
e8ac248
chore: remove unused function and test
giuliano176 Dec 16, 2024
184d415
refactor: split emails store tests into separate files
giuliano176 Dec 17, 2024
489823d
feat(tests): add comprehensive tests for message slice
giuliano176 Dec 17, 2024
e1be38f
feat: update MessageList component type definition
giuliano176 Dec 17, 2024
97c3e84
refactor: update sorting component and tests
giuliano176 Dec 17, 2024
5edb587
test: update sorting component and add new tests
giuliano176 Dec 17, 2024
0cff981
feat: refactor message handling in useMessageListByFolder
giuliano176 Dec 17, 2024
fb23801
test: add unit tests for MessageList component
giuliano176 Dec 17, 2024
1c854e9
feat: refactor error handling in appointment creation
giuliano176 Dec 18, 2024
648df7c
refactor: use zustand hooks in message preview panel
giuliano176 Dec 18, 2024
eb5dc1c
test(store): remove obsolete messages-slice test
giuliano176 Dec 18, 2024
d926868
test(hooks): remove use-request-debounced-message test
giuliano176 Dec 18, 2024
24cfa1a
fix(hooks): correct message normalization in appointment
giuliano176 Dec 18, 2024
d876dc3
fix(tests): wrap state updates in act to prevent console error
giuliano176 Dec 18, 2024
2342f8a
fix(tests): wrap state updates in act to prevent console error
giuliano176 Dec 18, 2024
18016e1
chore: minor code clean up
giuliano176 Dec 18, 2024
89e2b2f
Merge branch 'devel' into CO-1725-conversation-message-store-refactor
giuliano176 Dec 18, 2024
ea6a481
feat(shared-invite-reply): refactor folder actions
giuliano176 Dec 18, 2024
9915421
feat(tests): add response to MsgAction interceptor
giuliano176 Dec 18, 2024
23c3d2d
refactor: remove use-request-debounced-message hook
giuliano176 Dec 18, 2024
217b864
refactor: update getMsg API and inline errorSnackbar
giuliano176 Dec 18, 2024
73fd84a
refactor(store): improve state management
giuliano176 Dec 18, 2024
d3d8eba
feat: add conversation utils to emails store
giuliano176 Dec 18, 2024
83a904d
refactor: simplify conversation preview panel
giuliano176 Dec 18, 2024
6c8b512
refactor: update initial state for conversations
giuliano176 Dec 18, 2024
2d5ebae
refactor: rename messageIds to messagesIds
giuliano176 Dec 18, 2024
9cce6cf
feat: refactor conversation handling with Zustand
giuliano176 Dec 19, 2024
2327144
fix: rename conversationIds and messageIds fields
giuliano176 Dec 19, 2024
0d7b51f
fix: rename MessagesIndexSliceState to MessageIndexSliceState
giuliano176 Dec 19, 2024
d3fe9b4
fix(store): rename conversationsIndexSlice
giuliano176 Dec 19, 2024
14178bd
refactor(types): remove unused fields from state types
giuliano176 Dec 19, 2024
6d463e7
refactor: rename messagesIds to messageIdSet
giuliano176 Dec 19, 2024
154f1b4
fix(utils.ts): correct variable destructuring
giuliano176 Dec 19, 2024
e83d057
fix: update email hooks to ensure proper state reset
giuliano176 Dec 19, 2024
dadc9e1
refactor: rename messageIds to messageIdSet
giuliano176 Dec 19, 2024
9f983c2
Merge branch 'devel' into CO-1725-conversation-message-store-refactor
giuliano176 Dec 20, 2024
5ed7e38
chore: update commons
giuliano176 Dec 20, 2024
1d623cd
fix(tests): remove unused store dispatch
giuliano176 Dec 20, 2024
180f71f
fix(tests): correct key name in expected result
giuliano176 Dec 20, 2024
db82a8d
chore: update commons
giuliano176 Dec 20, 2024
e4b2d32
fix(tests): skip failing mail preview tests
giuliano176 Dec 20, 2024
d0fcade
fix(tests): update conversation list item tests
giuliano176 Dec 20, 2024
0e4c969
feat(tests): remove obsolete utils.test.ts
giuliano176 Dec 20, 2024
745d482
feat: add useConversationsByIds utility function
giuliano176 Dec 20, 2024
3632d95
feat: add tests for conversation index slice
giuliano176 Dec 20, 2024
e851112
refactor: rename and update normalize-conversation tests
giuliano176 Dec 20, 2024
2035828
feat: update test to check for conversation object
giuliano176 Dec 20, 2024
5e09b57
fix: handle undefined conversation in useCompleteConversation
giuliano176 Dec 20, 2024
b109ddc
feat(utils): update type annotation in updateMessages
giuliano176 Dec 20, 2024
615a793
fix(tests): update message generation function
giuliano176 Dec 20, 2024
78c938a
fix(tests): update message generation functions
giuliano176 Dec 20, 2024
9c55033
feat: update sorting in searchConvSoapAPI
giuliano176 Dec 23, 2024
59ae425
feat(tests): add conversation preview panel tests
giuliano176 Dec 23, 2024
183a6b1
refactor(detail-panel): simplify message retrieval
giuliano176 Dec 23, 2024
403a5c5
refactor(emails): enhance conversation message handling
giuliano176 Dec 23, 2024
5588986
refactor(detail-panel): update conversation props
giuliano176 Dec 23, 2024
ad9e912
refactor: delete unused use-conversation-list.ts
frisonisland Dec 23, 2024
386e6df
chore: TODO in message-list-item.tsx
frisonisland Dec 23, 2024
c117b78
test: update conversation-list-component.test.tsx to use new zustand …
frisonisland Dec 23, 2024
6f2834a
refactor: remove items props from conversations-multiple-selection-ac…
frisonisland Dec 23, 2024
b8b0592
test(conversations): add tests for multiple actions
giuliano176 Dec 23, 2024
f2d881a
fix(tests): update and add tests for actions
giuliano176 Dec 23, 2024
9354f24
test(search-view): re-enable conversation view tests
giuliano176 Dec 23, 2024
a10e87f
Merge branch 'devel' into CO-1725-conversation-message-store-refactor
giuliano176 Dec 23, 2024
f9c61a0
fix(conversation-list-item): correct CollapseElement prop
giuliano176 Dec 23, 2024
46909fe
chore: update commons
giuliano176 Dec 23, 2024
1991e1d
refactor(tests): replace message generator
giuliano176 Dec 23, 2024
7cdc186
refactor(tests): use message generator in tests
giuliano176 Dec 23, 2024
40a71c7
chore: remove unused code
giuliano176 Dec 23, 2024
58f97bd
refactor(tests): replace waitFor with act in tests
giuliano176 Dec 23, 2024
57f4d5d
refactor(conversations): rename prop for clarity
giuliano176 Dec 23, 2024
28543b7
fix: fix toggleOpen in conversation-list-item
giuliano176 Dec 23, 2024
7cfb591
refactor(messages): remove outdated TODO comments
giuliano176 Dec 23, 2024
9a057a5
refactor(tests): remove outdated TODO comment
giuliano176 Dec 23, 2024
11eb9d8
refactor(messages): remove types prop from hooks
giuliano176 Dec 23, 2024
2936f74
refactor(messages): simplify message normalization
giuliano176 Dec 23, 2024
433c203
feat(conversations): add load more functionality
giuliano176 Dec 23, 2024
bd8ccc8
test: add tests for conversation-list-hooks.test.tsx
frisonisland Dec 23, 2024
a24840a
refactor(folder-panel): remove redundant fragment
giuliano176 Dec 23, 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
25 changes: 25 additions & 0 deletions src/api/helpers/get-msg-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { normalizeMailMessageFromSoap } from '../../normalizations/normalize-message';
import type { MailMessage } from '../../types';
import { getMsgSoapAPI } from '../get-msg';

type GetMsgCallProps = {
msgId: string;
};

export const getMsg = async ({ msgId }: GetMsgCallProps): Promise<MailMessage> => {
const result = await getMsgSoapAPI({ msgId, max: 250000 });
const msg = result?.m[0];
return normalizeMailMessageFromSoap(msg, true) as MailMessage;
};

export const getFullMsg = async ({ msgId }: GetMsgCallProps): Promise<MailMessage> => {
const result = await getMsgSoapAPI({ msgId });
const msg = result?.m[0];
return normalizeMailMessageFromSoap(msg, true) as MailMessage;
};
42 changes: 42 additions & 0 deletions src/api/msg-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { soapFetch } from '@zextras/carbonio-shell-ui';
import { omitBy, isNil } from 'lodash';

import {
MsgActionParameters,
MsgActionRequest,
MsgActionResponse,
MsgActionResult
} from '../types';

export const msgActionSoapApi = async ({
ids,
operation,
parent,
tagName,
flag
}: MsgActionParameters): Promise<MsgActionResult> => {
const { action } = await soapFetch<MsgActionRequest, MsgActionResponse>('MsgAction', {
_jsns: 'urn:zimbraMail',

action: omitBy(
{
id: ids.join(','),
op: operation,
l: parent,
tn: tagName,
f: flag
},
isNil
)
});
return {
ids: action.id.split(','),
operation: action.op
};
};
6 changes: 4 additions & 2 deletions src/api/search-conv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { soapFetch } from '@zextras/carbonio-shell-ui';
import { AccountSettings, getUserSettings, soapFetch } from '@zextras/carbonio-shell-ui';
import { map } from 'lodash';

import { MAIL_VERIFICATION_HEADERS } from '../constants';
Expand All @@ -20,11 +20,13 @@ export async function searchConvSoapAPI({
fetch = 'all',
folderId
}: SearchConvParameters): Promise<SearchConvResponse> {
const userSettings: AccountSettings = getUserSettings();
const sortBy = userSettings.prefs.zimbraPrefConversationOrder as 'dateDesc' | 'dateAsc';
const request: SearchConvRequest = {
_jsns: 'urn:zimbraMail',
cid: conversationId,
recip: '2',
sortBy: 'dateDesc',
sortBy,
offset: 0,
fetch,
max: 250_000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getAttachmentParts } from '../../helpers/attachments';
import { getNoIdentityPlaceholder } from '../../helpers/identities';
import { useAppDispatch } from '../../hooks/redux';
import { getFullMsgAsyncThunk } from '../../store/actions';
import { retrieveFullMessage } from '../../store/zustand/search/hooks/hooks';
import { retrieveFullMessage } from '../../store/zustand/emails/hooks/hooks';
import { BodyPart, MailMessage } from '../../types';
import { useInSearchModule } from '../../ui-actions/utils';
import { getOriginalHtmlContent, getQuotedTextFromOriginalContent } from '../get-quoted-text-util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
import React from 'react';

import { act, screen, waitFor } from '@testing-library/react';
import { act, screen } from '@testing-library/react';

import { createSoapAPIInterceptor } from '../../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { setupTest } from '../../../carbonio-ui-commons/test/test-setup';
import { updateMessages } from '../../../store/zustand/search/store';
import { updateMessages } from '../../../store/zustand/emails/store';
import { generateCompleteMessageFromAPI } from '../../../tests/generators/api';
import { generateMessage } from '../../../tests/generators/generateMessage';
import { generateStore } from '../../../tests/generators/store';
Expand Down Expand Up @@ -118,8 +118,11 @@ describe('HTML message renderer', () => {
});

await interceptor;

expect(screen.queryByText('warningBanner.truncatedMessage.button')).not.toBeInTheDocument();
await act(async () => {
expect(
screen.queryByText('warningBanner.truncatedMessage.button')
).not.toBeInTheDocument();
});
});
});
it('should display empty fragment when message is set only mails store', () => {
Expand Down Expand Up @@ -241,20 +244,16 @@ describe('HTML message renderer', () => {
]
});

const { user } = setupTest(
<HtmlMessageRenderer message={message} />,

{
initialEntries: ['/mails'],
store
}
);
const { user } = setupTest(<HtmlMessageRenderer message={message} />, {
initialEntries: ['/mails'],
store
});

const loadMessageButton = await screen.findByText('warningBanner.truncatedMessage.button');
user.click(loadMessageButton);

await interceptor;
await waitFor(() => {
await act(async () => {
expect(screen.queryByText('warningBanner.truncatedMessage.button')).not.toBeInTheDocument();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export const TIMEOUTS = {
export const LIST_LIMIT = {
INITIAL_LIMIT: 100,
LOAD_MORE_LIMIT: 50
};
} as const;

export const LOCAL_STORAGES = {
EXPANDED_FOLDERS: 'open_mails_folders'
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/tests/attachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { getMsgCall } from '../../store/actions';
import { getMsg } from '../../api/helpers/get-msg-service';
import { getAttachmentParts, isContentIdEqual } from '../attachments';

describe('attachments', () => {
describe('getAttachmentParts', () => {
test('Inline attachment without content disposition are recognized anyway', async () => {
const msg = await getMsgCall({ msgId: '13' });
const msg = await getMsg({ msgId: '13' });
const attachmentParts = getAttachmentParts(msg.parts);
expect(attachmentParts).toHaveLength(1);
expect(attachmentParts[0].name).toBe('2');
Expand Down
26 changes: 22 additions & 4 deletions src/hooks/actions/test/use-msg-apply-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { setupHook } from '../../../carbonio-ui-commons/test/test-setup';
import { FOLDERS_DESCRIPTORS } from '../../../constants';
import { generateMessage } from '../../../tests/generators/generateMessage';
import { generateStore } from '../../../tests/generators/store';
import { ConvActionRequest } from '../../../types';
import { MsgActionRequest, MsgActionResponse } from '../../../types';
import { useMsgApplyTagDescriptor, useMsgApplyTagSubDescriptors } from '../use-msg-apply-tag';

jest.mock('../../../carbonio-ui-commons/store/zustand/tags', () => ({
Expand Down Expand Up @@ -167,7 +167,16 @@ describe('useMsgApplyTag', () => {
}
};
(useTags as jest.Mock).mockReturnValue(tags);
const interceptor = createSoapAPIInterceptor<ConvActionRequest>('MsgAction');
const response: MsgActionResponse = {
action: {
id: '123',
op: 'tag'
}
};
const interceptor = createSoapAPIInterceptor<MsgActionRequest, MsgActionResponse>(
'MsgAction',
response
);
const {
result: { current: descriptor }
} = setupHook(useMsgApplyTagSubDescriptors, {
Expand All @@ -185,15 +194,24 @@ describe('useMsgApplyTag', () => {
expect(requestParameter.action.l).toBeUndefined();
});

it('should call the API to add the tag from the message', async () => {
it('should call the API to add the tag to the message', async () => {
const tags = {
'1': {
id: '1',
name: 'tag 1'
}
};
(useTags as jest.Mock).mockReturnValue(tags);
const interceptor = createSoapAPIInterceptor<ConvActionRequest>('MsgAction');
const response: MsgActionResponse = {
action: {
id: '123',
op: 'tag'
}
};
const interceptor = createSoapAPIInterceptor<MsgActionRequest, MsgActionResponse>(
'MsgAction',
response
);
const {
result: { current: descriptor }
} = setupHook(useMsgApplyTagSubDescriptors, {
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/actions/test/use-msg-create-appointment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { act } from 'react';

import { FOLDERS } from '../../../carbonio-ui-commons/constants/folders';
import { useIntegratedFunction } from '../../../carbonio-ui-commons/test/mocks/carbonio-shell-ui';
import { createSoapAPIInterceptor } from '../../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { populateFoldersStore } from '../../../carbonio-ui-commons/test/mocks/store/folders';
import { setupHook } from '../../../carbonio-ui-commons/test/test-setup';
import { FOLDERS_DESCRIPTORS } from '../../../constants';
import { generateMessage } from '../../../tests/generators/generateMessage';
import { GetMsgRequest } from '../../../types';
import {
useMsgCreateAppointmentDescriptor,
useMsgCreateAppointmentFn
Expand Down Expand Up @@ -121,6 +123,23 @@ describe('useMsgCreateAppointment', () => {
})
);
});

it('should retrieve the message if the message is not complete', async () => {
const interceptor = createSoapAPIInterceptor<GetMsgRequest>('GetMsg');
populateFoldersStore();
const incompleteMsg = { ...msg, parent: FOLDERS.INBOX, isComplete: false };
const {
result: { current: functions }
} = setupHook(useMsgCreateAppointmentFn, { initialProps: [incompleteMsg, FOLDERS.INBOX] });

await act(async () => {
functions.execute();
});

const request = await interceptor;

expect(Object.keys(request)).not.toHaveLength(0);
});
});
});
});
16 changes: 13 additions & 3 deletions src/hooks/actions/test/use-msg-set-flag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { act } from 'react';

import { faker } from '@faker-js/faker';
import { times } from 'lodash';
import { act } from 'react';

import { createSoapAPIInterceptor } from '../../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { setupHook } from '../../../carbonio-ui-commons/test/test-setup';
import { API_REQUEST_STATUS } from '../../../constants';
import { generateStore } from '../../../tests/generators/store';
import { MsgActionRequest } from '../../../types';
import { MsgActionRequest, MsgActionResponse } from '../../../types';
import { useMsgSetFlagDescriptor, useMsgSetFlagFn } from '../use-msg-set-flag';

describe('useMsgSetFlag', () => {
Expand Down Expand Up @@ -92,7 +93,16 @@ describe('useMsgSetFlag', () => {
});

it('should call the API with the proper params if the action can be executed', async () => {
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest>('MsgAction');
const response: MsgActionResponse = {
action: {
id: '',
op: 'trash'
}
};
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest, MsgActionResponse>(
'MsgAction',
response
);
const ids = times(faker.number.int({ max: 20 }), () => faker.number.int().toString());

const {
Expand Down
16 changes: 13 additions & 3 deletions src/hooks/actions/test/use-msg-set-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { act } from 'react';

import { faker } from '@faker-js/faker';
import { times } from 'lodash';
import { act } from 'react';

import { FOLDERS } from '../../../carbonio-ui-commons/constants/folders';
import { createSoapAPIInterceptor } from '../../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { setupHook } from '../../../carbonio-ui-commons/test/test-setup';
import { FOLDERS_DESCRIPTORS } from '../../../constants';
import { generateStore } from '../../../tests/generators/store';
import { MsgActionRequest } from '../../../types';
import { MsgActionRequest, MsgActionResponse } from '../../../types';
import { useMsgSetReadDescriptor, useMsgSetReadFn } from '../use-msg-set-read';

describe('useMsgSetRead', () => {
Expand Down Expand Up @@ -154,7 +155,16 @@ describe('useMsgSetRead', () => {
});

it('should call the API with the proper params if the action can be executed', async () => {
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest>('MsgAction');
const response: MsgActionResponse = {
action: {
id: '',
op: 'trash'
}
};
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest, MsgActionResponse>(
'MsgAction',
response
);
const ids = times(faker.number.int({ max: 20 }), () => faker.number.int().toString());

const {
Expand Down
16 changes: 13 additions & 3 deletions src/hooks/actions/test/use-msg-set-unflag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { act } from 'react';

import { faker } from '@faker-js/faker';
import { times } from 'lodash';
import { act } from 'react';

import { createSoapAPIInterceptor } from '../../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { setupHook } from '../../../carbonio-ui-commons/test/test-setup';
import { generateStore } from '../../../tests/generators/store';
import { MsgActionRequest } from '../../../types';
import { MsgActionRequest, MsgActionResponse } from '../../../types';
import { useMsgSetUnflagDescriptor, useMsgSetUnflagFn } from '../use-msg-set-unflag';

describe('useMsgSetUnflag', () => {
Expand Down Expand Up @@ -85,7 +86,16 @@ describe('useMsgSetUnflag', () => {
});

it('should call the API with the proper params if the action can be executed', async () => {
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest>('MsgAction');
const response: MsgActionResponse = {
action: {
id: '',
op: 'trash'
}
};
const apiInterceptor = createSoapAPIInterceptor<MsgActionRequest, MsgActionResponse>(
'MsgAction',
response
);
const ids = times(faker.number.int({ max: 20 }), () => faker.number.int().toString());

const {
Expand Down
Loading