Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { mockCore, mockToast } from '@/tests/utils/test-setup';
import type { UserMFAMgmtProps } from '@/types/my-account/mfa/mfa-types';
import type { UserMFAMgmtViewProps } from '@/types/my-account/mfa/mfa-types';

// ===== Mock packages =====

mockToast();
const { initMockCoreClient } = mockCore();

Expand All @@ -38,8 +36,6 @@ vi.mock('sonner', () => ({
Toaster: () => null,
}));

// ===== Local mock creators =====

const createMockUserMFAMgmtProps = (overrides?: Partial<UserMFAMgmtProps>): UserMFAMgmtProps => ({
hideHeader: false,
showActiveOnly: false,
Expand Down Expand Up @@ -69,8 +65,6 @@ const setupEnrolledTotpFactor = (
);
};

// ===== Tests =====

describe('UserMFAMgmt', () => {
let mockCoreClient: ReturnType<typeof initMockCoreClient>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { vi, describe, it, expect, afterEach } from 'vitest';
import { DeleteFactorConfirmation } from '@/components/auth0/my-account/shared/mfa/delete-factor-confirmation';
import { renderWithProviders, createMockDeleteFactorConfirmationProps } from '@/tests/utils';

// ===== Test Suite =====
describe('DeleteFactorConfirmation', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { vi, describe, it, expect, afterEach } from 'vitest';
import { MFAEmptyState } from '@/components/auth0/my-account/shared/mfa/empty-state';
import { renderWithProviders, createMockMFAEmptyStateProps } from '@/tests/utils';

// ===== Test Suite =====
describe('MFAEmptyState', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { vi, describe, it, expect, afterEach } from 'vitest';
import { MFAErrorState } from '@/components/auth0/my-account/shared/mfa/error-state';
import { renderWithProviders, createMockMFAErrorStateProps } from '@/tests/utils';

// ===== Test Suite =====
describe('MFAMFAErrorState', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { vi, describe, it, expect, afterEach } from 'vitest';
import { FactorsList } from '@/components/auth0/my-account/shared/mfa/factors-list';
import { renderWithProviders, createMockFactorsListProps } from '@/tests/utils';

// ===== Test Suite =====
describe('FactorsList', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { vi, describe, it, expect, afterEach } from 'vitest';
import { OTPVerificationForm } from '@/components/auth0/my-account/shared/mfa/otp-verification-form';
import { renderWithProviders, createMockOTPVerificationFormProps } from '@/tests/utils';

// ===== Test Suite =====
describe('OTPVerificationForm', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { renderWithProviders, createMockUserMFASetupFormProps } from '@/tests/utils';
import type { UserMFASetupFormProps } from '@/types/my-account/mfa/mfa-types';

// ===== Test Suite =====
describe('UserMFASetupForm', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';

import { DomainTable, DomainTableView } from '@/components/auth0/my-organization/domain-table';
import { DomainTable } from '@/components/auth0/my-organization/domain-table';
import * as useCoreClientModule from '@/hooks/shared/use-core-client';
import {
createMockDomain,
Expand All @@ -13,26 +13,19 @@ import {
createMockCreateAction,
createMockVerifyAction,
createMockDeleteAction,
createMockDomainTableReturn,
} from '@/tests/utils/__mocks__/my-organization/domain-management/domain.mocks';
import { renderWithProviders } from '@/tests/utils/test-provider';
import { mockCore, mockToast } from '@/tests/utils/test-setup';

// ===== Mock packages =====

mockToast();
const { initMockCoreClient } = mockCore();

// ===== Local utils =====

const waitForComponentToLoad = async () => {
return await waitFor(() => {
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
});
};

// ===== Tests =====

describe('DomainTable', () => {
const mockDomain = createMockDomain();
const mockVerifiedDomain = createMockVerifiedDomain();
Expand Down Expand Up @@ -677,35 +670,100 @@ describe('DomainTable', () => {
});
});
});
});

describe('DomainTableView', () => {
const mockDomainTable = createMockDomainTableReturn();
const defaultViewProps = {
domainTable: mockDomainTable,
schema: undefined,
styling: { variables: { common: {}, light: {}, dark: {} }, classes: {} },
hideHeader: false,
readOnly: false,
customMessages: {},
createAction: undefined,
onOpenProvider: undefined,
onCreateProvider: undefined,
};

it('renders the table and header', () => {
renderWithProviders(<DomainTableView {...defaultViewProps} />);
expect(screen.getByRole('table')).toBeInTheDocument();
expect(screen.getByText(/header.title/i)).toBeInTheDocument();
describe('table rendering', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rax7389 Could you explain a bit on why testing view component is not expected here as we already had tests written for logic component explicitly.
Also, if we considering removing them now, we should also remove the relevant mocks created for this view components under mocks folder, for e.g. createMockDomainTableReturn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout removed the unused mocks, but we should test the Public components only and check the behaviour of Internal component to make sure better integration and regression test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @rax7389 Can you resolve the conflicts?

describe('when domains are loaded', () => {
it('should display domain column', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getByText(/table.columns.domain/i)).toBeInTheDocument();
});

it('should display status column', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getByText(/table.columns.status/i)).toBeInTheDocument();
});

it('should display domain name in table row', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getAllByText(mockDomain.domain).length).toBeGreaterThan(0);
});

it('should display verified domain with verified badge', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getByText(/shared\.domain_statuses\.verified/i)).toBeInTheDocument();
});

it('should display pending domain with pending badge', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getByText(/shared\.domain_statuses\.pending/i)).toBeInTheDocument();
});
});

describe('when no domains exist', () => {
it('should display empty message', async () => {
const apiService = mockCoreClient.getMyOrganizationApiClient();
(apiService.organization.domains.list as ReturnType<typeof vi.fn>).mockResolvedValue({
response: { organization_domains: [] },
});

renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

expect(screen.getByText(/table.empty_message/i)).toBeInTheDocument();
});
});
});

it('does not render header if hideHeader is true', () => {
renderWithProviders(<DomainTableView {...defaultViewProps} hideHeader={true} />);
expect(screen.queryByText(/header.title/i)).not.toBeInTheDocument();
describe('pagination', () => {
describe('when domains are paginated', () => {
it('should render table with domain data', async () => {
renderWithProviders(<DomainTable {...createMockDomainTableProps()} />);

await waitForComponentToLoad();

const table = screen.getByRole('table');
expect(table).toBeInTheDocument();
expect(screen.getAllByText(mockDomain.domain).length).toBeGreaterThan(0);
});
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

it('disables create button if readOnly is true', () => {
renderWithProviders(<DomainTableView {...defaultViewProps} readOnly={true} />);
expect(screen.getByRole('button', { name: /create/i })).toBeDisabled();
describe('customMessages', () => {
describe('when custom header title is provided', () => {
it('should render component with customMessages prop', async () => {
renderWithProviders(
<DomainTable
{...createMockDomainTableProps({
customMessages: {
header: {
title: 'Custom Domain Title',
},
},
})}
/>,
);

await waitForComponentToLoad();

expect(screen.getByRole('table')).toBeInTheDocument();
expect(screen.getByText(/header\.title|Custom Domain Title/i)).toBeInTheDocument();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
});
});
Loading
Loading