summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Elias <francois.elias@livio.io>2020-12-03 08:27:21 -0500
committerFrank Elias <francois.elias@livio.io>2020-12-03 08:27:21 -0500
commit85feab359c62729aa046ae66ea4b635b60f35c6b (patch)
tree9c2be16ffd131628c230594fcb6900b886ef1e0e
parentede6d2e81fee8a036a0e85ad8e9c86866c6ef82b (diff)
downloadsdl_ios-85feab359c62729aa046ae66ea4b635b60f35c6b.tar.gz
Unit tests for fileNeedsUpload
-rw-r--r--SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m6
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m62
2 files changed, 65 insertions, 3 deletions
diff --git a/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m b/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
index b4fa5f169..65285f830 100644
--- a/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
@@ -103,7 +103,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_uploadInitialStateImagesWithCompletionHandler:(void (^)(void))handler {
NSMutableArray<SDLArtwork *> *initialStatesToBeUploaded = [NSMutableArray array];
for (SDLSoftButtonObject *object in self.softButtonObjects) {
- if (self.fileManager != nil && [self.fileManager fileNeedsUpload:object.currentState.artwork] && self.softButtonCapabilities.imageSupported.boolValue) {
+ if ([self.fileManager fileNeedsUpload:object.currentState.artwork]) {
[initialStatesToBeUploaded addObject:object.currentState.artwork];
}
}
@@ -118,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
for (SDLSoftButtonObject *object in self.softButtonObjects) {
for (SDLSoftButtonState *state in object.states) {
if ([state.name isEqualToString:object.currentState.name]) { continue; }
- if (self.fileManager != nil && [self.fileManager fileNeedsUpload:state.artwork] && self.softButtonCapabilities.imageSupported.boolValue) {
+ if ([self.fileManager fileNeedsUpload:state.artwork]) {
[otherStatesToBeUploaded addObject:state.artwork];
}
}
@@ -233,7 +233,7 @@ NS_ASSUME_NONNULL_BEGIN
for (SDLSoftButtonObject *button in self.softButtonObjects) {
for (SDLSoftButtonState *state in button.states) {
SDLArtwork *artwork = state.artwork;
- if (self.fileManager != nil && ![self.fileManager fileNeedsUpload:artwork] && self.softButtonCapabilities.imageSupported.boolValue) { continue; }
+ if (![self.fileManager fileNeedsUpload:artwork]) { continue; }
return NO;
}
}
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
index af5f443a7..3e74499f5 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
@@ -466,6 +466,68 @@ describe(@"uploading / deleting single files with the file manager", ^{
expect(testFileManager.pendingTransactions.count).to(equal(1));
});
});
+
+ describe(@"checking if files and artworks needs upload", ^{
+ __block UIImage *testUIImage = nil;
+ __block NSString *expectedArtworkName = nil;
+ __block SDLArtwork *artwork = nil;
+
+ context(@"when artwork is nil", ^{
+ it(@"should not allow file to be uploaded", ^{
+ expect(artwork).to(beNil());
+ BOOL testFileNeedsUpload = [testFileManager fileNeedsUpload:artwork];
+ expect(testFileNeedsUpload).to(beFalse());
+ });
+ });
+
+ context(@"when artwork is static", ^{
+ it(@"should not allow file to be uploaded", ^{
+ artwork = [[SDLArtwork alloc] initWithStaticIcon:SDLStaticIconNameKey];
+
+ BOOL testFileNeedsUpload = [testFileManager fileNeedsUpload:artwork];
+ expect(testFileNeedsUpload).to(beFalse());
+ });
+ });
+
+ context(@"when artwork is dynamic", ^{
+ beforeEach(^{
+ expectedArtworkName = testInitialFileNames.firstObject;
+
+ artwork = [SDLArtwork artworkWithImage:testUIImage name:expectedArtworkName asImageFormat:SDLArtworkImageFormatPNG];
+ });
+
+ context(@"when uploading artwork for the first time", ^{
+ it(@"should allow file to be uploaded", ^{
+ BOOL testFileNeedsUpload = [testFileManager fileNeedsUpload:artwork];
+ expect(testFileNeedsUpload).to(beTrue());
+ });
+ });
+
+ context(@"when artwork is previously uploaded", ^{
+ beforeEach(^{
+ testUIImage = [FileManagerSpecHelper imagesForCount:1].firstObject;
+
+ testFileManager.uploadedEphemeralFileNames = [NSMutableSet setWithArray:testInitialFileNames];
+ testFileManager.mutableRemoteFileNames = [NSMutableSet setWithArray:testInitialFileNames];
+ [testFileManager.stateMachine setToState:SDLFileManagerStateReady fromOldState:SDLFileManagerStateShutdown callEnterTransition:NO];
+ });
+
+ it(@"should not allow file to be uploaded when overwrite is set to false", ^{
+ artwork.overwrite = NO;
+
+ BOOL testFileNeedsUpload = [testFileManager fileNeedsUpload:artwork];
+ expect(testFileNeedsUpload).to(beFalse());
+ });
+
+ it(@"should not allow file to be uploaded when overwrite is set to true", ^{
+ artwork.overwrite = YES;
+
+ BOOL testFileNeedsUpload = [testFileManager fileNeedsUpload:artwork];
+ expect(testFileNeedsUpload).to(beTrue());
+ });
+ });
+ });
+ });
});
describe(@"uploading/deleting multiple files in the file manager", ^{