Skip to content

Commit

Permalink
fix: replace deprecated faker properties and fix tests (#511)
Browse files Browse the repository at this point in the history
* fix: replace deprecated faker properties and fix tests
* fix: fix type in shareFolderRequest
  • Loading branch information
giuliano176 authored Jan 5, 2024
1 parent b6bc202 commit 5ae0d8f
Show file tree
Hide file tree
Showing 17 changed files with 8,503 additions and 6,976 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config: Config = {
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less)$': '<rootDir>/__mocks__/fileMock.js'
},
collectCoverage: true,
collectCoverage: false,
testTimeout: 20000
};

Expand Down
15,294 changes: 8,405 additions & 6,889 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/store/actions/share-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Account, BatchRequest, soapFetch } from '@zextras/carbonio-shell-ui';
import { trim } from 'lodash';

import { Folder } from '../../carbonio-ui-commons/types/folder';
import { FolderActionGrant, FolderActionRequest } from '../../types';

export type ShareFolderDataType = {
sendNotification?: boolean;
Expand Down Expand Up @@ -35,10 +36,13 @@ export const shareFolder = createAsyncThunk(
pw: '',
inh: '1'
}
}
} as FolderActionGrant
}));

const response = await soapFetch<BatchRequest, Response>('Batch', {
const response = await soapFetch<
BatchRequest & { FolderActionRequest?: Array<FolderActionRequest> },
Response
>('Batch', {
_jsns: 'urn:zimbra',
FolderActionRequest: requests
});
Expand Down
4 changes: 2 additions & 2 deletions src/tests/generators/editorCases/editor-case-v2-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const buildEditorCase = (messagesStoreDispatch: AppDispatch): MailsEditor
const mocksContext = getMocksContext();

return {
id: faker.datatype.uuid(),
id: faker.string.uuid(),
did: FAKE_MESSAGE_ID,
action: EditViewActions.EDIT_AS_NEW,
identityId: mocksContext.identities.primary.identity.id,
Expand All @@ -30,7 +30,7 @@ export const buildEditorCase = (messagesStoreDispatch: AppDispatch): MailsEditor
plainText: 'test'
},
recipients: { to: [], cc: [], bcc: [] },
subject: faker.random.words(3),
subject: faker.lorem.words(3),
unsavedAttachments: [],
savedAttachments: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/tests/generators/generateConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const generateRandomParticipants = (count: number, type: ParticipantRoleType): A
* @param messageGenerationCount
*/
const generateConversation = ({
id = faker.datatype.number().toString(),
id = faker.number.int().toString(),
folderId = FOLDERS.INBOX,
receiveDate = faker.date.recent(1).valueOf(),
receiveDate = faker.date.recent({ days: 1 }).valueOf(),
to,
cc,
from,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/generators/generateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ type MessageGenerationParams = {
* @param isSentByMe
*/
const generateMessage = ({
id = faker.datatype.number().toString(),
id = faker.number.int().toString(),
folderId = FOLDERS.INBOX,
sendDate = faker.date.recent(2).valueOf(),
receiveDate = faker.date.recent(1).valueOf(),
sendDate = faker.date.recent({ days: 2 }).valueOf(),
receiveDate = faker.date.recent({ days: 1 }).valueOf(),
to = [{ type: ParticipantRole.TO, address: faker.internet.email() }],
cc = [],
from = { type: ParticipantRole.FROM, address: faker.internet.email() },
Expand Down
6 changes: 3 additions & 3 deletions src/tests/generators/getMsgResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ type GetMsgResponseGenerationParams = {
* @param body
*/
const generateGetMsgResponse = ({
id = faker.datatype.number().toString(),
id = faker.number.int().toString(),
folder = FOLDERS.INBOX,
sendDate = toUnixTimestamp(faker.date.recent(2)),
receiveDate = toUnixTimestamp(faker.date.recent(1)),
sendDate = toUnixTimestamp(faker.date.recent({ days: 2 })),
receiveDate = toUnixTimestamp(faker.date.recent({ days: 1 })),
to = [{ type: ParticipantRole.TO, address: faker.internet.email() }],
cc = [],
from = { type: ParticipantRole.FROM, address: faker.internet.email() },
Expand Down
26 changes: 13 additions & 13 deletions src/views/app/detail-panel/edit/tests/edit-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,27 @@ describe('Edit view', () => {
expect(btnSend).toBeDisabled();

// Reset the content of the "to" component and type the address
await user.click(toInputElement);
await user.clear(toInputElement);
await user.type(toInputElement, address);
await act(() => user.click(toInputElement));
await act(() => user.clear(toInputElement));
await act(() => user.type(toInputElement, address));

// Click on the "CC" button to show CC Recipient field
await user.click(btnCc);
await act(() => user.click(btnCc));
const ccComponent = screen.getByTestId('RecipientCc');
const ccInputElement = within(ccComponent).getByRole('textbox');

// Reset the content of the "Cc" component and type the address
await user.click(ccInputElement);
await user.clear(ccInputElement);
await user.type(ccInputElement, ccAddress);
await act(() => user.click(ccInputElement));
await act(() => user.clear(ccInputElement));
await act(() => user.type(ccInputElement, ccAddress));

// Insert a subject
await user.click(subjectInputElement);
await user.type(subjectInputElement, subject);
await act(() => user.click(subjectInputElement));
await act(() => user.type(subjectInputElement, subject));

const optionIcon = screen.getByTestId('options-dropdown-icon');
expect(optionIcon).toBeInTheDocument();
await user.click(optionIcon);
await act(() => user.click(optionIcon));
const markAsImportantOption = within(screen.getByTestId('dropdown-popper-list')).getByText(
/label\.mark_as_important/i
);
Expand All @@ -187,11 +187,11 @@ describe('Edit view', () => {
});

// Workaround of typing problem in the preset textarea
await user.clear(editorTextareaElement);
await act(() => user.clear(editorTextareaElement));

// Insert a text inside editor
await user.type(editorTextareaElement, body);
await user.click(subjectInputElement);
await act(() => user.type(editorTextareaElement, body));
await act(() => user.click(subjectInputElement));

// Check for the status of the "send" button to be enabled
expect(btnSend).toBeEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe.each`
const userFolder: Folder = {
isLink: false,
id: FOLDERS_DESCRIPTORS.USER_DEFINED.id,
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: FOLDERS_DESCRIPTORS.USER_DEFINED.desc,
activesyncdisabled: false,
recursive: false,
Expand Down
12 changes: 7 additions & 5 deletions src/views/settings/filters/parts/create-filter-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { FC, ReactElement, useCallback, useMemo, useState } from 'react';

import { Input, Container, Checkbox, Padding, Divider, Row } from '@zextras/carbonio-design-system';
import { useUserSettings } from '@zextras/carbonio-shell-ui';
import type { TFunction } from 'i18next';
import { map, omit, reduce } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { useUserSettings } from '@zextras/carbonio-shell-ui';

import { CreateFilterContext } from './create-filter-context';
import ModalFooter from './create-filter-modal-footer';
import ModalHeader from '../../../../carbonio-ui-commons/components/modals/modal-header';
import DefaultCondition from './create-filters-conditions/default';
import { CreateFilterContext } from './create-filter-context';
import { modifyFilterRules } from '../../../../store/actions/modify-filter-rules';
import FilterActionConditions from './new-filter-action-conditions';
import FilterTestConditionRow from './filter-test-condition-row';
import FilterActionConditions from './new-filter-action-conditions';
import { getButtonInfo } from './utils';
import ModalHeader from '../../../../carbonio-ui-commons/components/modals/modal-header';
import { modifyFilterRules } from '../../../../store/actions/modify-filter-rules';
import type { FilterActions } from '../../../../types';

type ComponentProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import React from 'react';
import { act, screen, within } from '@testing-library/react';

import { faker } from '@faker-js/faker';
import { act, screen, within } from '@testing-library/react';
import { t } from '@zextras/carbonio-shell-ui';
import CreateFilterModal from '../create-filter-modal';

import { setupTest } from '../../../../../carbonio-ui-commons/test/test-setup';
import { generateStore } from '../../../../../tests/generators/store';
import CreateFilterModal from '../create-filter-modal';

describe('create-filter-modal', () => {
test('create filter add filter name and by default it will be deactive', async () => {
Expand All @@ -27,13 +29,13 @@ describe('create-filter-modal', () => {
await user.clear(filterInputElement);

// Insert the new filter name into the text input
await user.type(filterInputElement, name);
await act(() => user.type(filterInputElement, name));

const filterActiveUnChecked = within(screen.getByTestId('active-filter')).getByTestId(
'icon: Square'
);
expect(filterActiveUnChecked).toBeInTheDocument();
await user.click(filterActiveUnChecked);
await act(() => user.click(filterActiveUnChecked));

const filterActiveChecked = within(screen.getByTestId('active-filter')).getByTestId(
'icon: CheckmarkSquare'
Expand Down Expand Up @@ -79,16 +81,16 @@ describe('create-filter-modal', () => {
const filterName = screen.getByTestId('filter-name');
const name = faker.lorem.word();
const filterInputElement = within(filterName).getByRole('textbox');
await user.clear(filterInputElement);
await act(() => user.clear(filterInputElement));

// Insert the new filter name into the text input
await user.type(filterInputElement, name);
await act(() => user.type(filterInputElement, name));

const filterActiveUnChecked = within(screen.getByTestId('active-filter')).getByTestId(
'icon: Square'
);
expect(filterActiveUnChecked).toBeInTheDocument();
await user.click(filterActiveUnChecked);
await act(() => user.click(filterActiveUnChecked));

const filterActiveChecked = within(screen.getByTestId('active-filter')).getByTestId(
'icon: CheckmarkSquare'
Expand All @@ -101,7 +103,7 @@ describe('create-filter-modal', () => {
const fieldLabel = screen.getByText(/settings\.field/i);
expect(fieldLabel).toBeInTheDocument();

await user.click(fieldLabel);
await act(() => user.click(fieldLabel));

const fieldAnyOption = within(screen.getByTestId('dropdown-popper-list')).getByText(
/label\.any/i
Expand Down
8 changes: 4 additions & 4 deletions src/views/sidebar/tests/delete-modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ describe('delete-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down Expand Up @@ -72,11 +72,11 @@ describe('delete-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '109',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Trash/Confluence',
l: FOLDERS.TRASH,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down
28 changes: 14 additions & 14 deletions src/views/sidebar/tests/edit-modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down Expand Up @@ -77,11 +77,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: FOLDERS.INBOX,
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'folders.inbox',
absFolderPath: '/Inbox',
l: FOLDERS.USER_ROOT,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'ui',
u: 37,
Expand Down Expand Up @@ -129,11 +129,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down Expand Up @@ -171,11 +171,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down Expand Up @@ -270,11 +270,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down Expand Up @@ -348,11 +348,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: FOLDERS.INBOX,
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'folders.inbox',
absFolderPath: '/Inbox',
l: FOLDERS.USER_ROOT,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'ui',
u: 37,
Expand Down Expand Up @@ -393,11 +393,11 @@ describe('edit-modal', () => {
const store = generateStore();
const folder: Folder = {
id: '106',
uuid: faker.datatype.uuid(),
uuid: faker.string.uuid(),
name: 'Confluence',
absFolderPath: '/Inbox/Confluence',
l: FOLDERS.INBOX,
luuid: faker.datatype.uuid(),
luuid: faker.string.uuid(),
checked: false,
f: 'u',
u: 25,
Expand Down
Loading

0 comments on commit 5ae0d8f

Please sign in to comment.