devabhishekpal commented on code in PR #7626: URL: https://github.com/apache/ozone/pull/7626#discussion_r1900611976
########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/datanodes/Datanodes.test.tsx: ########## @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { + render, + screen, + waitFor +} from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { rest } from "msw"; +import { vi } from 'vitest'; + +import Datanodes from '@/v2/pages/datanodes/datanodes'; +import * as commonUtils from '@/utils/common'; +import { datanodeServer } from '@/__tests__/mocks/datanodeMocks/datanodeServer'; +import { datanodeLocators } from '@/__tests__/locators/locators'; + +// Mock utility functions +vi.spyOn(commonUtils, 'showDataFetchError'); + +vi.mock('@/components/autoReloadPanel/autoReloadPanel', () => ({ + default: () => <div data-testid="auto-reload-panel" />, +})); +vi.mock('@/v2/components/select/multiSelect.tsx', () => ({ + default: ({ onChange }: { onChange: Function }) => ( + <select data-testid="multi-select" onChange={(e) => onChange(e.target.value)}> + <option value="hostname">Hostname</option> + <option value="uuid">UUID</option> + </select> + ), +})); + +describe('Datanodes Component', () => { + // Start and stop MSW server before and after all tests + beforeAll(() => datanodeServer.listen()); + afterEach(() => datanodeServer.resetHandlers()); + afterAll(() => datanodeServer.close()); + + test('renders component correctly', () => { + render(<Datanodes />); + + expect(screen.getByText(/Datanodes/)).toBeInTheDocument(); + expect(screen.getByTestId('auto-reload-panel')).toBeInTheDocument(); + expect(screen.getByTestId('multi-select')).toBeInTheDocument(); + expect(screen.getByTestId('search-input')).toBeInTheDocument(); + }); + + test('renders table with correct number of rows', async () => { + render(<Datanodes />); + + // Wait for the data to load + const rows = await waitFor(() => screen.getAllByTestId(/dntable-/)); Review Comment: Refactored these into `datanodes.utils.tsx` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
