Improve component branch coverage from 66.66% to 77.77%

- Enhanced ContainerCard tests
  - Added test for unknown container status fallback
  - Branch coverage: 50% → 100%

- Enhanced LoginForm tests
  - Added failed login submission test (triggers shake animation)
  - Branch coverage: 80% → 100%

Side effects:
- ContainerHeader: 75% → 100% branch coverage
- ContainerCard sub-components: 88.23% → 94.11% overall

Total: 238 passing tests (up from 235)
Overall branch coverage: 72.33% → 73.51%

https://claude.ai/code/session_mmQs0
This commit is contained in:
Claude
2026-02-01 15:54:02 +00:00
parent ea6b4fb30c
commit 239bc08a67
2 changed files with 55 additions and 1 deletions

View File

@@ -83,6 +83,22 @@ describe('ContainerCard', () => {
expect(card).toHaveStyle({ borderColor: '#718096' });
});
it('should use default border color for unknown status', () => {
const unknownContainer = { ...mockContainer, status: 'unknown' };
const { container } = render(
<ContainerCard
container={unknownContainer}
onOpenShell={mockOnOpenShell}
onContainerUpdate={mockOnContainerUpdate}
/>
);
const card = container.querySelector('.MuiCard-root');
// Should fallback to 'stopped' color (#718096)
expect(card).toHaveStyle({ borderColor: '#718096' });
});
it('should call useContainerActions with correct parameters', () => {
render(
<ContainerCard

View File

@@ -1,9 +1,10 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';
import authReducer from '@/lib/store/authSlice';
import LoginForm from '../LoginForm';
import { apiClient } from '@/lib/api';
jest.mock('next/navigation', () => ({
useRouter: jest.fn(() => ({
@@ -112,4 +113,41 @@ describe('LoginForm', () => {
const submitButton = screen.getByRole('button', { name: /logging in/i });
expect(submitButton).toBeDisabled();
});
it('renders without shake animation by default', () => {
renderWithProvider(<LoginForm />);
// The component should render successfully
expect(screen.getByRole('button', { name: /access dashboard/i })).toBeInTheDocument();
});
it('handles form submission with failed login', async () => {
jest.useFakeTimers();
(apiClient.login as jest.Mock).mockResolvedValue({
success: false,
message: 'Invalid credentials',
});
renderWithProvider(<LoginForm />);
const usernameInput = screen.getByLabelText(/username/i);
const passwordInput = screen.getByLabelText(/password/i);
const submitButton = screen.getByRole('button', { name: /access dashboard/i });
fireEvent.change(usernameInput, { target: { value: 'wronguser' } });
fireEvent.change(passwordInput, { target: { value: 'wrongpass' } });
fireEvent.click(submitButton);
// Wait for error to appear
await waitFor(() => {
expect(screen.getByText('Invalid credentials')).toBeInTheDocument();
});
// The shake animation should be triggered (isShaking: true)
// We can't directly test CSS animations, but we verify the component still renders
expect(screen.getByRole('button', { name: /access dashboard/i })).toBeInTheDocument();
jest.useRealTimers();
});
});