Skip to content

Commit 5333ad8

Browse files
sammy-SCfacebook-github-bot
authored andcommittedOct 21, 2020
Add unit tests for RCTComponentViewRegistry
Summary: Changelog: [internal] Adds unit tests for `RCTComponentViewRegistry`. Reviewed By: shergin Differential Revision: D24391419 fbshipit-source-id: e8adb641361c3e1394f652a1819f196d2402f493
1 parent 5b270e0 commit 5333ad8

File tree

2 files changed

+104
-18
lines changed

2 files changed

+104
-18
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTComponentViewRegistry.h>
9+
#import <React/RCTViewComponentView.h>
10+
#import <XCTest/XCTest.h>
11+
12+
@interface RCTComponentViewRegistryTests : XCTestCase
13+
@end
14+
15+
using namespace facebook::react;
16+
17+
@implementation RCTComponentViewRegistryTests {
18+
RCTComponentViewRegistry *_componentViewRegistry;
19+
}
20+
21+
- (void)setUp
22+
{
23+
[super setUp];
24+
_componentViewRegistry = [RCTComponentViewRegistry new];
25+
}
26+
27+
- (void)testComponentViewDescriptorWithTag
28+
{
29+
XCTAssertThrows(
30+
^{
31+
Tag nonExistingTag = 12;
32+
[self->_componentViewRegistry componentViewDescriptorWithTag:nonExistingTag];
33+
}(),
34+
@"Should throw: `Attempt to query unregistered component`");
35+
36+
Tag existingTag = 2;
37+
auto newViewDescriptor = [_componentViewRegistry
38+
dequeueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
39+
tag:existingTag];
40+
41+
XCTAssertNoThrow(^{
42+
auto componentDescriptor = [self->_componentViewRegistry componentViewDescriptorWithTag:existingTag];
43+
XCTAssertEqual(newViewDescriptor, componentDescriptor);
44+
}());
45+
}
46+
47+
- (void)testFindComponentViewWithTag
48+
{
49+
Tag nonExistingTag = 12;
50+
XCTAssertNil([_componentViewRegistry findComponentViewWithTag:nonExistingTag]);
51+
52+
Tag existingTag = 2;
53+
auto newViewDescriptor = [_componentViewRegistry
54+
dequeueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
55+
tag:existingTag];
56+
57+
XCTAssertEqual(newViewDescriptor.view, [_componentViewRegistry findComponentViewWithTag:existingTag]);
58+
}
59+
60+
- (void)testDequeueAndEnqueue
61+
{
62+
Tag existingTag = 2;
63+
auto newViewDescriptor = [_componentViewRegistry
64+
dequeueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
65+
tag:existingTag];
66+
67+
XCTAssertThrows(
68+
^{
69+
[self->_componentViewRegistry
70+
dequeueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
71+
tag:existingTag];
72+
}(),
73+
@"Should throw: `Attempt to dequeue already registered component`");
74+
75+
XCTAssertThrows(
76+
^{
77+
Tag nonExistingTag = 12;
78+
[self->_componentViewRegistry
79+
enqueueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
80+
tag:nonExistingTag
81+
componentViewDescriptor:newViewDescriptor];
82+
}(),
83+
@"Should throw: `Attempt to enqueue unregistered component`");
84+
}
85+
86+
@end

‎React/Tests/Text/RCTParagraphComponentViewTests.mm

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
#import <React/RCTParagraphComponentView.h>
1010

1111
#import <XCTest/XCTest.h>
12-
#import <react/attributedstring/AttributedString.h>
13-
#import <react/attributedstring/ParagraphAttributes.h>
14-
#import <react/attributedstring/TextAttributes.h>
15-
#import <react/componentregistry/ComponentDescriptorProviderRegistry.h>
16-
#import <react/components/root/RootComponentDescriptor.h>
17-
#import <react/components/text/ParagraphComponentDescriptor.h>
18-
#import <react/components/text/ParagraphShadowNode.h>
19-
#import <react/components/text/ParagraphState.h>
20-
#import <react/components/text/RawTextComponentDescriptor.h>
21-
#import <react/components/text/RawTextShadowNode.h>
22-
#import <react/components/text/TextComponentDescriptor.h>
23-
#import <react/components/text/TextShadowNode.h>
24-
#import <react/components/view/ViewComponentDescriptor.h>
25-
#import <react/element/ComponentBuilder.h>
26-
#import <react/element/Element.h>
27-
#import <react/element/testUtils.h>
28-
#import <react/textlayoutmanager/RCTTextLayoutManager.h>
29-
#import <react/textlayoutmanager/TextLayoutManager.h>
12+
#import <react/renderer/attributedstring/AttributedString.h>
13+
#import <react/renderer/attributedstring/ParagraphAttributes.h>
14+
#import <react/renderer/attributedstring/TextAttributes.h>
15+
#import <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
16+
#import <react/renderer/components/root/RootComponentDescriptor.h>
17+
#import <react/renderer/components/text/ParagraphComponentDescriptor.h>
18+
#import <react/renderer/components/text/ParagraphShadowNode.h>
19+
#import <react/renderer/components/text/ParagraphState.h>
20+
#import <react/renderer/components/text/RawTextComponentDescriptor.h>
21+
#import <react/renderer/components/text/RawTextShadowNode.h>
22+
#import <react/renderer/components/text/TextComponentDescriptor.h>
23+
#import <react/renderer/components/text/TextShadowNode.h>
24+
#import <react/renderer/components/view/ViewComponentDescriptor.h>
25+
#import <react/renderer/element/ComponentBuilder.h>
26+
#import <react/renderer/element/Element.h>
27+
#import <react/renderer/element/testUtils.h>
28+
#import <react/renderer/textlayoutmanager/RCTTextLayoutManager.h>
29+
#import <react/renderer/textlayoutmanager/TextLayoutManager.h>
3030

3131
@interface RCTParagraphComponentAccessibilityProviderTests : XCTestCase
3232

0 commit comments

Comments
 (0)
Please sign in to comment.