Skip to content

Commit e550ae7

Browse files
authored
More test cases - custom layout transitions (#6458)
<!-- 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. -->
1 parent 4004a67 commit e550ae7

File tree

6 files changed

+263
-98
lines changed

6 files changed

+263
-98
lines changed

apps/common-app/src/examples/RuntimeTests/RuntimeTestsExample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ export default function RuntimeTestsExample() {
7171
describe('Compare layout transitions with **constant view size** with snapshots', () => {
7272
require('./tests/layoutAnimations/layout/predefinedLayoutPosition.test');
7373
});
74-
describe('Compare Test layout transitions including view **size changes** with snapshots', () => {
74+
describe('Compare predefined layout transitions including view **size changes** with snapshots', () => {
7575
require('./tests/layoutAnimations/layout/positionAndSize.test');
7676
});
77+
require('./tests/layoutAnimations/layout/custom.test');
7778
},
7879
},
7980
{

apps/common-app/src/examples/RuntimeTests/tests/layoutAnimations/layout/TestComponents.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import React, { useState, useEffect } from 'react';
22
import { View, StyleSheet } from 'react-native';
33
import Animated from 'react-native-reanimated';
4-
import { useTestRef } from '../../../ReJest/RuntimeTestsApi';
4+
import {
5+
clearRenderOutput,
6+
getTestComponent,
7+
mockAnimationTimer,
8+
mockWindowDimensions,
9+
recordAnimationUpdates,
10+
render,
11+
unmockAnimationTimer,
12+
unmockWindowDimensions,
13+
useTestRef,
14+
waitForAnimationUpdates,
15+
} from '../../../ReJest/RuntimeTestsApi';
516

617
export const TRANSITION_REF = 'TRANSITION_REF';
718
export enum Direction {
@@ -13,6 +24,32 @@ export enum Direction {
1324
LEFT_UP = 'LEFT_UP',
1425
}
1526

27+
export async function getSnapshotUpdates(
28+
layout: any,
29+
direction: Direction,
30+
snapshotLength: number,
31+
changeSize?: boolean,
32+
) {
33+
await mockAnimationTimer();
34+
await mockWindowDimensions();
35+
36+
const updatesContainer = await recordAnimationUpdates();
37+
if (direction === Direction.UP || direction === Direction.DOWN) {
38+
await render(<TransitionUpOrDown layout={layout} direction={direction} changeSize={!!changeSize} />);
39+
} else {
40+
await render(<TransitionLeftOrRight layout={layout} direction={direction} changeSize={!!changeSize} />);
41+
}
42+
await waitForAnimationUpdates(snapshotLength);
43+
const component = getTestComponent(TRANSITION_REF);
44+
const updates = updatesContainer.getUpdates(component);
45+
46+
await unmockAnimationTimer();
47+
await unmockWindowDimensions();
48+
await clearRenderOutput();
49+
50+
return updates;
51+
}
52+
1653
export const TransitionUpOrDown = ({
1754
layout,
1855
direction,

0 commit comments

Comments
 (0)