diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-03-25 14:24:59 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-03-25 14:24:59 -0400 |
commit | dee4c80d80b1174bdd7fb442aa79997a622d2f1b (patch) | |
tree | 7cce84e3f4d5faba680e2a69589449a44e35b9fe /SmartDeviceLinkTests/SDLCacheFileManagerSpec.m | |
parent | 38d2efabb9976b3902800ad6882a4845fcd31e9a (diff) | |
download | sdl_ios-dee4c80d80b1174bdd7fb442aa79997a622d2f1b.tar.gz |
updated tests
Diffstat (limited to 'SmartDeviceLinkTests/SDLCacheFileManagerSpec.m')
-rw-r--r-- | SmartDeviceLinkTests/SDLCacheFileManagerSpec.m | 106 |
1 files changed, 90 insertions, 16 deletions
diff --git a/SmartDeviceLinkTests/SDLCacheFileManagerSpec.m b/SmartDeviceLinkTests/SDLCacheFileManagerSpec.m index 4b79981af..2ec4ee42d 100644 --- a/SmartDeviceLinkTests/SDLCacheFileManagerSpec.m +++ b/SmartDeviceLinkTests/SDLCacheFileManagerSpec.m @@ -17,9 +17,13 @@ @interface SDLCacheFileManager () ++ (nullable NSString *)sdl_writeImage:(UIImage *)icon toFileFromURL:(NSString *)urlString atFilePath:(NSString *)filePath; + @property (weak, nonatomic, nullable) NSURLSession *urlSession; @property (weak, nonatomic, nullable) NSURLSessionDataTask *dataTask; @property (strong, nonatomic) NSFileManager *fileManager; +@property (strong, nonatomic, readonly, nullable) NSString *cacheFileBaseDirectory; +@property (strong, nonatomic, readonly, nullable) NSString *archiveFileDirectory; @end @@ -27,48 +31,118 @@ QuickSpecBegin(SDLCacheFileManagerSpec) describe(@"a cache file manager", ^{ __block SDLCacheFileManager *testManager = nil; + __block NSFileManager *mockFileManager = nil; + __block id mockUnarchiver = nil; + __block id mockUIImage = nil; + __block SDLOnSystemRequest *testRequest = nil; + __block NSString *testURL = nil; + __block NSString *testFilePath = nil; + __block NSString *testHashName = nil; + __block UIImage *testImage = nil; + __block SDLIconArchiveFile *testArchiveFile = nil; + __block SDLLockScreenIconCache *testIconCache = nil; + __block NSArray<SDLLockScreenIconCache *> *testArchiveFileLockScreenCacheArray = nil; beforeEach(^{ testManager = [[SDLCacheFileManager alloc] init]; - testManager.fileManager = OCMClassMock([NSFileManager class]); + + testURL = @"http://i.imgur.com/TgkvOIZ.png"; + testRequest = [[SDLOnSystemRequest alloc] init]; + testRequest.url = testURL; + + testHashName = @"935e06761f887b20"; + + testFilePath = [[NSBundle bundleForClass:self.class] pathForResource:@"testImagePNG" ofType:@"png"]; + + testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil]; + + testIconCache = [[SDLLockScreenIconCache alloc] initWithIconUrl:testURL iconFilePath:testFilePath]; + // add expired testIconCache object + testArchiveFileLockScreenCacheArray = @[testIconCache]; + + testArchiveFile = [[SDLIconArchiveFile alloc] init]; + testArchiveFile.lockScreenIconCaches = testArchiveFileLockScreenCacheArray; + + mockFileManager = OCMStrictClassMock([NSFileManager class]); + testManager.fileManager = mockFileManager; + mockUnarchiver = OCMClassMock([NSKeyedUnarchiver class]); + OCMStub(ClassMethod([mockUnarchiver unarchiveObjectWithFile:[OCMArg any]])).andReturn(testArchiveFile); + mockUIImage = OCMClassMock([UIImage class]); }); it(@"should initialize properties", ^{ expect(testManager.urlSession).toNot(beNil()); + expect(testManager.fileManager).toNot(beNil()); }); - describe(@"after receiving lock screen icon system request", ^{ - __block SDLOnSystemRequest *request = nil; - __block NSString *testURL = nil; - __block SDLIconArchiveFile *archiveFile = nil; - describe(@"request with existing icon", ^{ beforeEach(^{ - testURL = @"https://livio.io/"; - - request = [[SDLOnSystemRequest alloc] init]; - request.url = testURL; + OCMStub(ClassMethod([mockUIImage imageWithContentsOfFile:[OCMArg any]])).andReturn(testImage); }); context(@"icon is not exipred", ^{ - // retrieve icon from path - // return icon + __block UIImage *resultImage = nil; + __block NSError *resultError = nil; + + beforeEach(^{ + OCMStub([mockFileManager fileExistsAtPath:[OCMArg any]]).andReturn(YES); + [testManager retrieveImageForRequest:testRequest withCompletionHandler:^(UIImage * _Nullable image, NSError * _Nullable error) { + resultImage = image; + resultError = error; + }]; + }); + + it(@"should return image and no error", ^{ + expect(resultImage).to(equal(testImage)); + expect(resultError).to(beNil()); + }); + }); context(@"icon is expired", ^{ - // download icon - // update archive file - // return icon + + + it(@"should have an archive file present with expired icon", ^{ + expect(testManager.archiveFileDirectory).toNot(beNil()); + expect(testArchiveFile).toNot(beNil()); + expect(testArchiveFile.lockScreenIconCaches.count).toNot(beNil()); + }); + + it(@"should have same url as cache", ^{ + expect(testURL).to(match(testIconCache.iconUrl)); + }); + + it(@"should update icon", ^{ + + }); + + it(@"should return icon with nil error", ^{ + UIImage *image = [[UIImage alloc] init]; + NSError *error = nil; +// OCMStub([testManager retrieveImageForRequest:[OCMArg any] withCompletionHandler:([OCMArg invokeBlockWithArgs:@[image, error], nil])]); + expect(image).toNot(beNil()); + expect(error).to(beNil()); + }); }); }); describe(@"request with new icon", ^{ // it should dowload the icon + + context(@"directory doesn't exist", ^{ + // create directory + // download icon + }); + + context(@"directory exists", ^{ + // download icon + // save to archive file + // return icon + }); }); }); -}); QuickSpecEnd |