Back to Repositories

Testing ChakraWrapper Component Rendering in Apache Airflow

This test suite validates the ChakraWrapper component’s functionality in Apache Airflow’s UI, focusing on proper rendering of child components and empty wrapper states. The tests ensure the wrapper component correctly integrates with Chakra UI and maintains proper component hierarchy.

Test Coverage Overview

The test suite provides comprehensive coverage of the ChakraWrapper component’s core functionality.

  • Tests rendering with child components present
  • Validates empty wrapper rendering
  • Verifies DOM integration and presence

Implementation Analysis

The testing approach utilizes React Testing Library’s render method combined with Vitest for test execution. The implementation follows component testing best practices by checking both populated and empty component states, using modern React testing patterns with TypeScript integration.

  • Leverages React Testing Library’s getByText queries
  • Uses container assertions for empty state validation
  • Implements TypeScript for type-safe testing

Technical Details

  • Testing Framework: Vitest
  • UI Testing Library: @testing-library/react
  • Component Type: TypeScript React Component
  • Test Environment: JSDOM
  • Assertion Style: expect statements with DOM presence checks

Best Practices Demonstrated

The test suite exemplifies several testing best practices in React component testing.

  • Isolation of component rendering tests
  • Clear test case separation and naming
  • Use of describe blocks for logical grouping
  • Minimal test setup and clear assertions
  • Testing both normal and edge cases

apache/airflow

airflow/ui/src/utils/ChakraWrapper.test.tsx

            
/*!
 * 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 { render } from "@testing-library/react";
import { describe, it, expect } from "vitest";

import { ChakraWrapper } from "src/utils/ChakraWrapper.tsx";

describe("ChakraWrapper", () => {
  it("renders children correctly", () => {
    const { getByText } = render(
      <ChakraWrapper>
        <div>Test Child</div>
      </ChakraWrapper>,
    );

    expect(getByText("Test Child")).toBeInTheDocument();
  });

  it("renders without children", () => {
    const { container } = render(<ChakraWrapper />);

    expect(container).toBeInTheDocument();
  });
});