I am attempting to test the output of some of my functions that affect cell's inside a UICollectionView via the delegate, however after hours of trying to get it to play nice i have come across some baffling results
Setup
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MediaSelectionSuite" bundle:nil];
chatGallery = [storyboard instantiateViewControllerWithIdentifier:@"Gallery"];
[chatGallery performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
[chatGallery viewDidLoad];
SUT = [[GalleryCollectionViewDelegate alloc]initForParent:chatGallery];
}
This passes - affecting the cell directly
- (void)testCollectionHighlightedCellisYellow
{
// Arrange
[chatGallery assets][0] = [[GalleryAsset alloc]init];
[[chatGallery thumbnailCollectionView] reloadData];
UICollectionViewCell *cell = [SUT collectionView:[chatGallery thumbnailCollectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
// Act
[SUT highlightCell:cell withColour:[UIColor yellowColor]];
// Assert
XCTAssertEqual([UIColor yellowColor].CGColor, [cell.layer borderColor]);
}
This fails - affecting the cell via a generated NSIndexPath
- (void)testCollectionHighlightedCellisIndexZeroOne
{
// Arrange
[chatGallery assets][0] = [[GalleryAsset alloc]init];
[[chatGallery thumbnailCollectionView] reloadData];
UICollectionViewCell *cell = [SUT collectionView:[chatGallery thumbnailCollectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
// Act
[SUT highlightCellAtIndex:[[chatGallery thumbnailCollectionView] indexPathForCell:cell].item inCollection:[chatGallery thumbnailCollectionView] withColour:[UIColor yellowColor]];
// Assert
XCTAssertEqual([UIColor yellowColor].CGColor, [cell.layer borderColor]);
}
Your first thought it probably well you are using a different function clearly the second function is the one at fault...well usually i would be inclined to agree, but the following test will show you why this maybe is not the case.
This Fails
- (void)testCellsAreEqual
{
// Arrange
[chatGallery assets][0] = [[GalleryAsset alloc]init];
[[chatGallery thumbnailCollectionView] reloadData];
// Act
UICollectionViewCell *cellOne = [SUT collectionView:[chatGallery thumbnailCollectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
UICollectionViewCell *cellTwo = [SUT collectionView:[chatGallery thumbnailCollectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
// Assert
XCTAssertEqualObjects(cellOne,cellTwo );
}
This test was made after much debugging and seeing that for some reason the table cell produces two different cells for the same indexPath...Is this normal behaviour of dequeueReusableCellWithReuseIdentifier:forIndexPath:
? or have i set the tests up wrong somehow?
Another interesting thing to note is that calling [[chatGallery thumbnailCollectionView]cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
will always seem to return nil even when the previously shown [SUT collectionView:[chatGallery thumbnailCollectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
produces something.
Can anyone explain what is going on?
Aucun commentaire:
Enregistrer un commentaire