Skip to content
Merged
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 @@ -10,7 +10,7 @@ import { SaveValidationContextProvider } from '@/src/context/SaveValidationConte
import { DEFAULT_ETAG } from '@/src/constants/api-headers';
import { InterceptorTemplate } from '@/src/models/interceptor-template';
import { DialInterceptor } from '@/src/models/dial/interceptor';
import { getInterceptorsList } from '../../interceptors/actions';
import { getInterceptorsList } from '@/src/app/[lang]/interceptors/actions';
import { filterNames } from '@/src/utils/entities/filter-names';
import { ApplicationRoute } from '@/src/types/routes';
import { getIsEnableAuthToggle } from '@/src/utils/env/get-auth-toggle';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import AddEntitiesView from '../AddEntitiesView';
import { ButtonsI18nKey, EntitiesI18nKey } from '@/src/constants/i18n';
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import AddEntitiesView from '../AddEntitiesView';

// Mock createPortal to render modal content inline for test simplicity
vi.mock('react-dom', () => ({
Expand All @@ -10,7 +10,7 @@ vi.mock('react-dom', () => ({
}));

describe('AddEntitiesView', () => {
it('renders the view title and entity count', () => {
test('renders the view title and entity count', () => {
const customColumns = [{ field: 'custom', headerName: 'Custom' }];
render(
<AddEntitiesView
Expand All @@ -25,7 +25,7 @@ describe('AddEntitiesView', () => {
expect(screen.getByText(EntitiesI18nKey.NoEntities)).toBeInTheDocument();
});

it('calls onAdd when AddEntitiesGrid onApply is triggered', () => {
test('calls onAdd when AddEntitiesGrid onApply is triggered', () => {
const onAdd = vi.fn();
const models = [{ id: '1', name: 'Model1' }];
render(<AddEntitiesView models={models} applications={[]} roles={[]} keys={[]} onAdd={onAdd} />);
Expand All @@ -37,14 +37,14 @@ describe('AddEntitiesView', () => {
fireEvent.click(modalButtons[1]);
});

it('calls onRemove when remove operation is triggered', () => {
test('calls onRemove when remove operation is triggered', () => {
const onRemove = vi.fn();
const models = [{ id: '1', name: 'Model1' }];
render(<AddEntitiesView models={models} applications={[]} roles={[]} keys={[]} onRemove={onRemove} />);
expect(typeof onRemove).toBe('function');
});

it('renders with getRelevantDataForEntity', () => {
test('renders with getRelevantDataForEntity', () => {
const getRelevantDataForEntity = vi.fn(() => []);
render(
<AddEntitiesView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react';
import SingleValueChart from './SingleValueChart';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, vi, test } from 'vitest';
import { BasicI18nKey } from '@/src/constants/i18n';

const validQuery = {
Expand All @@ -20,17 +20,17 @@ const defaultProps = {
};

describe('SingleValueChart', () => {
it('renders the title as text', () => {
test('renders the title as text', () => {
render(<SingleValueChart {...defaultProps} />);
expect(screen.getByText('Test Title')).toBeInTheDocument();
});

it('renders the unit if provided', async () => {
test('renders the unit if provided', async () => {
render(<SingleValueChart {...defaultProps} />);
expect(await screen.findByText('ms')).toBeInTheDocument();
});

it('renders NoDataContent if data is null', async () => {
test('renders NoDataContent if data is null', async () => {
mockGetData.mockResolvedValueOnce({ success: false } as any);
render(<SingleValueChart {...defaultProps} />);
expect(await screen.findByText(BasicI18nKey.NoData)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeAll, describe, expect, it, test, vi } from 'vitest';

import AttachmentInput from './AttachmentInput';
import { AttachmentsI18nKey } from '@/src/constants/i18n';
Expand All @@ -26,14 +26,14 @@ const options = [
];

describe('Common components - AttachmentInput', () => {
it('renders tags from initialValues', () => {
test('renders tags from initialValues', () => {
render(<AttachmentInput availableItems={options} initialValues={['pdf']} />);

expect(screen.getByText('PDF')).toBeInTheDocument();
expect(screen.getByRole('button', { name: AttachmentsI18nKey.UseAll })).toBeInTheDocument();
});

it('filters suggestions while typing and adds one on click', async () => {
test('filters suggestions while typing and adds one on click', async () => {
const onChange = vi.fn();
render(<AttachmentInput availableItems={options} onChange={onChange} />);

Expand All @@ -50,7 +50,7 @@ describe('Common components - AttachmentInput', () => {
expect(screen.queryByRole('list ')).toBeNull();
});

it('selects all items with the “Select all” button and resets on remove', async () => {
test('selects all items with the “Select all” button and resets on remove', async () => {
const onChange = vi.fn();
render(<AttachmentInput availableItems={options} onChange={onChange} allValueLabel="ALL VALUES" />);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EntitiesI18nKey } from '@/src/constants/i18n';
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { describe, expect, test } from 'vitest';
import FolderList from './FolderList';
import { EntitiesI18nKey } from '@/src/constants/i18n';

const fakeContext = () => ({
files: [],
Expand All @@ -16,7 +16,7 @@ const fakeContext = () => ({
});

describe('FolderList', () => {
it('renders no data message when files are empty', () => {
test('renders no data message when files are empty', () => {
render(<FolderList context={fakeContext} />);
expect(screen.getByText(EntitiesI18nKey.NoFolders)).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { describe, expect, test } from 'vitest';
import LabelledText from './LabelledText';

describe('LabelledText', () => {
it('renders label and text', () => {
test('renders label and text', () => {
render(<LabelledText label="Test Label" text="Test Text" />);
expect(screen.getByText('Test Label')).toBeInTheDocument();
expect(screen.getByText('Test Text')).toBeInTheDocument();
});

it('renders children instead of text if provided', () => {
test('renders children instead of text if provided', () => {
render(
<LabelledText label="Child Label">
<span>Child Content</span>
Expand All @@ -19,12 +19,12 @@ describe('LabelledText', () => {
expect(screen.getByText('Child Label')).toBeInTheDocument();
});

it('renders copy button if copyButton is true', () => {
test('renders copy button if copyButton is true', () => {
render(<LabelledText label="Copy Label" text="Copy Text" copyable />);
expect(screen.getByLabelText('copy')).toBeInTheDocument();
});

it('renders without text', () => {
test('renders without text', () => {
render(<LabelledText label="No Text" />);
expect(screen.getByText('No Text')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { describe, expect, test } from 'vitest';
import Multiselect from './Multiselect';

describe('Multiselect', () => {
it('renders field title and error text', () => {
test('renders field title and error text', () => {
render(<Multiselect elementId="id" title="Title" errorText="Error!" />);
expect(screen.getByText('Title')).toBeInTheDocument();
expect(screen.getByText('Error!')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { describe, expect, test } from 'vitest';
import ReadonlyField from './ReadonlyField';

describe('ReadonlyField', () => {
it('renders the title and value', () => {
test('renders the title and value', () => {
render(<ReadonlyField title="Test Title" value="Test Value" />);
expect(screen.getByDisplayValue('Test Value')).toBeInTheDocument();
expect(screen.getByText('Test Title')).toBeInTheDocument();
});

it('renders with empty value', () => {
test('renders with empty value', () => {
render(<ReadonlyField title="Empty Value" />);
expect(screen.getByDisplayValue('')).toBeInTheDocument();
expect(screen.getByText('Empty Value')).toBeInTheDocument();
Expand Down
6 changes: 3 additions & 3 deletions apps/ai-dial-admin/src/components/Content/Content.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { describe, expect, test } from 'vitest';
import Content from './Content';

describe('Content', () => {
it('renders children', () => {
test('renders children', () => {
render(
<Content isEnableAuth={true} beVersion={'1.0.0'}>
<div>Test Content</div>
Expand All @@ -12,7 +12,7 @@ describe('Content', () => {
expect(screen.getByText('Test Content')).toBeInTheDocument();
});

it('renders with beVersion', () => {
test('renders with beVersion', () => {
render(
<Content isEnableAuth={false} beVersion={'2.3.4'}>
<span>Versioned</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ import { exportFiles } from '@/src/app/[lang]/files/actions';
import { exportPrompts } from '@/src/app/[lang]/prompts/actions';
import { MenuI18nKey } from '@/src/constants/i18n';
import { ApplicationRoute } from '@/src/types/routes';
import { describe, expect, it } from 'vitest';
import { describe, expect, test } from 'vitest';
import { getExportFunction, getJsonFileName, getNotificationType } from '../utils';

describe('getNotificationType', () => {
it('should return MenuI18nKey.Prompts when route is Prompts', () => {
test('should return MenuI18nKey.Prompts when route is Prompts', () => {
const result = getNotificationType(ApplicationRoute.Prompts);
expect(result).toBe(MenuI18nKey.Prompts);
});

it('should return MenuI18nKey.Files when route is Files', () => {
test('should return MenuI18nKey.Files when route is Files', () => {
const result = getNotificationType(ApplicationRoute.Files);
expect(result).toBe(MenuI18nKey.Files);
});

it('should return MenuI18nKey.Applications when route is AssetsApplications', () => {
test('should return MenuI18nKey.Applications when route is AssetsApplications', () => {
const result = getNotificationType(ApplicationRoute.AssetsApplications);
expect(result).toBe(MenuI18nKey.Applications);
});

it('should return MenuI18nKey.Applications when route is AssetsToolsets', () => {
test('should return MenuI18nKey.Applications when route is AssetsToolsets', () => {
const result = getNotificationType(ApplicationRoute.AssetsToolsets);
expect(result).toBe(MenuI18nKey.Toolsets);
});

it('should return an empty string when route is undefined or not matching any of the routes', () => {
test('should return an empty string when route is undefined or not matching any of the routes', () => {
const resultWithUndefinedRoute = getNotificationType();
const resultWithUnknownRoute = getNotificationType('SomeOtherRoute' as ApplicationRoute);

Expand All @@ -36,17 +36,17 @@ describe('getNotificationType', () => {
});

describe('getExportFunction', () => {
it('should return exportPrompts when route is Prompts', () => {
test('should return exportPrompts when route is Prompts', () => {
const result = getExportFunction(ApplicationRoute.Prompts);
expect(result).toBe(exportPrompts);
});

it('should return exportFiles when route is Files', () => {
test('should return exportFiles when route is Files', () => {
const result = getExportFunction(ApplicationRoute.Files);
expect(result).toBe(exportFiles);
});

it('should return null when route is undefined or does not match any known route', () => {
test('should return null when route is undefined or does not match any known route', () => {
const resultWithUndefinedRoute = getExportFunction();
const resultWithUnknownRoute = getExportFunction('SomeOtherRoute' as ApplicationRoute);

Expand All @@ -56,27 +56,27 @@ describe('getExportFunction', () => {
});

describe('getJsonFileName', () => {
it('should return "prompts" when route is Prompts', () => {
test('should return "prompts" when route is Prompts', () => {
const result = getJsonFileName(ApplicationRoute.Prompts);
expect(result).toBe('prompts');
});

it('should return "files" when route is Files', () => {
test('should return "files" when route is Files', () => {
const result = getJsonFileName(ApplicationRoute.Files);
expect(result).toBe('files');
});

it('should return "applications" when route is AssetsApplications', () => {
test('should return "applications" when route is AssetsApplications', () => {
const result = getJsonFileName(ApplicationRoute.AssetsApplications);
expect(result).toBe('applications');
});

it('should return "toolsets" when route is AssetsToolsets', () => {
test('should return "toolsets" when route is AssetsToolsets', () => {
const result = getJsonFileName(ApplicationRoute.AssetsToolsets);
expect(result).toBe('toolsets');
});

it('should return an empty string when route is undefined or does not match any known route', () => {
test('should return an empty string when route is undefined or does not match any known route', () => {
const resultWithUndefinedRoute = getJsonFileName();
const resultWithUnknownRoute = getJsonFileName('SomeOtherRoute' as ApplicationRoute);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import PreviewModal from '../PreviewModal';
import { ExportType } from '@/src/types/export';
import { ButtonsI18nKey, ExportI18nKey } from '@/src/constants/i18n';
import { ExportType } from '@/src/types/export';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import PreviewModal from '../PreviewModal';

const defaultProps = {
exportRequest: { $type: ExportType.Full },
Expand All @@ -16,27 +16,27 @@ vi.mock('@/src/app/[lang]/export-config/actions', () => ({
}));

describe('PreviewModal', () => {
it('renders popup and tabs', async () => {
test('renders popup and tabs', async () => {
render(<PreviewModal {...defaultProps} />);
expect(screen.getByText(ExportI18nKey.FilePreview)).toBeInTheDocument();
await waitFor(() => expect(screen.getByRole('status')).toBeInTheDocument());
});

it('calls onClose when cancel button is clicked', async () => {
test('calls onClose when cancel button is clicked', async () => {
render(<PreviewModal {...defaultProps} />);
const cancelBtn = await screen.getByRole('button', { name: ButtonsI18nKey.Cancel });
fireEvent.click(cancelBtn);
expect(defaultProps.onClose).toHaveBeenCalled();
});

it('calls onPrepare when export button is clicked', async () => {
test('calls onPrepare when export button is clicked', async () => {
render(<PreviewModal {...defaultProps} />);
const exportBtn = await screen.getByRole('button', { name: ButtonsI18nKey.Export });
fireEvent.click(exportBtn);
expect(defaultProps.onPrepare).toHaveBeenCalled();
});

it('toggles secret switch', async () => {
test('toggles secret switch', async () => {
render(<PreviewModal {...defaultProps} />);
const switchLabel = await screen.findByText(ExportI18nKey.IncludeSecrets);
expect(switchLabel).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import ExportConfig from '../ExportConfig';
import { ButtonsI18nKey } from '@/src/constants/i18n';

vi.mock('@/src/app/[lang]/export-config/actions', async (importOriginal) => {
const actual = await importOriginal();
Expand All @@ -13,7 +12,7 @@ vi.mock('@/src/app/[lang]/export-config/actions', async (importOriginal) => {
});

describe('ExportConfig', () => {
it('renders export config title and button', () => {
test('renders export config title and button', () => {
render(<ExportConfig enableExportConfigMap={true} />);
expect(screen.getByText(/ExportConfig/i)).toBeInTheDocument();
expect(screen.getByRole('button')).toBeInTheDocument();
Expand Down
Loading
Loading