Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tests/ui/FloatingActionButtonTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {NavigationContainer} from '@react-navigation/native';
import {cleanup, fireEvent, render, screen} from '@testing-library/react-native';
import React from 'react';
import FloatingActionButton from '@components/FloatingActionButton';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import colors from '@styles/theme/colors';
import CONST from '@src/CONST';

Expand All @@ -20,7 +21,8 @@ jest.mock('@components/ProductTrainingContext', () => ({
}));

// useResponsiveLayout determines LHB visibility. Mock a wide layout to keep behaviour deterministic.
jest.mock('@hooks/useResponsiveLayout', () => (): {shouldUseNarrowLayout: boolean} => ({shouldUseNarrowLayout: false}));
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());
const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction<typeof useResponsiveLayout>;

// Mock useIsHomeRouteActive to avoid navigation state issues
jest.mock('@navigation/helpers/useIsHomeRouteActive', () => (): boolean => false);
Expand Down Expand Up @@ -51,6 +53,10 @@ describe('FloatingActionButton hover', () => {
jest.clearAllMocks();
});

beforeAll(() => {
mockedUseResponsiveLayout.mockReturnValue({...CONST.NAVIGATION_TESTS.DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, shouldUseNarrowLayout: false});
});

it('changes background color on hover', () => {
renderFAB();
const fab = screen.getByTestId('floating-action-button');
Expand All @@ -69,4 +75,23 @@ describe('FloatingActionButton hover', () => {
fireEvent(fab, 'hoverOut');
expect(animatedContainer).not.toHaveStyle({backgroundColor: colors.productDark500});
});

it('should render animated button if LHB is visible', () => {
renderFAB();

// Get the animated container by testID
const animatedContainer = screen.getByTestId('fab-animated-container');

expect(animatedContainer).toBeVisible();
});

it('should render regular button if LHB is not visible', () => {
mockedUseResponsiveLayout.mockReturnValue({...CONST.NAVIGATION_TESTS.DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, shouldUseNarrowLayout: true});
renderFAB();

// Get the container by testID
const container = screen.getByTestId('fab-container');

expect(container).toBeVisible();
});
});
47 changes: 47 additions & 0 deletions tests/ui/FloatingReceiptButtonTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {NavigationContainer} from '@react-navigation/native';
import {cleanup, fireEvent, render, screen} from '@testing-library/react-native';
import React from 'react';
import FloatingReceiptButton from '@components/FloatingReceiptButton';
import colors from '@styles/theme/colors';
import CONST from '@src/CONST';

describe('FloatingReceiptButton hover', () => {
const onPress = jest.fn();

const renderFAB = () =>
render(
<NavigationContainer>
<FloatingReceiptButton
onPress={onPress}
accessibilityLabel="fab"
role={CONST.ROLE.BUTTON}
/>
</NavigationContainer>,
);

afterEach(() => {
cleanup();
jest.clearAllMocks();
});

it('changes background color on hover', () => {
renderFAB();

// Get the receipt button by testID
const frb = screen.getByTestId('floating-receipt-button');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an empty line after renderFAB()


// Get the container by testID
const container = screen.getByTestId('floating-receipt-button-container');

// Before hover, should not have greenHover background
expect(container).not.toHaveStyle({backgroundColor: colors.greenHover});

// Test hover in
fireEvent(frb, 'hoverIn');
expect(container).toHaveStyle({backgroundColor: colors.greenHover});

// Test hover out
fireEvent(frb, 'hoverOut');
expect(container).not.toHaveStyle({backgroundColor: colors.greenHover});
});
});
Loading