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
16 changes: 4 additions & 12 deletions packages/components/src/ScreenWrapper/ScreenWrapperSection.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';

import { MD3LightTheme } from '@jmstechnologiesinc/react-native-paper';
import { List, Text } from '@jmstechnologiesinc/react-native-paper';
import { List } from '@jmstechnologiesinc/react-native-paper';

import MutedText from '../MutedText/MutedText';
import ScreenWrapperContainer, { containerPaddings } from './ScreenWrapperContainer';
import { moderateScale } from '@jmstechnologiesinc/react-native-size-matters';

const sectionPaddings = {
...containerPaddings,
Expand Down Expand Up @@ -33,16 +33,8 @@ export const ScreenWrapperSection = ({
{title}
</List.Subheader>
) : null}
<Text
selectable={false}
style={{
fontSize: moderateScale(14),
color: MD3LightTheme.colors.onSurfaceVariant,
paddingBottom: moderateScale(13),
}}
>
{description}
</Text>
{/* MD3 supporting text, on the 4 dp spacing grid. */}
<MutedText style={{ paddingBottom: MD3LightTheme.spacing.x3 }}>{description}</MutedText>
</>
) : title ? (
<List.Subheader style={[{ paddingHorizontal: 0 }, titleStyle]}>{title}</List.Subheader>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
jest.mock('react-native-localize', () => ({
findBestLanguageTag: jest.fn(() => ({ languageTag: 'en', isRTL: false })),
}));

import React from 'react';
import renderer, { act } from 'react-test-renderer';

import { List, MD3LightTheme, Provider } from '@jmstechnologiesinc/react-native-paper';

import { setI18nConfig } from '../../Localization/Localization';
import MutedText from '../../MutedText/MutedText';
import ScreenWrapperSection from '../ScreenWrapperSection';

// A section's description is MD3's supporting text under its subheader: the theme's muted body text, on the spacing
// grid, so it follows the theme instead of a hand-picked size and colour.

jest.useFakeTimers();

const mounted = [];

const render = (element) => {
let tree;
act(() => {
tree = renderer.create(<Provider theme={MD3LightTheme}>{element}</Provider>);
});
mounted.push(tree);
return tree;
};

afterEach(() => {
act(() => {
mounted.splice(0).forEach((tree) => tree.unmount());
jest.runOnlyPendingTimers();
});
});

beforeAll(() => setI18nConfig());

describe('ScreenWrapperSection', () => {
it('writes its description as muted supporting text under its title', () => {
const tree = render(<ScreenWrapperSection title="Payouts" description="Where your earnings go" />);
expect(tree.root.findByType(List.Subheader).props.children).toBe('Payouts');
const description = tree.root.findByType(MutedText);
expect(description.props.children).toBe('Where your earnings go');
expect(description.props.style).toEqual({ paddingBottom: MD3LightTheme.spacing.x3 });
});

it('has no supporting text without a description', () => {
const tree = render(<ScreenWrapperSection title="Payouts" />);
expect(tree.root.findAllByType(MutedText)).toHaveLength(0);
});
});
Loading