Skip to content
Permalink
Browse files

[NavigationDrawer] Add Fakes files for tests (#5453)

### Context
In #5423 my thinking was that we would need to test MDCBottomDrawerViewController but majority of the test are going to be related to MDCBottomDrawerContainerViewController. We may still want to test MDCBottomDrawerViewController so that is why I haven't completely removed that file for tests. But, we need fakes in a couple places so this adds _Fakes_ files so that code can be shared.

### The problem
We need fakes for test in MaterialNavigationDrawer because we can't present and that code should be shared.

### The fix
Add a `MDCNavigationDrawerFakes` files so we can have fakes and they can be shared across test files.

### Related bugs
#4911
  • Loading branch information
codeman7 committed Oct 19, 2018
1 parent f18085d commit 596f72b395039e3250338f45198f424f7aa90c04
@@ -44,7 +44,10 @@ mdc_objc_library(
mdc_objc_library(
name = "unit_test_sources",
testonly = 1,
srcs = native.glob(["tests/unit/*.m"]),
srcs = native.glob([
"tests/unit/*.m",
"tests/unit/*.h",
]),
sdk_frameworks = [
"UIKit",
"XCTest",
@@ -0,0 +1,51 @@
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "MDCNavigationDrawerFakes.h"

@implementation MDCNavigationDrawerFakeHeaderViewController
@end

static NSString *const reuseIdentifier = @"FakeCell";

@implementation MDCNavigationDrawerFakeTableViewController

- (instancetype)init {
self = [super init];
if (self) {
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
return self;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier
forIndexPath:indexPath];
return cell;
}

@end
@@ -0,0 +1,23 @@
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import <UIKit/UIKit.h>

#import "MaterialNavigationDrawer.h"

@interface MDCNavigationDrawerFakeHeaderViewController : UIViewController <MDCBottomDrawerHeader>
@end

@interface MDCNavigationDrawerFakeTableViewController : UITableViewController
@end
@@ -15,6 +15,7 @@
#import <XCTest/XCTest.h>

#import "../../src/private/MDCBottomDrawerContainerViewController.h"
#import "MDCNavigationDrawerFakes.h"

@interface MDCBottomDrawerContainerViewController (ScrollViewTests)

@@ -16,52 +16,12 @@

#import "MaterialNavigationDrawer.h"

#import "MDCNavigationDrawerFakes.h"

@interface MDCNavigationDrawerTest : XCTestCase
@property(nonatomic, strong) MDCBottomDrawerViewController *navigationDrawer;
@end

@interface MDCNavigationDrawerFakeTableViewController : UITableViewController
@end

@interface MDCNavigationDrawerFakeHeaderViewController : UIViewController <MDCBottomDrawerHeader>
@end

static NSString *const reuseIdentifier = @"FakeCell";

@implementation MDCNavigationDrawerFakeTableViewController

- (instancetype)init {
self = [super init];
if (self) {
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
return self;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier
forIndexPath:indexPath];
return cell;
}

@end

@implementation MDCNavigationDrawerFakeHeaderViewController
@end

@implementation MDCNavigationDrawerTest

- (void)setUp {

0 comments on commit 596f72b

Please sign in to comment.
You can’t perform that action at this time.