Rename SonarKitLayoutPlugin to FlipperKitLayoutPlugin

Summary: Renames SonarKitLayoutPlugin to FlipperKitLayoutPlugin

Reviewed By: passy

Differential Revision: D9949785

fbshipit-source-id: 8cfde4dfad3e34038d2f66f0ce4393db9d83ef60
This commit is contained in:
Pritesh Nandgaonkar
2018-09-20 04:27:10 -07:00
committed by Facebook Github Bot
parent 04efc06f6a
commit ba7b43a547
73 changed files with 65 additions and 65 deletions

View File

@@ -0,0 +1,14 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <FlipperKitLayoutPlugin/SKTapListener.h>
@interface SKTapListenerMock : NSObject<SKTapListener>
- (void)tapAt:(CGPoint)point;
@end

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "SKTapListenerMock.h"
@implementation SKTapListenerMock
{
NSMutableArray<SKTapReceiver> *_tapReceivers;
}
@synthesize isMounted;
- (instancetype)init {
if (self = [super init]) {
_tapReceivers = [NSMutableArray new];
}
return self;
}
- (void)listenForTapWithBlock:(SKTapReceiver)receiver {
[_tapReceivers addObject: receiver];
}
- (void)tapAt:(CGPoint)point {
for (SKTapReceiver recv in _tapReceivers) {
recv(point);
}
[_tapReceivers removeAllObjects];
}
- (void)mountWithFrame:(CGRect)frame {
isMounted = YES;
}
- (void)unmount {
isMounted = NO;
}
@end

View File

@@ -0,0 +1,250 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <XCTest/XCTest.h>
#if FB_SONARKIT_ENABLED
#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h>
#import <FlipperKitLayoutPlugin/SKNodeDescriptor.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <SonarKitTestUtils/SonarConnectionMock.h>
#import <SonarKitTestUtils/SonarResponderMock.h>
#import "SKTapListenerMock.h"
#import "TestNode.h"
#import "TestNodeDescriptor.h"
@interface SonarKitLayoutPluginTests : XCTestCase
@end
@implementation SonarKitLayoutPluginTests
{
SKDescriptorMapper *_descriptorMapper;
}
- (void)setUp {
[super setUp];
_descriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[_descriptorMapper registerDescriptor: [TestNodeDescriptor new]
forClass: [TestNode class]];
}
- (void)testGetRoot {
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc]
initWithRootNode: [[TestNode alloc] initWithName: @"rootNode"]
withTapListener: nil
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
SonarReceiver receiver = connection.receivers[@"getRoot"];
receiver(@{}, responder);
XCTAssertTrue(([responder.successes containsObject: @{
@"id": @"rootNode",
@"name": @"TestNode",
@"children": @[],
@"attributes": @[],
@"data": @{},
@"decoration": @"",
}]));
}
- (void)testGetEmptyNodes {
FlipperKitLayoutPlugin *plugin = [FlipperKitLayoutPlugin new];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
SonarReceiver receiver = connection.receivers[@"getNodes"];
receiver(@{@"ids": @[]}, responder);
XCTAssertTrue(([responder.successes containsObject:@{@"elements": @[]}]));
}
- (void)testGetNodes {
TestNode *rootNode = [[TestNode alloc] initWithName: @"rootNode"];
NSArray *childNodes = @[
[[TestNode alloc] initWithName: @"testNode1"],
[[TestNode alloc] initWithName: @"testNode2"],
[[TestNode alloc] initWithName: @"testNode3"],
];
rootNode.children = childNodes;
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc] initWithRootNode: rootNode
withTapListener: nil
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
// Ensure that nodes are tracked
connection.receivers[@"getRoot"](@{}, responder);
SonarReceiver receiver = connection.receivers[@"getNodes"];
receiver(@{@"ids": @[ @"testNode1", @"testNode2", @"testNode3" ]}, responder);
XCTAssertTrue(([responder.successes containsObject:@{@"elements": @[
@{
@"id": @"testNode1",
@"name": @"TestNode",
@"children": @[],
@"attributes": @[],
@"data": @{},
@"decoration": @"",
},
@{
@"id": @"testNode2",
@"name": @"TestNode",
@"children": @[],
@"attributes": @[],
@"data": @{},
@"decoration": @"",
},
@{
@"id": @"testNode3",
@"name": @"TestNode",
@"children": @[],
@"attributes": @[],
@"data": @{},
@"decoration": @"",
},
]}]));
}
- (void)testSetHighlighted {
TestNode *rootNode = [[TestNode alloc] initWithName: @"rootNode"];
TestNode *testNode1 = [[TestNode alloc] initWithName: @"testNode1"];
TestNode *testNode2 = [[TestNode alloc] initWithName: @"testNode2"];
NSArray *childNodes = @[ testNode1, testNode2 ];
rootNode.children = childNodes;
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc] initWithRootNode: rootNode
withTapListener: nil
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
// Setup in order to track nodes successfully
connection.receivers[@"getRoot"](@{}, responder);
SonarReceiver getNodesCall = connection.receivers[@"getNodes"];
getNodesCall(@{@"ids": @[ @"testNode1", @"testNode2" ]}, responder);
SonarReceiver setHighlighted = connection.receivers[@"setHighlighted"];
setHighlighted(@{@"id":@"testNode2"}, responder);
XCTAssertTrue(testNode2.highlighted);
setHighlighted(@{@"id":@"testNode1"}, responder);
// Ensure that old highlight was removed
XCTAssertTrue(testNode1.highlighted && !testNode2.highlighted);
}
- (void)testSetSearchActive {
TestNode *rootNode = [[TestNode alloc] initWithName: @"rootNode"
withFrame: CGRectMake(0, 0, 20, 60)];
TestNode *testNode1 = [[TestNode alloc] initWithName: @"testNode1"
withFrame: CGRectMake(20, 20, 20, 20)];
TestNode *testNode2 = [[TestNode alloc] initWithName: @"testNode2"
withFrame: CGRectMake(20, 40, 20, 20)];
TestNode *testNode3 = [[TestNode alloc] initWithName: @"testNode3"
withFrame: CGRectMake(25, 42, 5, 5)];
rootNode.children = @[ testNode1, testNode2 ];
testNode2.children = @[ testNode3 ];
SKTapListenerMock *tapListener = [SKTapListenerMock new];
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc] initWithRootNode: rootNode
withTapListener: tapListener
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
connection.receivers[@"setSearchActive"](@{@"active":@YES}, responder);
// Fake a tap at `testNode3`
[tapListener tapAt: (CGPoint){ 26, 43 }];
XCTAssertTrue(([connection.sent[@"select"] containsObject: @{ @"path": @[ @"testNode2", @"testNode3" ] }]));
}
- (void)testSetSearchActiveMountAndUnmount {
TestNode *rootNode = [[TestNode alloc] initWithName: @"rootNode"];
SKTapListenerMock *tapListener = [SKTapListenerMock new];
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc] initWithRootNode: rootNode
withTapListener: tapListener
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
SonarReceiver setSearchActive = connection.receivers[@"setSearchActive"];
setSearchActive(@{@"active":@YES}, responder);
XCTAssertTrue(tapListener.isMounted);
setSearchActive(@{@"active":@NO}, responder);
XCTAssertTrue(! tapListener.isMounted);
}
- (void)testSetData {
TestNode *rootNode = [[TestNode alloc] initWithName: @"rootNode"
withFrame: CGRectMake(0, 0, 20, 60)];
TestNode *testNode1 = [[TestNode alloc] initWithName: @"testNode1"
withFrame: CGRectMake(20, 20, 20, 20)];
TestNode *testNode2 = [[TestNode alloc] initWithName: @"testNode2"
withFrame: CGRectMake(20, 40, 20, 20)];
TestNode *testNode3 = [[TestNode alloc] initWithName: @"testNode3"
withFrame: CGRectMake(25, 42, 5, 5)];
rootNode.children = @[ testNode1, testNode2 ];
testNode2.children = @[ testNode3 ];
SKTapListenerMock *tapListener = [SKTapListenerMock new];
FlipperKitLayoutPlugin *plugin = [[FlipperKitLayoutPlugin alloc] initWithRootNode: rootNode
withTapListener: tapListener
withDescriptorMapper: _descriptorMapper];
SonarConnectionMock *connection = [SonarConnectionMock new];
SonarResponderMock *responder = [SonarResponderMock new];
[plugin didConnect:connection];
// Setup in order to track nodes successfully
connection.receivers[@"getRoot"](@{}, responder);
connection.receivers[@"getNodes"](@{ @"ids": @[ @"testNode2" ] }, responder);
// Modify the name of testNode3
connection.receivers[@"setData"](@{
@"id": @"testNode3",
@"path": @[ @"TestNode", @"name" ],
@"value": @"changedNameForTestNode3",
}, responder);
XCTAssertTrue([testNode3.nodeName isEqualToString: @"changedNameForTestNode3"]);
}
@end
#endif

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <UIKit/UIKit.h>
@interface TestNode : NSObject
@property (nonatomic, copy) NSString *nodeName;
@property (nonatomic, copy) NSArray<TestNode *> *children;
@property (nonatomic, assign) BOOL highlighted;
@property (nonatomic, assign) CGRect frame;
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithName:(NSString *)name withFrame:(CGRect)frame;
@end

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "TestNode.h"
@implementation TestNode
- (instancetype)initWithName:(NSString *)name {
return [self initWithName: name
withFrame: CGRectZero];
}
- (instancetype)initWithName:(NSString *)name withFrame:(CGRect)frame {
if (self = [super init]) {
_nodeName = name;
_frame = frame;
}
return self;
}
@end

View File

@@ -0,0 +1,13 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <FlipperKitLayoutPlugin/SKNodeDescriptor.h>
#import "TestNode.h"
@interface TestNodeDescriptor : SKNodeDescriptor<TestNode *>
@end

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "TestNodeDescriptor.h"
@implementation TestNodeDescriptor
- (NSString *)identifierForNode:(TestNode *)node {
return node.nodeName;
}
- (NSUInteger)childCountForNode:(TestNode *)node {
return [node.children count];
}
- (id)childForNode:(TestNode *)node atIndex:(NSUInteger)index {
return [node.children objectAtIndex: index];
}
- (void)setHighlighted:(BOOL)highlighted forNode:(TestNode *)node {
node.highlighted = highlighted;
}
- (void)hitTest:(SKTouch *)touch forNode:(TestNode *)node {
NSUInteger index = [node.children count] - 1;
for (TestNode *childNode in [node.children reverseObjectEnumerator]) {
if ([touch containedIn: childNode.frame]) {
[touch continueWithChildIndex: index withOffset: node.frame.origin];
return;
}
index = index - 1;
}
[touch finish];
}
- (NSDictionary<NSString *, SKNodeUpdateData> *)dataMutationsForNode:(TestNode *)node {
return @{
@"TestNode.name": ^(NSString *newName) {
node.nodeName = newName;
}
};
}
@end