Skip to content
Open
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
7 changes: 3 additions & 4 deletions src/components/Appbar/AppbarBackIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Image, Platform, StyleSheet, View } from 'react-native';
import type { ColorValue } from 'react-native';

import { useLocale } from '../../core/locale';
import MaterialCommunityIcon from '../MaterialCommunityIcon';
import Icon from '../Icon';

const AppbarBackIcon = ({
size,
Expand Down Expand Up @@ -34,11 +34,10 @@ const AppbarBackIcon = ({
/>
</View>
) : (
<MaterialCommunityIcon
name="arrow-left"
<Icon
source={{ source: 'arrow-left', direction }}
color={color}
size={size}
direction={direction}
/>
);
};
Expand Down
65 changes: 62 additions & 3 deletions src/components/__tests__/Appbar/Appbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Animated } from 'react-native';
import { Animated, Platform, Text as RNText } from 'react-native';

import { describe, expect, it, jest } from '@jest/globals';
import { act } from '@testing-library/react-native';
import { afterEach, describe, expect, it, jest } from '@jest/globals';
import { act, render as rtlRender } from '@testing-library/react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import PaperProvider from '../../../core/PaperProvider';
import { getTheme } from '../../../core/theming';
import { render, screen } from '../../../test-utils';
import { tokens } from '../../../theme/tokens';
Expand All @@ -14,6 +15,7 @@ import {
modeTextVariant,
renderAppbarContent as utilRenderAppbarContent,
} from '../../Appbar/utils';
import type { IconProps } from '../../MaterialCommunityIcon';
import Menu from '../../Menu/Menu';
import Searchbar from '../../Searchbar';
import Text from '../../Typography/Text';
Expand Down Expand Up @@ -453,3 +455,60 @@ describe('animated value changes correctly', () => {
});
});
});

describe('Appbar.BackAction icon', () => {
const originalPlatform = Platform.OS;

afterEach(() => {
Platform.OS = originalPlatform;
});

const CustomIcon = ({ name, size, direction, testID }: IconProps) => (
<RNText
testID={testID}
style={{
fontSize: size,
transform: [{ scaleX: direction === 'rtl' ? -1 : 1 }],
}}
>
{`custom-${name}`}
</RNText>
);

const renderBackAction = (direction?: 'ltr' | 'rtl') =>
rtlRender(
<PaperProvider settings={{ icon: CustomIcon }} direction={direction}>
<Appbar.BackAction onPress={() => {}} testID="back-action" />
</PaperProvider>
);

it('renders the icon provided through PaperProvider settings', async () => {
Platform.OS = 'android';

await renderBackAction();

expect(
screen.getByText('custom-arrow-left', { includeHiddenElements: true })
).toBeOnTheScreen();
});

it('keeps the icon mirrored in RTL', async () => {
Platform.OS = 'android';

await renderBackAction('rtl');

expect(
screen.getByText('custom-arrow-left', { includeHiddenElements: true })
).toHaveStyle({ transform: [{ scaleX: -1 }] });
});

it('keeps the icon unmirrored in LTR', async () => {
Platform.OS = 'android';

await renderBackAction('ltr');

expect(
screen.getByText('custom-arrow-left', { includeHiddenElements: true })
).toHaveStyle({ transform: [{ scaleX: 1 }] });
});
});