Updated tests to cover the new API and repeated all of the test logic for URL initialisation to ensure that the functionality is the same

This commit is contained in:
Gareth Reese
2016-03-08 08:30:13 +00:00
parent fb1c5e8ee6
commit f7ff8b4173
2 changed files with 123 additions and 39 deletions

View File

@@ -497,7 +497,7 @@
NSLog(@"Item is %@", item);
if (logEvent)
NSLog(@"Log code %ld domain %@ comment %@", logEvent.errorStatusCode, logEvent.errorDomain, logEvent.errorComment);
NSLog(@"Log code %ld domain %@ comment %@", (long)logEvent.errorStatusCode, logEvent.errorDomain, logEvent.errorComment);
}
}

View File

@@ -15,6 +15,7 @@
ASVideoNode *_videoNode;
AVURLAsset *_firstAsset;
AVAsset *_secondAsset;
NSURL *_url;
}
@end
@@ -42,103 +43,151 @@
- (void)setUp
{
_videoNode = [[ASVideoNode alloc] init];
// _videoNode = [[ASVideoNode alloc] init];
_firstAsset = [AVURLAsset assetWithURL:[NSURL URLWithString:@"firstURL"]];
_secondAsset = [AVAsset assetWithURL:[NSURL URLWithString:@"secondURL"]];
_url = [NSURL URLWithString:@"testURL"];
}
- (void)testVideoNodeReplacesAVPlayerItemWhenNewURLIsSet
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
_videoNode.asset = _firstAsset;
AVPlayerItem *item = [_videoNode currentItem];
_videoNode.asset = _secondAsset;
AVPlayerItem *secondItem = [_videoNode currentItem];
XCTAssertNotEqualObjects(item, secondItem);
}
- (void)testVideoNodeDoesNotReplaceAVPlayerItemWhenSameURLIsSet
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
_videoNode.asset = _firstAsset;
AVPlayerItem *item = [_videoNode currentItem];
_videoNode.asset = [AVAsset assetWithURL:_firstAsset.URL];
AVPlayerItem *secondItem = [_videoNode currentItem];
XCTAssertEqualObjects(item, secondItem);
}
- (void)testSpinnerDefaultsToNil
{
XCTAssertNil(_videoNode.spinner);
}
- (void)testOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnode
{
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnodeWithUrl];
}
- (void)testOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnodeWithUrl
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnodeWithUrl];
}
- (void)doOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnodeWithUrl
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
_videoNode.asset = _firstAsset;
[_videoNode play];
XCTAssertNotNil(_videoNode.spinner);
}
- (void)testOnPauseSpinnerIsPausedIfPresent
{
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doOnPauseSpinnerIsPausedIfPresentWithURL];
}
- (void)testOnPauseSpinnerIsPausedIfPresentWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doOnPauseSpinnerIsPausedIfPresentWithURL];
}
- (void)doOnPauseSpinnerIsPausedIfPresentWithURL
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
_videoNode.asset = _firstAsset;
[_videoNode play];
[_videoNode pause];
XCTAssertFalse(((UIActivityIndicatorView *)_videoNode.spinner.view).isAnimating);
}
- (void)testOnVideoReadySpinnerIsStoppedAndRemoved
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doOnVideoReadySpinnerIsStoppedAndRemovedWithURL];
}
- (void)testOnVideoReadySpinnerIsStoppedAndRemovedWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doOnVideoReadySpinnerIsStoppedAndRemovedWithURL];
}
- (void)doOnVideoReadySpinnerIsStoppedAndRemovedWithURL
{
_videoNode.interfaceState = ASInterfaceStateFetchData;
[_videoNode play];
[_videoNode observeValueForKeyPath:@"status" ofObject:[_videoNode currentItem] change:@{@"new" : @(AVPlayerItemStatusReadyToPlay)} context:NULL];
XCTAssertFalse(((UIActivityIndicatorView *)_videoNode.spinner.view).isAnimating);
}
- (void)testPlayerDefaultsToNil
{
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
XCTAssertNil(_videoNode.player);
}
- (void)testPlayerDefaultsToNilWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
XCTAssertNil(_videoNode.player);
}
- (void)testPlayerIsCreatedInFetchData
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
_videoNode.interfaceState = ASInterfaceStateFetchData;
XCTAssertNotNil(_videoNode.player);
}
- (void)testPlayerIsCreatedInFetchDataWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
_videoNode.interfaceState = ASInterfaceStateFetchData;
XCTAssertNotNil(_videoNode.player);
}
- (void)testPlayerLayerNodeIsAddedOnDidLoadIfVisibleAndAutoPlaying
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doPlayerLayerNodeIsAddedOnDidLoadIfVisibleAndAutoPlayingWithURL];
}
- (void)testPlayerLayerNodeIsAddedOnDidLoadIfVisibleAndAutoPlayingWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doPlayerLayerNodeIsAddedOnDidLoadIfVisibleAndAutoPlayingWithURL];
}
- (void)doPlayerLayerNodeIsAddedOnDidLoadIfVisibleAndAutoPlayingWithURL
{
[_videoNode setInterfaceState:ASInterfaceStateNone];
[_videoNode didLoad];
XCTAssert(![_videoNode.subnodes containsObject:_videoNode.playerNode]);
}
- (void)testPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlaying
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlaying];
}
- (void)testPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlayingWithUrl
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlaying];
}
- (void)doPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlaying
{
[_videoNode pause];
[_videoNode setInterfaceState:ASInterfaceStateVisible];
[_videoNode didLoad];
@@ -149,7 +198,18 @@
- (void)testVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplay
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplay];
}
- (void)testVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplayWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplay];
}
- (void)doVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplay
{
_videoNode.shouldAutoplay = YES;
_videoNode.playerNode = [[ASDisplayNode alloc] initWithLayerBlock:^CALayer *{
AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
@@ -162,9 +222,21 @@
XCTAssertTrue(_videoNode.shouldBePlaying);
}
- (void)testVideoShouldPauseWhenItLeavesVisibleButShouldKnowPlayingShouldRestartLater
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doVideoShouldPauseWhenItLeavesVisibleButShouldKnowPlayingShouldRestartLater];
}
- (void)testVideoShouldPauseWhenItLeavesVisibleButShouldKnowPlayingShouldRestartLaterWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doVideoShouldPauseWhenItLeavesVisibleButShouldKnowPlayingShouldRestartLater];
}
- (void)doVideoShouldPauseWhenItLeavesVisibleButShouldKnowPlayingShouldRestartLater
{
[_videoNode play];
[_videoNode interfaceStateDidChange:ASInterfaceStateNone fromState:ASInterfaceStateVisible];
@@ -173,9 +245,21 @@
XCTAssertTrue(_videoNode.shouldBePlaying);
}
- (void)testVideoThatIsPlayingWhenItLeavesVisibleRangeStartsAgainWhenItComesBack
{
_videoNode.asset = _firstAsset;
_videoNode = [[ASVideoNode alloc] initWithAsset:_firstAsset];
[self doVideoThatIsPlayingWhenItLeavesVisibleRangeStartsAgainWhenItComesBack];
}
- (void)testVideoThatIsPlayingWhenItLeavesVisibleRangeStartsAgainWhenItComesBackWithURL
{
_videoNode = [[ASVideoNode alloc] initWithURL:_url];
[self doVideoThatIsPlayingWhenItLeavesVisibleRangeStartsAgainWhenItComesBack];
}
- (void)doVideoThatIsPlayingWhenItLeavesVisibleRangeStartsAgainWhenItComesBack
{
[_videoNode play];
[_videoNode interfaceStateDidChange:ASInterfaceStateVisible fromState:ASInterfaceStateNone];