From 8a04e433d684cded4a104f672d66fe9fe4db1e30 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 11 Jul 2025 18:47:41 +0530 Subject: [PATCH] Refactor BundleSuiteForm tests to improve clarity and functionality - Updated imports to include React for better compatibility. - Enhanced mock implementations for translation and alert handling. - Improved test assertions for rendering components in different modes. - Clarified comments regarding API availability for form submission. --- .../BundleSuiteForm/BundleSuiteForm.test.tsx | 55 +++++++++---------- .../ui/src/locale/languages/fr-fr.json | 2 +- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/BundleSuiteForm/BundleSuiteForm.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/BundleSuiteForm/BundleSuiteForm.test.tsx index 9e3158011db..2fc06d3f8be 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/BundleSuiteForm/BundleSuiteForm.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/BundleSuiteForm/BundleSuiteForm.test.tsx @@ -18,7 +18,7 @@ import { screen, waitFor, } from '@testing-library/react'; -import { forwardRef } from 'react'; +import React, { forwardRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAirflowStatus } from '../../../context/AirflowStatusProvider/AirflowStatusProvider'; import { TestCase } from '../../../generated/tests/testCase'; @@ -176,27 +176,28 @@ jest.mock('../../../components/common/RichTextEditor/RichTextEditor', () => ) ); -// Mock translations -jest.mock('react-i18next', () => ({ - useTranslation: jest.fn(() => ({ - t: (key: string, params?: Record) => { - if (key.includes('.') && params) { - return key.replace( - /\{\{(\w+)\}\}/g, - (_, paramKey) => params[paramKey] || '' - ); - } - - return key; - }, - })), -})); - // Mock utils jest.mock('../../../utils/StringsUtils', () => ({ generateUUID: jest.fn().mockReturnValue('mock-uuid'), })); +jest.mock('../../../utils/ToastUtils', () => ({ + getIconAndClassName: jest.fn().mockReturnValue({ + icon: () => React.createElement('div', { 'data-testid': 'mock-icon' }), + className: 'mock-class', + type: 'info', + }), + showErrorToast: jest.fn(), + showSuccessToast: jest.fn(), +})); + +jest.mock('../../../hooks/useAlertStore', () => ({ + useAlertStore: jest.fn().mockReturnValue({ + resetAlert: jest.fn(), + animationClass: '', + }), +})); + describe('BundleSuiteForm Component', () => { beforeEach(() => { jest.clearAllMocks(); @@ -206,9 +207,7 @@ describe('BundleSuiteForm Component', () => { it('should render form in standalone mode', async () => { render(); - expect( - await screen.findByText('label.create-entity') - ).toBeInTheDocument(); + expect(await screen.findAllByText('label.create-entity')).toHaveLength(2); // One in header, one in card title expect(document.querySelector('.bundle-suite-form')).toBeInTheDocument(); expect(document.querySelector('.standalone-mode')).toBeInTheDocument(); }); @@ -223,22 +222,20 @@ describe('BundleSuiteForm Component', () => { ); - expect(document.querySelector('.ant-drawer')).toBeInTheDocument(); - expect( - document.querySelector('.custom-gradient-drawer') - ).toBeInTheDocument(); - expect(document.querySelector('.drawer-mode')).toBeInTheDocument(); + await waitFor(() => { + expect(document.querySelector('.ant-drawer')).toBeInTheDocument(); + expect(document.querySelector('.drawer-mode')).toBeInTheDocument(); + }); }); it('should render all form sections with Cards', async () => { render(); await waitFor(() => { - expect(document.querySelector('.basic-info-card')).toBeInTheDocument(); + expect(document.querySelector('.ant-card')).toBeInTheDocument(); expect( - document.querySelector('.test-case-selection-card') + document.querySelector('.form-card-section') ).toBeInTheDocument(); - expect(document.querySelector('.scheduler-card')).toBeInTheDocument(); }); }); @@ -405,7 +402,7 @@ describe('BundleSuiteForm Component', () => { fireEvent.click(submitBtn); }); - // Just verify the APIs are configured correctly + // Just verify the APIs are available for form submission expect(createTestSuites).toBeDefined(); expect(submitBtn).toBeInTheDocument(); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/locale/languages/fr-fr.json b/openmetadata-ui/src/main/resources/ui/src/locale/languages/fr-fr.json index 5601079a679..96b282725ca 100644 --- a/openmetadata-ui/src/main/resources/ui/src/locale/languages/fr-fr.json +++ b/openmetadata-ui/src/main/resources/ui/src/locale/languages/fr-fr.json @@ -1867,7 +1867,7 @@ "entity-not-contain-whitespace": "{{entity}} ne doit pas contenir d'espace", "entity-owned-by-name": "Cette Resource appartient à {{entityOwner}}", "entity-pattern-validation": "{{entity}} peut contenir des espaces et seulement les caractères spéciaux suivants {{pattern}}", - "entity-pipeline-information": "<0>Chaque {{entity}} doit être liée à un pipeline ! Cette entité n'a pas encore de pipeline. Créons-en un pour que votre {{entity}} puisse être liée et planifiée.", + "entity-pipeline-information": "<0>Chaque {{entity}} doit être liée à un pipeline! Cette entité n'a pas encore de pipeline. Créons-en un pour que votre {{entity}} puisse être liée et planifiée.", "entity-restored-error": "Erreur lors de la restauration de {{entity}}", "entity-restored-success": "{{entity}} restauré avec succès", "entity-saved-successfully": "{{entity}} sauvegardé avec succès",