Skip to content

Commit

Permalink
More test cases - custom layout transitions (#6458)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
  • Loading branch information
Latropos committed Sep 18, 2024
1 parent 4004a67 commit e550ae7
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ export default function RuntimeTestsExample() {
describe('Compare layout transitions with **constant view size** with snapshots', () => {
require('./tests/layoutAnimations/layout/predefinedLayoutPosition.test');
});
describe('Compare Test layout transitions including view **size changes** with snapshots', () => {
describe('Compare predefined layout transitions including view **size changes** with snapshots', () => {
require('./tests/layoutAnimations/layout/positionAndSize.test');
});
require('./tests/layoutAnimations/layout/custom.test');
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import React, { useState, useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import Animated from 'react-native-reanimated';
import { useTestRef } from '../../../ReJest/RuntimeTestsApi';
import {
clearRenderOutput,
getTestComponent,
mockAnimationTimer,
mockWindowDimensions,
recordAnimationUpdates,
render,
unmockAnimationTimer,
unmockWindowDimensions,
useTestRef,
waitForAnimationUpdates,
} from '../../../ReJest/RuntimeTestsApi';

export const TRANSITION_REF = 'TRANSITION_REF';
export enum Direction {
Expand All @@ -13,6 +24,32 @@ export enum Direction {
LEFT_UP = 'LEFT_UP',
}

export async function getSnapshotUpdates(
layout: any,
direction: Direction,
snapshotLength: number,
changeSize?: boolean,
) {
await mockAnimationTimer();
await mockWindowDimensions();

const updatesContainer = await recordAnimationUpdates();
if (direction === Direction.UP || direction === Direction.DOWN) {
await render(<TransitionUpOrDown layout={layout} direction={direction} changeSize={!!changeSize} />);
} else {
await render(<TransitionLeftOrRight layout={layout} direction={direction} changeSize={!!changeSize} />);
}
await waitForAnimationUpdates(snapshotLength);
const component = getTestComponent(TRANSITION_REF);
const updates = updatesContainer.getUpdates(component);

await unmockAnimationTimer();
await unmockWindowDimensions();
await clearRenderOutput();

return updates;
}

export const TransitionUpOrDown = ({
layout,
direction,
Expand Down
Loading

0 comments on commit e550ae7

Please sign in to comment.