Skip to content

Commit

Permalink
refactor(zimbra): tests & improve test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Tristan WAGNER <[email protected]>
  • Loading branch information
tristanwagner committed Oct 11, 2024
1 parent a4d4d15 commit 1a078d8
Show file tree
Hide file tree
Showing 67 changed files with 1,086 additions and 1,420 deletions.
1 change: 1 addition & 0 deletions packages/manager/apps/zimbra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
154 changes: 83 additions & 71 deletions packages/manager/apps/zimbra/src/api/_mock_/account.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,94 @@
import { AccountType } from '@/api/account';
import { ResourceStatus } from '@/api/api.type';

export const accountMock: AccountType[] = [
{
checksum: 'string',
currentState: {
contactInformation: {
city: 'string',
company: 'string',
country: 'string',
faxNumber: 'string',
mobileNumber: 'string',
office: 'string',
phoneNumber: 'string',
postcode: 'string',
profession: 'string',
service: 'string',
street: 'string',
},
createdAt: '2024-07-09T13:27:12.775Z',
description: 'string',
detailedStatus: [
{
details: 'string',
link: 'string',
status: 'BLOCKEDFORSPAM',
},
],
displayName: 'string',
domainId: '19097ad4-2870-4000-8bb0-470f414b0301',
email: 'string',
firstName: 'string',
hideInGal: false,
lastConnectionAt: '2024-07-09T13:27:12.775Z',
lastName: 'string',
offer: 'BUSINESS',
organizationId: '19097ad4-2870-4000-82b3-b71a147bc580',
organizationLabel: 'string',
quota: {
available: 0,
used: 0,
},
updatedAt: '2024-07-09T13:27:12.775Z',
export const accountDetailMock: AccountType = {
checksum: 'string',
currentState: {
contactInformation: {
city: 'string',
company: 'string',
country: 'string',
faxNumber: 'string',
mobileNumber: 'string',
office: 'string',
phoneNumber: 'string',
postcode: 'string',
profession: 'string',
service: 'string',
street: 'string',
},
currentTasks: [
createdAt: '2024-07-09T13:27:12.775Z',
description: 'string',
detailedStatus: [
{
id: '19097ad4-2870-4000-8bed-ecab3a061780',
details: 'string',
link: 'string',
status: 'ERROR',
type: 'string',
status: 'BLOCKEDFORSPAM',
},
],
id: '19097ad4-2880-4000-8b03-9d110f0b8f80',
resourceStatus: ResourceStatus.CREATING,
targetSpec: {
contactInformation: {
city: 'string',
company: 'string',
country: 'string',
faxNumber: 'string',
mobileNumber: 'string',
office: 'string',
phoneNumber: 'string',
postcode: 'string',
profession: 'string',
service: 'string',
street: 'string',
},
description: 'string',
displayName: 'string',
email: 'string',
firstName: 'string',
hideInGal: false,
lastName: 'string',
quota: {
available: 0,
used: 0,
},
displayName: 'string',
domainId: '19097ad4-2870-4000-8bb0-470f414b0301',
email: 'string',
firstName: 'string',
hideInGal: false,
lastConnectionAt: '2024-07-09T13:27:12.775Z',
lastName: 'string',
offer: 'BUSINESS',
organizationId: '19097ad4-2870-4000-82b3-b71a147bc580',
organizationLabel: 'string',
quota: {
available: 0,
used: 0,
},
updatedAt: '2024-07-09T13:27:12.775Z',
},
currentTasks: [
{
id: '19097ad4-2870-4000-8bed-ecab3a061780',
link: 'string',
status: 'ERROR',
type: 'string',
},
],
id: '19097ad4-2880-4000-8b03-9d110f0b8f80',
resourceStatus: ResourceStatus.READY,
targetSpec: {
contactInformation: {
city: 'string',
company: 'string',
country: 'string',
faxNumber: 'string',
mobileNumber: 'string',
office: 'string',
phoneNumber: 'string',
postcode: 'string',
profession: 'string',
service: 'string',
street: 'string',
},
description: 'string',
displayName: 'string',
email: 'string',
firstName: 'string',
hideInGal: false,
lastName: 'string',
quota: {
available: 0,
used: 0,
},
},
};

export const accountsMock: AccountType[] = [
accountDetailMock,
{
...accountDetailMock,
id: '19097ad4-2880-4444-8b03-9d110f0b8f80',
resourceStatus: ResourceStatus.CREATING,
},
{
...accountDetailMock,
id: '19097ad4-2880-5555-8b03-9d110f0b8f80',
resourceStatus: ResourceStatus.ERROR,
},
];
70 changes: 36 additions & 34 deletions packages/manager/apps/zimbra/src/api/_mock_/domain.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import { DomainType } from '@/api/domain';
import { ResourceStatus } from '@/api/api.type';

export const domainMock: DomainType[] = [
{
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
resourceStatus: ResourceStatus.READY,
checksum: 'string',
targetSpec: {
organizationId: '00000000-0000-0000-0000-000000000000',
},
currentState: {
organizationId: '00000000-0000-0000-0000-000000000000',
name: 'NormalDomain',
status: 'READY',
createdAt: '2024-04-12T12:27:47.213Z',
updatedAt: '2024-04-12T12:27:47.213Z',
organizationLabel: 'ToyStory',
cnameToCheck: '',
accountsStatistics: [
{
offer: 'STARTER',
configuredAccountsCount: 0,
availableAccountsCount: 4,
},
],
expectedDNSConfig: {
mx: [],
ownership: {
cname: null,
},
},
},
currentTasks: [
export const domainDetailMock: DomainType = {
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
resourceStatus: ResourceStatus.READY,
checksum: 'string',
targetSpec: {
organizationId: '00000000-0000-0000-0000-000000000000',
},
currentState: {
organizationId: '00000000-0000-0000-0000-000000000000',
name: 'NormalDomain',
status: 'READY',
createdAt: '2024-04-12T12:27:47.213Z',
updatedAt: '2024-04-12T12:27:47.213Z',
organizationLabel: 'ToyStory',
cnameToCheck: '',
accountsStatistics: [
{
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
type: 'string',
link: 'string',
offer: 'STARTER',
configuredAccountsCount: 0,
availableAccountsCount: 4,
},
],
expectedDNSConfig: {
mx: [],
ownership: {
cname: null,
},
},
},
currentTasks: [
{
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
type: 'string',
link: 'string',
},
],
};

export const domainsMock: DomainType[] = [
domainDetailMock,
{
id: '3fa91f64-0000-4562-b3fc-000000000000',
resourceStatus: ResourceStatus.READY,
Expand Down
1 change: 1 addition & 0 deletions packages/manager/apps/zimbra/src/api/_mock_/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './organization';
export * from './domain';
export * from './account';
export * from './alias';
export * from './task';
21 changes: 21 additions & 0 deletions packages/manager/apps/zimbra/src/api/_mock_/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const taskDetailMock = {
createdAt: 'string',
errors: [{ message: 'string' }],
finishedAt: 'string',
id: '1',
link: 'string',
message: 'string',
progress: [{ name: 'string', status: 'string' }],
startedAt: 'string',
status: 'string',
type: 'string',
updatedAt: 'string',
};

export const taskMocks = [
taskDetailMock,
{ ...taskDetailMock, id: '2' },
{ ...taskDetailMock, id: '3' },
{ ...taskDetailMock, id: '4' },
{ ...taskDetailMock, id: '5' },
];
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export const Breadcrumb: React.FC<BreadcrumbProps> = ({
...items,
].filter(Boolean);

return <OsdsBreadcrumb className="mb-4" items={breadcrumbItems} />;
return (
<OsdsBreadcrumb
data-testid="breadcrumb"
className="mb-4"
items={breadcrumbItems}
/>
);
};

export default Breadcrumb;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { describe, expect } from 'vitest';
import { render } from '@/utils/test.provider';
import Breadcrumb from '../Breadcrumb';

describe('Breadcrumb component', () => {
it('should render', async () => {
const { getByTestId } = render(<Breadcrumb />);
const cmp = getByTestId('breadcrumb');
expect(cmp).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ButtonTooltip: React.FC<ButtonTooltipProps> = (props) => {
variant={ODS_BUTTON_VARIANT.stroked}
color={ODS_THEME_COLOR_INTENT.primary}
onClick={(event) => handleTooltipToggle(event)}
data-testid="button-tooltip"
circle
>
<OsdsIcon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { describe, expect } from 'vitest';
import { render } from '@/utils/test.provider';
import ButtonTooltip from '../ButtonTooltip';

describe('ButtonTooltip component', () => {
it('should render', async () => {
const { getByTestId } = render(
<ButtonTooltip tooltipContent={[{ label: 'Test' }]} />,
);
const cmp = getByTestId('button-tooltip');
expect(cmp).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { describe, expect, vi } from 'vitest';
import { render } from '@/utils/test.provider';
import ErrorBanner from '../Error';

vi.mock('@ovh-ux/manager-react-core-application', async (importActual) => {
return {
...(await importActual<
typeof import('@ovh-ux/manager-react-core-application')
>()),
useShell: vi.fn(() => ({
tracking: {
trackPage: vi.fn(),
},
environment: {
getEnvironment: vi.fn(() => Promise.resolve({})),
},
})),
};
});

describe('Error component', () => {
it('should render', async () => {
const { getByText } = render(
<ErrorBanner error={{ data: { message: 'test' } }} />,
);
expect(getByText('test')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Loading({
size = ODS_SPINNER_SIZE.md,
}) {
return (
<div className={className}>
<div data-testid="spinner" className={className}>
<OsdsSpinner mode={mode} size={size} inline></OsdsSpinner>
</div>
);
Expand Down
18 changes: 4 additions & 14 deletions packages/manager/apps/zimbra/src/components/Modals/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from 'react';
import {
OsdsButton,
OsdsModal,
OsdsSpinner,
} from '@ovhcloud/ods-components/react';
import { OsdsButton, OsdsModal } from '@ovhcloud/ods-components/react';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { ODS_BUTTON_VARIANT, ODS_SPINNER_MODE } from '@ovhcloud/ods-components';
import { ODS_BUTTON_VARIANT } from '@ovhcloud/ods-components';
import Loading from '@/components/Loading/Loading';

export interface ButtonType {
testid?: string;
Expand Down Expand Up @@ -47,14 +44,7 @@ const Modal: React.FC<ModalProps> = ({
onOdsModalClose={onDismissible}
>
{!isLoading && <div className="flex flex-col text-left">{children}</div>}
{isLoading && (
<div className="flex flex-col text-left">
<OsdsSpinner
mode={ODS_SPINNER_MODE.indeterminate}
inline
></OsdsSpinner>
</div>
)}
{isLoading && <Loading />}

{secondaryButton && (
<OsdsButton
Expand Down
Loading

0 comments on commit 1a078d8

Please sign in to comment.