Skip to content

Commit

Permalink
test: add test to assert presence of default constrains in SOAP API call
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavbhatt committed Nov 11, 2024
1 parent 7886f06 commit ccd68d6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/types/soap/conv-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ConvActionRequest = ZimbraRequest & {
op?: ConvActionOperation;
tn?: string;
l?: string;
tcon?: string;
};
};

Expand Down
93 changes: 91 additions & 2 deletions src/ui-actions/tests/move-conv-msg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import { getFolder } from '../../carbonio-ui-commons/store/zustand/folder';
import { createSoapAPIInterceptor } from '../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { populateFoldersStore } from '../../carbonio-ui-commons/test/mocks/store/folders';
import { makeListItemsVisible, setupTest } from '../../carbonio-ui-commons/test/test-setup';
import { API_REQUEST_STATUS } from '../../constants';
import { API_REQUEST_STATUS, CONV_ACTION_CONSTRAINS } from '../../constants';
import { generateConversation } from '../../tests/generators/generateConversation';
import { generateMessage } from '../../tests/generators/generateMessage';
import { generateStore } from '../../tests/generators/store';
import { MailMessage, MsgActionRequest, MsgActionResponse } from '../../types';
import {
ConvActionRequest,
ConvActionResponse,
MailMessage,
MsgActionRequest,
MsgActionResponse
} from '../../types';
import MoveConvMessage from '../move-conv-msg';

describe('MoveConvMsg', () => {
Expand Down Expand Up @@ -224,5 +231,87 @@ describe('MoveConvMsg', () => {
expect(requestParameter.action.f).toBeUndefined();
expect(requestParameter.action.tn).toBeUndefined();
});

it('should call conv action api with default constrains when user clicks confirm', async () => {
populateFoldersStore({ view: FOLDER_VIEW.conversation });

const { children: inboxChildren } = getFolder(FOLDERS.INBOX) ?? {};
const sourceFolderId = inboxChildren?.[0].id ?? '';
const destinationFolder = FOLDERS.SENT;

const conversation = generateConversation({
folderId: sourceFolderId,
isSingleMessageConversation: false
});
const msgIdsInConversation = conversation.messages.map<string>((msg) => msg.id);

const store = generateStore({
conversations: {
currentFolder: sourceFolderId,
expandedStatus: {
[conversation.id]: API_REQUEST_STATUS.fulfilled
},
searchedInFolder: {},
conversations: {
[conversation.id]: conversation
},
searchRequestStatus: API_REQUEST_STATUS.fulfilled
}
});

const interceptor = createSoapAPIInterceptor<ConvActionRequest, ConvActionResponse>(
'ConvAction',
{
action: {
id: conversation.id,
op: 'move'
}
}
);

const component = (
<MoveConvMessage
folderId={sourceFolderId}
selectedIDs={msgIdsInConversation}
onClose={jest.fn()}
isMessageView={false}
isRestore={false}
deselectAll={jest.fn()}
dispatch={store.dispatch}
/>
);

const { user } = setupTest(component, { store });
makeListItemsVisible();

const inboxFolderListItem = await screen.findByTestId(
`folder-accordion-item-${destinationFolder}`,
{},
{ timeout: 10000 }
);

act(() => {
jest.advanceTimersByTime(1000);
});

await act(async () => {
await user.click(inboxFolderListItem);
});

const button = screen.getByRole('button', {
name: /Move/
});

await act(async () => {
await user.click(button);
});

const requestParameter = await interceptor;
expect(requestParameter.action.id).toBe(msgIdsInConversation.join(','));
expect(requestParameter.action.op).toBe('move');
expect(requestParameter.action.l).toBe(destinationFolder);
expect(requestParameter.action.tcon).toBe(CONV_ACTION_CONSTRAINS);
expect(requestParameter.action.tn).toBeUndefined();
});
});
});

0 comments on commit ccd68d6

Please sign in to comment.