Skip to content

Commit

Permalink
Undo unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Latropos committed Oct 14, 2024
1 parent 0ac1839 commit ddabf41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,44 @@ const TestComponent = ({
);
};

async function getSnapshotUpdate(testAnimation: TestAnimation, delay: number, applyWithDelay: boolean) {
async function getSnapshotUpdates(testAnimation: TestAnimation, delay: number) {
await unmockAnimationTimer();
await mockAnimationTimer();
const updatesContainerNoDelay = await recordAnimationUpdates();
await render(<TestComponent applyWithDelay={applyWithDelay} testAnimation={testAnimation} delay={delay} />);
await wait(350 + delay);
await render(<TestComponent applyWithDelay={false} testAnimation={testAnimation} delay={delay} />);
await wait(350);

const componentActive = getTestComponent(TEST_COMPONENT_ACTIVE_REF);
const componentPassive = getTestComponent(TEST_COMPONENT_PASSIVE_REF);
let componentActive = getTestComponent(TEST_COMPONENT_ACTIVE_REF);
let componentPassive = getTestComponent(TEST_COMPONENT_PASSIVE_REF);

const snapshots = {
const noDelaySnapshots = {
active: updatesContainerNoDelay.getUpdates(componentActive),
passive: updatesContainerNoDelay.getUpdates(componentPassive),
activeNative: await updatesContainerNoDelay.getNativeSnapshots(componentActive),
passiveNative: await updatesContainerNoDelay.getNativeSnapshots(componentPassive),
};

await unmockAnimationTimer();
await mockAnimationTimer();
await clearRenderOutput();
return snapshots;
const updatesContainerWithDelay = await recordAnimationUpdates();
await render(<TestComponent applyWithDelay={true} testAnimation={testAnimation} delay={delay} />);
await wait(350 + delay);
componentActive = getTestComponent(TEST_COMPONENT_ACTIVE_REF);
componentPassive = getTestComponent(TEST_COMPONENT_PASSIVE_REF);

const delaySnapshots = {
active: updatesContainerWithDelay.getUpdates(componentActive),
passive: updatesContainerWithDelay.getUpdates(componentPassive),
activeNative: await updatesContainerWithDelay.getNativeSnapshots(componentActive),
passiveNative: await updatesContainerWithDelay.getNativeSnapshots(componentPassive),
};
await clearRenderOutput();

return {
noDelaySnapshots,
delaySnapshots,
};
}

function compareActiveAndPassiveSnapshots(
Expand All @@ -126,10 +145,8 @@ function compareActiveAndPassiveSnapshots(
};
});
expect([...filler, ...passive]).toMatchSnapshots(active);
const nativeSnapshotsFiller = _IS_FABRIC ? [{ width: 100 }] : [];

expect([...nativeSnapshotsFiller, ...active]).toMatchNativeSnapshots(activeNative);
expect([...nativeSnapshotsFiller, ...passive]).toMatchNativeSnapshots(passiveNative);
expect(active).toMatchNativeSnapshots(activeNative);
expect(passive).toMatchNativeSnapshots(passiveNative);
}

const testCases = [
Expand All @@ -143,8 +160,7 @@ const testCases = [
for (const { testAnimation, delay } of testCases) {
describe(`Apply **${delay}ms** delay to _${testAnimation}_`, () => {
test('Components animated with `withDelay` of have same snapshot but moved in time', async () => {
const delaySnapshots = await getSnapshotUpdate(testAnimation, delay, true);
const noDelaySnapshots = await getSnapshotUpdate(testAnimation, 0, false);
const { delaySnapshots, noDelaySnapshots } = await getSnapshotUpdates(testAnimation, delay);

compareActiveAndPassiveSnapshots(
'Components animated _without_ withDelay in two different ways have matching snapshots',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
recordAnimationUpdates,
render,
waitForAnimationUpdates,
useTestRef,
getTestComponent,
} from '../../../ReJest/RuntimeTestsApi';
import { ColorSnapshots as Snapshots } from './entering.snapshot';

const COMPONENT_REF = 'AnimatedComponent';
const AnimatedComponent = ({ fromColor, toColor }: { fromColor: string; toColor: string }) => {
const customAnim = () => {
'worklet';
Expand All @@ -24,19 +21,17 @@ const AnimatedComponent = ({ fromColor, toColor }: { fromColor: string; toColor:
const initialValues = { backgroundColor: fromColor };
return { initialValues, animations };
};
const ref = useTestRef(COMPONENT_REF);

return <Animated.View ref={ref} style={styles.colorBox} entering={customAnim} />;
return <Animated.View style={styles.colorBox} entering={customAnim} />;
};

async function getSnapshotUpdates(fromColor: string, toColor: string, snapshot: Array<any>) {
await mockAnimationTimer();
const updatesContainer = await recordAnimationUpdates();
await render(<AnimatedComponent fromColor={fromColor} toColor={toColor} />);
await waitForAnimationUpdates(snapshot.length);
const component = getTestComponent(COMPONENT_REF);
const updates = updatesContainer.getUpdates(component, ['backgroundColor']);
const nativeUpdates = await updatesContainer.getNativeSnapshots(component, ['backgroundColor']);
const updates = updatesContainer.getUpdates();
const nativeUpdates = await updatesContainer.getNativeSnapshots();
return [updates, nativeUpdates];
}

Expand Down

0 comments on commit ddabf41

Please sign in to comment.