import React from "react";
import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
import { fireEvent } from "@testing-library/react-native";
const mockUseIsRTL = jest.fn(() => true);
jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
useIsRTL: mockUseIsRTL,
}));
const BarView = require("../BarView").default;
describe("BarView", () => {
const screenStyles = {
title_font_color: "#000",
title_font_android: "Roboto",
title_font_ios: "San Francisco",
title_font_size: "16",
background_color: "#fff",
};
const barState = {
backHandler: jest.fn(),
closeHandler: jest.fn(),
title: "Test Title",
};
beforeEach(() => {
jest.clearAllMocks();
});
it("renders without crashing", () => {
mockUseIsRTL.mockReturnValue(false);
const { getByText } = renderWithProviders(
);
expect(getByText("Test Title")).toBeTruthy();
});
it("applies RTL styles when isRTL is true", () => {
mockUseIsRTL.mockReturnValue(true);
const { getByTestId } = renderWithProviders(
);
expect(getByTestId("BarView-safeAreaView").props.style).toContainEqual({
transform: [{ scaleX: -1 }],
});
});
it("does not apply RTL styles when isRTL is false", () => {
mockUseIsRTL.mockReturnValue(false);
const { getByTestId } = renderWithProviders(
);
expect(getByTestId("BarView-safeAreaView").props.style).not.toContainEqual({
transform: [{ scaleX: -1 }],
});
});
it("calls closeHandler when CloseButton is pressed", () => {
mockUseIsRTL.mockReturnValue(false);
const { getByTestId } = renderWithProviders(
);
fireEvent.press(getByTestId("closeButton-actionButton-touchable"));
expect(barState.closeHandler).toHaveBeenCalled();
});
it("calls backHandler when BackButton is pressed", () => {
mockUseIsRTL.mockReturnValue(false);
const { getByTestId } = renderWithProviders(
);
fireEvent.press(getByTestId("backButton-actionButton-touchable"));
expect(barState.backHandler).toHaveBeenCalled();
});
});