/**
* Tests for ConnectionStatusIndicator component
*/
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { ConnectionStatusIndicator } from '../ConnectionStatusIndicator';
// Import just the types, not the full module to avoid native dependencies
import { BLEConnectionState } from '@/services/ble/types';
describe('ConnectionStatusIndicator', () => {
describe('Connection States', () => {
it('renders disconnected state correctly', () => {
const { getByText } = render(
);
expect(getByText('Not Connected')).toBeTruthy();
});
it('renders connecting state correctly', () => {
const { getByText } = render(
);
expect(getByText('Connecting...')).toBeTruthy();
});
it('renders connected/ready state correctly', () => {
const { getByText } = render(
);
expect(getByText('Connected')).toBeTruthy();
});
it('renders error state correctly', () => {
const { getByText } = render(
);
expect(getByText('Connection Error')).toBeTruthy();
});
it('renders disconnecting state correctly', () => {
const { getByText } = render(
);
expect(getByText('Disconnecting...')).toBeTruthy();
});
});
describe('Reconnecting State', () => {
it('shows reconnecting message when isReconnecting is true', () => {
const { getByText } = render(
);
expect(getByText('Reconnecting... (1/3)')).toBeTruthy();
expect(getByText('Attempting to restore connection...')).toBeTruthy();
});
it('shows cancel button when reconnecting', () => {
const onCancel = jest.fn();
const { getByText } = render(
);
const cancelButton = getByText('Cancel');
expect(cancelButton).toBeTruthy();
fireEvent.press(cancelButton);
expect(onCancel).toHaveBeenCalledTimes(1);
});
});
describe('Reconnect Action', () => {
it('shows reconnect button when disconnected or errored', () => {
const onReconnect = jest.fn();
const { getByText } = render(
);
const reconnectButton = getByText('Reconnect');
expect(reconnectButton).toBeTruthy();
fireEvent.press(reconnectButton);
expect(onReconnect).toHaveBeenCalledTimes(1);
});
it('shows reconnect button on error state', () => {
const onReconnect = jest.fn();
const { getByText } = render(
);
const reconnectButton = getByText('Reconnect');
expect(reconnectButton).toBeTruthy();
});
it('does not show reconnect button when connected', () => {
const onReconnect = jest.fn();
const { queryByText } = render(
);
expect(queryByText('Reconnect')).toBeNull();
});
it('does not show reconnect button when reconnecting', () => {
const onReconnect = jest.fn();
const { queryByText } = render(
);
expect(queryByText('Reconnect')).toBeNull();
});
});
describe('Compact Mode', () => {
it('renders in compact mode', () => {
const { getByText } = render(
);
expect(getByText('Connected')).toBeTruthy();
});
it('does not show action buttons in compact mode', () => {
const onReconnect = jest.fn();
const { queryByText } = render(
);
// Compact mode should not show action buttons
expect(queryByText('Reconnect')).toBeNull();
});
});
});