@samitouri / QOS-React / commits / 4d65408938

Test that fabric renderer sends diffs (#12075)

Sebastian Markbåge committed Jan 22, 2018 at 22:29 UTC 4d6540893809cbecb5d7490a77ec7ad32e2aeeb3
3 files changed +58 -4
packages/react-native-renderer/src/__mocks__/FabricUIManager.js
+4 -4
@@ -72,21 +72,21 @@ const RCTFabricUIManager = {
72 }),
73 cloneNodeWithNewProps: jest.fn(function cloneNodeWithNewProps(
74 node,
75 - newProps,
75 + newPropsDiff,
76 ) {
77 return {
78 reactTag: node.reactTag,
79 viewName: node.viewName,
80 - props: newProps,
80 + props: {...node.props, ...newPropsDiff},
81 children: node.children,
82 };
83 }),
84 cloneNodeWithNewChildrenAndProps: jest.fn(
85 - function cloneNodeWithNewChildrenAndProps(node, newProps) {
85 + function cloneNodeWithNewChildrenAndProps(node, newPropsDiff) {
86 return {
87 reactTag: node.reactTag,
88 viewName: node.viewName,
89 - props: newProps,
89 + props: {...node.props, ...newPropsDiff},
90 children: [],
91 };
92 },
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
+42
@@ -109,6 +109,48 @@ describe('ReactFabric', () => {
109 ).toBe(1);
110 });
111
112 + it('should only pass props diffs to FabricUIManager.cloneNode', () => {
113 + const View = createReactNativeComponentClass('View', () => ({
114 + validAttributes: {foo: true, bar: true},
115 + uiViewClassName: 'View',
116 + }));
117 +
118 + ReactFabric.render(
119 + <View foo="a" bar="a">
120 + 1
121 + </View>,
122 + 11,
123 + );
124 + expect(FabricUIManager.cloneNode).not.toBeCalled();
125 + expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
126 + expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
127 + expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
128 +
129 + ReactFabric.render(
130 + <View foo="a" bar="b">
131 + 1
132 + </View>,
133 + 11,
134 + );
135 + expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
136 + bar: 'b',
137 + });
138 + expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
139 +
140 + ReactFabric.render(
141 + <View foo="b" bar="b">
142 + 2
143 + </View>,
144 + 11,
145 + );
146 + expect(
147 + FabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
148 + ).toEqual({
149 + foo: 'b',
150 + });
151 + expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
152 + });
153 +
154 it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => {
155 const View = createReactNativeComponentClass('View', () => ({
156 validAttributes: {foo: true},
packages/react-native-renderer/src/__tests__/__snapshots__/ReactFabric-test.internal.js.snap
+12
@@ -49,3 +49,15 @@ exports[`ReactFabric renders and reorders children 2`] = `
49 View {\\"title\\":\\"z\\"}
50 View {\\"title\\":\\"y\\"}"
51 `;
52 +
53 +exports[`ReactFabric should only pass props diffs to FabricUIManager.cloneNode 1`] = `
54 +"11
55 + View {\\"foo\\":\\"a\\",\\"bar\\":\\"b\\"}
56 + RCTRawText {\\"text\\":\\"1\\"}"
57 +`;
58 +
59 +exports[`ReactFabric should only pass props diffs to FabricUIManager.cloneNode 2`] = `
60 +"11
61 + View {\\"foo\\":\\"b\\",\\"bar\\":\\"b\\"}
62 + RCTRawText {\\"text\\":\\"2\\"}"
63 +`;