@@ -29,20 +29,29 @@ class AnimatedPropsRegistryTest : public ::testing::Test {
2929 registry.initializeSurface (1 );
3030 }
3131
32- void update (AnimatedProps props) {
33- std::vector<AnimationMutations> batches (1 );
34- batches[0 ].batch .push_back (
32+ void update (
33+ AnimatedProps props,
34+ bool commitDirectProps = true ,
35+ bool finishesAnimation = false ) {
36+ std::vector<FrontendMutations> batches (1 );
37+ batches[0 ].commitDirectProps = commitDirectProps;
38+ batches[0 ].mutations .batch .push_back (
3539 AnimationMutation{
3640 .tag = 10 ,
3741 .family = node->getFamilyShared (),
38- .props = std::move (props)});
42+ .props = std::move (props),
43+ .finishesAnimation = finishesAnimation});
3944 registry.update (batches);
4045 }
4146
42- void updateRaw (folly::dynamic props) {
47+ void updateRaw (
48+ folly::dynamic props,
49+ bool commitDirectProps = true ,
50+ bool finishesAnimation = false ) {
4351 update (
44- {.props = {},
45- .rawProps = std::make_unique<RawProps>(std::move (props))});
52+ {.props = {}, .rawProps = std::make_unique<RawProps>(std::move (props))},
53+ commitDirectProps,
54+ finishesAnimation);
4655 }
4756
4857 void expectRawProps (const folly::dynamic& expected) {
@@ -54,6 +63,66 @@ class AnimatedPropsRegistryTest : public ::testing::Test {
5463 }
5564};
5665
66+ TEST_F (AnimatedPropsRegistryTest, unsyncedUpdatesAreNotRecorded) {
67+ updateRaw (folly::dynamic::object (" opacity" , 0.5 ), false );
68+ auto [families, map] = registry.getMap (1 );
69+ EXPECT_TRUE (families.empty ());
70+ EXPECT_FALSE (map.contains (10 ));
71+ }
72+
73+ TEST_F (AnimatedPropsRegistryTest, unsyncedFinalValuesAreKeptApart) {
74+ updateRaw (folly::dynamic::object (" opacity" , 0.5 ), false );
75+ updateRaw (folly::dynamic::object (" opacity" , 0.2 ), false , true );
76+
77+ auto [families, map] = registry.getMap (1 );
78+ EXPECT_TRUE (families.empty ());
79+ EXPECT_FALSE (map.contains (10 ));
80+ auto finalValues = registry.takeFinalValues (1 );
81+ ASSERT_TRUE (finalValues.contains (10 ));
82+ folly::dynamic expected = folly::dynamic::object (" opacity" , 0.2 );
83+ EXPECT_EQ (finalValues.at (10 ).props , expected);
84+ }
85+
86+ TEST_F (AnimatedPropsRegistryTest, takenFinalValuesAreNotTakenAgain) {
87+ updateRaw (folly::dynamic::object (" opacity" , 0.2 ), false , true );
88+ registry.takeFinalValues (1 );
89+ updateRaw (folly::dynamic::object (" width" , 10 ), false , true );
90+
91+ auto finalValues = registry.takeFinalValues (1 );
92+ ASSERT_TRUE (finalValues.contains (10 ));
93+ folly::dynamic expected = folly::dynamic::object (" width" , 10 );
94+ EXPECT_EQ (finalValues.at (10 ).props , expected);
95+ }
96+
97+ TEST_F (AnimatedPropsRegistryTest, restoredFinalValuesYieldToNewerOnes) {
98+ updateRaw (folly::dynamic::object (" opacity" , 0.2 )(" width" , 10 ), false , true );
99+ auto taken = registry.takeFinalValues (1 );
100+ updateRaw (folly::dynamic::object (" opacity" , 0.3 ), false , true );
101+
102+ registry.restoreFinalValues (1 , std::move (taken));
103+
104+ auto finalValues = registry.takeFinalValues (1 );
105+ ASSERT_TRUE (finalValues.contains (10 ));
106+ folly::dynamic expected = folly::dynamic::object (" opacity" , 0.3 )(" width" , 10 );
107+ EXPECT_EQ (finalValues.at (10 ).props , expected);
108+ }
109+
110+ TEST_F (AnimatedPropsRegistryTest, unsyncedUpdatesEraseOlderRecordedValues) {
111+ updateRaw (folly::dynamic::object (" opacity" , 0.8 )(" width" , 5 ));
112+ snapshot ();
113+ updateRaw (folly::dynamic::object (" opacity" , 0.7 ));
114+ updateRaw (folly::dynamic::object (" opacity" , 0.2 ), false );
115+ expectRawProps (folly::dynamic::object (" width" , 5 ));
116+ }
117+
118+ TEST_F (AnimatedPropsRegistryTest, laterSyncedUpdatesAreRecorded) {
119+ updateRaw (folly::dynamic::object (" opacity" , 0.25 ));
120+ snapshot ();
121+ updateRaw (folly::dynamic::object (" opacity" , 0.5 ), false );
122+ updateRaw (folly::dynamic::object (" opacity" , 0.75 ));
123+ expectRawProps (folly::dynamic::object (" opacity" , 0.75 ));
124+ }
125+
57126TEST_F (AnimatedPropsRegistryTest, rawUpdatesDoNotAllocateTypedProps) {
58127 for (int frame = 0 ; frame < 10 ; frame++) {
59128 updateRaw (folly::dynamic::object (" opacity" , frame / 10.0 ));
@@ -68,16 +137,17 @@ TEST_F(AnimatedPropsRegistryTest, updatePreservesInputForSynchronousMount) {
68137 folly::dynamic rawProps = folly::dynamic::object (" opacity" , 0.25 )(
69138 " transform" ,
70139 folly::dynamic::array (folly::dynamic::object (" translateX" , 10 )));
71- std::vector<AnimationMutations > batches (1 );
72- batches[0 ].batch .push_back (
140+ std::vector<FrontendMutations > batches (1 );
141+ batches[0 ].mutations . batch .push_back (
73142 AnimationMutation{
74143 .tag = 10 ,
75144 .family = node->getFamilyShared (),
76145 .props = AnimatedProps{
77146 .props = {}, .rawProps = std::make_unique<RawProps>(rawProps)}});
78147 registry.update (batches);
79148 registry.update (batches);
80- EXPECT_EQ (batches[0 ].batch [0 ].props .rawProps ->toDynamic (), rawProps);
149+ EXPECT_EQ (
150+ batches[0 ].mutations .batch [0 ].props .rawProps ->toDynamic (), rawProps);
81151 EXPECT_EQ (*snapshot ().rawProps , rawProps);
82152}
83153
0 commit comments