Skip to content

Refactor HintDriver to allow optional style flattening in tests #3502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
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
4 changes: 2 additions & 2 deletions src/components/hint/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ describe('Hint Screen component test', () => {
const renderTree = render(<TestCase visible/>);
const driver = HintDriver({renderTree, testID: HINT_TEST_ID});
const hintBubble = await driver.getHintBubble();
expect(hintBubble.getStyle().backgroundColor).toBe(expectedColor);
expect(hintBubble.getStyle(true).backgroundColor).toBe(expectedColor);
});

it('Should color hint bubble with provided color prop', async () => {
const renderTree = render(<TestCase visible color={Colors.white}/>);
const driver = HintDriver({renderTree, testID: HINT_TEST_ID});
const hintBubble = await driver.getHintBubble();
expect(hintBubble.getStyle().backgroundColor).toBe(Colors.white);
expect(hintBubble.getStyle(true).backgroundColor).toBe(Colors.white);
});

it('Should modal be not visible when hint is not visible', async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/view/View.driver.new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.dr
export const ViewDriver = (props: ComponentProps) => {
const driver = useComponentDriver(props);

const getStyle = () => {
return StyleSheet.flatten(driver.getElement().props.style);
const getStyle = (flatten = false) => {
const style = driver.getElement().props.style;
return flatten ? StyleSheet.flatten(style) : style;
};
return {...driver, getStyle};
};