diff --git a/client/src/ConfigurationTask/ConfigurationTask.test.js b/client/src/ConfigurationTask/ConfigurationTask.test.js new file mode 100644 index 0000000..e2db671 --- /dev/null +++ b/client/src/ConfigurationTask/ConfigurationTask.test.js @@ -0,0 +1,90 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import ConfigurationTask from './index'; +import '@testing-library/jest-dom'; + + +// Mock the useTranslation hook with actual translations +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: key => ({ + "setup.tabs.taskinfo.task_info": "Task Information", + "setup.tabs.taskinfo.task_choice": "Choice of Task", + "setup.tabs.taskinfo.task_choice_classification": "Image Classification", + "setup.tabs.taskinfo.task_choice_segmentation": "Image Segmentation", + }[key]), + }), +})); + + jest.mock('material-survey/components/Survey', () => ({ + // Mock implementation for Survey + __esModule: true, + default: jest.fn(({ form, onQuestionChange }) => ( +
+ {form.questions.map((q) => ( +
+ {q.title} + {q.type === 'text' && } + {q.type === 'radiogroup' && ( +
+ {q.choices.map((choice) => ( + + ))} +
+ )} +
+ ))} + +
+ )), + })); + + describe('ConfigurationTask', () => { + test('renders form with questions and calls onChange on answer change', () => { + const mockConfig = {}; + const mockOnChange = jest.fn(); + + const mockForm = { + questions: [ + { name: 'taskDescription', title: 'Task Description', type: 'text' }, + { + name: 'taskChoice', + title: 'Task Choice', + type: 'radiogroup', + choices: [ + { value: 'image_classification', text: 'Image Classification' }, + { value: 'image_segmentation', text: 'Image Segmentation' }, + ], + }, + ], + }; + + render(); + + // Assert question titles are rendered + expect(screen.getByText('Task Information')).toBeInTheDocument(); + expect(screen.getByText('Choice of Task')).toBeInTheDocument(); + + // Assert radio buttons are rendered + const imageClassificationRadio = screen.getByTestId(`radio-taskChoice-image_classification`); + const imageSegmentationRadio = screen.getByTestId(`radio-taskChoice-image_segmentation`); + expect(imageClassificationRadio).toBeInTheDocument(); + expect(imageSegmentationRadio).toBeInTheDocument(); + + // Simulate changing radio button and verify onChange is called + fireEvent.click(imageSegmentationRadio, { target: { value: 'image_segmentation' } }); + expect(imageSegmentationRadio).toHaveAttribute('value', 'image_segmentation'); + + // Simulate completing the form + fireEvent.click(screen.getByTestId('complete-button')); + // Add assertions to verify completion behavior based on YourComponent logic + }); + }); \ No newline at end of file diff --git a/client/src/ConfigureImageClassification/ConfigureImageClassification.test.js b/client/src/ConfigureImageClassification/ConfigureImageClassification.test.js new file mode 100644 index 0000000..7fb469c --- /dev/null +++ b/client/src/ConfigureImageClassification/ConfigureImageClassification.test.js @@ -0,0 +1,102 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import ConfigureImageClassification from './index'; +import '@testing-library/jest-dom'; + +// Mock the useTranslation hook with actual translations +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: key => ({ + "configuration.multiple_regions": "Multiple Regions", + "configuration.multiple_region_labels": "Multiple Region Labels", + "configuration.region_types_allowed": "Region Types Allowed", + "configuration.region_types_allowed.description": "Select the types of regions allowed", + "configuration.labels": "Labels", + "configuration.labels.description": "Provide labels for the regions", + "configuration.labels.option.id": "ID", + "configuration.labels.option.description": "Description", + "configuration.regions": "Regions", + "configuration.regions.description": "Select a region type", + }[key]), + }), +})); + +// Mock the Survey component from material-survey +jest.mock('material-survey/components/Survey', () => ({ + __esModule: true, + default: jest.fn(({ form, onQuestionChange }) => ( +
+ {form.questions.map((q) => ( +
+ {q.title} + {q.type === 'boolean' && } + {q.type === 'checkbox' && ( +
+ {q.choices.map((choice) => ( + + ))} +
+ )} + {q.type === 'matrixdynamic' && ( +
+ {q.columns.map((col) => ( +
{col.title}
+ ))} + +
+ )} + {q.type === 'dropdown' && ( + + )} +
+ ))} + +
+ )), +})); + +describe('ConfigureImageClassification', () => { + test('renders form with questions and calls onChange on answer change', () => { + const mockConfig = {}; + const mockOnChange = jest.fn(); + + render(); + + // Assert question titles are rendered + expect(screen.getByText('Multiple Regions')).toBeInTheDocument(); + expect(screen.getByText('Multiple Region Labels')).toBeInTheDocument(); + expect(screen.getByText('Region Types Allowed')).toBeInTheDocument(); + expect(screen.getByText('Labels')).toBeInTheDocument(); + expect(screen.getByText('Regions')).toBeInTheDocument(); + + // Assert checkboxes are rendered + const multipleRegionsCheckbox = screen.getByTestId('checkbox-multipleRegions'); + const multipleRegionLabelsCheckbox = screen.getByTestId('checkbox-multipleRegionLabels'); + expect(multipleRegionsCheckbox).toBeInTheDocument(); + expect(multipleRegionLabelsCheckbox).toBeInTheDocument(); + + // Simulate changing checkbox and verify onChange is called + fireEvent.change(multipleRegionsCheckbox, { target: { checked: true } }); + expect(multipleRegionsCheckbox).toBeChecked(); + fireEvent.change(multipleRegionLabelsCheckbox, { target: { checked: true } }); + expect(multipleRegionLabelsCheckbox).toBeChecked(); + + // Simulate completing the form + fireEvent.click(screen.getByTestId('complete-button')); + // Add assertions to verify completion behavior based on YourComponent logic + }); +}); diff --git a/client/src/ConfigureImageSegmentation/ConfigureImageSegmentation.test.js b/client/src/ConfigureImageSegmentation/ConfigureImageSegmentation.test.js new file mode 100644 index 0000000..4b4d0c4 --- /dev/null +++ b/client/src/ConfigureImageSegmentation/ConfigureImageSegmentation.test.js @@ -0,0 +1,92 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import ConfigureImageSegmentation from './index'; +import '@testing-library/jest-dom'; + +// Mock the useTranslation hook with actual translations +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: key => ({ + "configuration.region_types_allowed": "Region Types Allowed", + "configuration.region_types_allowed.description": "Select the types of regions allowed", + "configuration.multiple_regions": "Multiple Regions", + "configuration.multiple_region_labels": "Multiple Region Labels", + "configuration.labels": "Labels", + "configuration.labels.description": "Provide labels for the regions", + "configuration.labels.option.id": "ID", + "configuration.labels.option.description": "Description", + }[key]), + }), +})); + +// Mock the Survey component from material-survey +jest.mock('material-survey/components/Survey', () => ({ + __esModule: true, + default: jest.fn(({ form, onQuestionChange }) => ( +
+ {form.questions.map((q) => ( +
+ {q.title} + {q.type === 'boolean' && } + {q.type === 'multiple-dropdown' && ( + + )} + {q.type === 'matrixdynamic' && ( +
+ {q.columns.map((col) => ( +
{col.title}
+ ))} + +
+ )} +
+ ))} + +
+ )), +})); + +describe('ConfigureImageSegmentation', () => { + test('renders form with questions and calls onChange on answer change', () => { + const mockConfig = {}; + const mockOnChange = jest.fn(); + + render(); + + // Assert question titles are rendered + expect(screen.getByText('Region Types Allowed')).toBeInTheDocument(); + expect(screen.getByText('Multiple Regions')).toBeInTheDocument(); + expect(screen.getByText('Multiple Region Labels')).toBeInTheDocument(); + expect(screen.getByText('Labels')).toBeInTheDocument(); + + // Assert checkboxes are rendered + const multipleRegionsCheckbox = screen.getByTestId('checkbox-multipleRegions'); + const multipleRegionLabelsCheckbox = screen.getByTestId('checkbox-multipleRegionLabels'); + expect(multipleRegionsCheckbox).toBeInTheDocument(); + expect(multipleRegionLabelsCheckbox).toBeInTheDocument(); + + // Simulate changing checkbox and verify onChange is called + fireEvent.change(multipleRegionsCheckbox, { target: { checked: true } }); + expect(multipleRegionsCheckbox).toBeChecked(); + fireEvent.change(multipleRegionLabelsCheckbox, { target: { checked: true } }); + expect(multipleRegionLabelsCheckbox).toBeChecked(); + + // Simulate changing multiple-dropdown and verify onChange is called + const regionTypesAllowedDropdown = screen.getByTestId('multiple-dropdown-regionTypesAllowed'); + fireEvent.mouseDown(regionTypesAllowedDropdown); + const boundingBoxOption = screen.getByText('bounding-box'); + const polygonOption = screen.getByText('polygon'); + fireEvent.click(boundingBoxOption); + fireEvent.click(polygonOption); + + // Simulate completing the form + fireEvent.click(screen.getByTestId('complete-button')); + // Add assertions to verify completion behavior based on YourComponent logic + }); +}); diff --git a/client/src/SetupPage/SetupPage.test.js b/client/src/SetupPage/SetupPage.test.js new file mode 100644 index 0000000..aaa1382 --- /dev/null +++ b/client/src/SetupPage/SetupPage.test.js @@ -0,0 +1,63 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { SetupPage } from './index'; +import { useSettings } from '../SettingsProvider'; + +// Mock useTranslation hook +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (key) => key, + }), +})); + +// Mock useSettings hook +jest.mock('../SettingsProvider', () => ({ + useSettings: jest.fn(), +})); + +// Mock dependent components +jest.mock('../ConfigureImageClassification', () => jest.fn(() =>
)); +jest.mock('../ConfigureImageSegmentation', () => jest.fn(() =>
)); +jest.mock('../ConfigurationTask', () => jest.fn(({ onChange }) => ( + onChange({ target: { value: e.target.value } })} + /> +))); +jest.mock('../ImageUpload', () => jest.fn(() =>
)); + +describe('SetupPage', () => { + const mockSettings = { + taskDescription: '', + configuration: { labels: [] }, + images: [], + taskChoice: 'image_classification', + }; + const mockSetConfiguration = jest.fn(); + const mockSetShowLabel = jest.fn(); + + beforeEach(() => { + useSettings.mockReturnValue({ + changeSetting: jest.fn(), + }); + + render( + + ); + }); + + test('renders tabs and default content', () => { + // Check tabs + expect(screen.getByText('setup.tabs.taskinfo')).toBeInTheDocument(); + expect(screen.getByText('setup.tabs.configure')).toBeInTheDocument(); + expect(screen.getByText('setup.tabs.image')).toBeInTheDocument(); + + // Check default content (datatype tab) + expect(screen.getByTestId('ConfigurationTask')).toBeInTheDocument(); + }); +});