diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index e4dc1cb50..3d0b535e6 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ CA10C1341C572A4B0049165D /* FolioReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA10C1331C572A4B0049165D /* FolioReaderTests.swift */; }; CA61603F1C572C4C00ACD034 /* The Adventures Of Sherlock Holmes - Adventure I.epub in Resources */ = {isa = PBXBuildFile; fileRef = 6E5C9B081C403942008F6FD9 /* The Adventures Of Sherlock Holmes - Adventure I.epub */; }; CA6160401C572C4C00ACD034 /* The Silver Chair.epub in Resources */ = {isa = PBXBuildFile; fileRef = 6E5C9B031C4037B7008F6FD9 /* The Silver Chair.epub */; }; + CAF233291C57E1F400CB930C /* SharingProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF233281C57E1F400CB930C /* SharingProviderTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -48,6 +49,7 @@ CA10C1311C572A4B0049165D /* FolioReaderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FolioReaderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; CA10C1331C572A4B0049165D /* FolioReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolioReaderTests.swift; sourceTree = ""; }; CA10C1351C572A4B0049165D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CAF233281C57E1F400CB930C /* SharingProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingProviderTests.swift; sourceTree = ""; }; CF0BE619497BB80F68421DFD /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; D92D71D4A92CE71CA9A6CF5A /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; DC3BF5678D61F199F4ECC2BD /* Pods-FolioReaderTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FolioReaderTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FolioReaderTests/Pods-FolioReaderTests.debug.xcconfig"; sourceTree = ""; }; @@ -122,6 +124,7 @@ isa = PBXGroup; children = ( CA10C1331C572A4B0049165D /* FolioReaderTests.swift */, + CAF233281C57E1F400CB930C /* SharingProviderTests.swift */, CA10C1351C572A4B0049165D /* Info.plist */, ); path = FolioReaderTests; @@ -367,6 +370,7 @@ buildActionMask = 2147483647; files = ( CA10C1341C572A4B0049165D /* FolioReaderTests.swift in Sources */, + CAF233291C57E1F400CB930C /* SharingProviderTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/FolioReaderTests/SharingProviderTests.swift b/Example/FolioReaderTests/SharingProviderTests.swift new file mode 100644 index 000000000..c4441647b --- /dev/null +++ b/Example/FolioReaderTests/SharingProviderTests.swift @@ -0,0 +1,59 @@ +// +// SharingProviderTests.swift +// Example +// +// Created by Brandon Kobilansky on 1/26/16. +// Copyright © 2016 FolioReader. All rights reserved. +// + +@testable import FolioReaderKit + +import Quick +import Nimble + +class SharingProviderTests: QuickSpec { + override func spec() { + var subject: FolioReaderSharingProvider! + + context("when sharing a document") { + let activityViewController = UIActivityViewController(activityItems: [], applicationActivities: nil) + + it("sets the subject field") { + subject = self.providerWithHTML() + let subjectForActivityType = subject.activityViewController(activityViewController, subjectForActivityType: nil) + expect(subjectForActivityType).to(equal(subject.subject)) + } + + context("without HTML") { + beforeEach { + subject = self.providerWithoutHTML() + } + + it("returns text for a mail activity") { + let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityTypeMail) as? String + expect(itemForActivityType).to(equal(subject.text)) + } + } + + context("with HTML") { + beforeEach { + subject = self.providerWithHTML() + } + + it("returns HTML for a mail activity") { + let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityTypeMail) as? String + expect(itemForActivityType).to(equal(subject.html)) + } + } + } + } + + func providerWithHTML() -> FolioReaderSharingProvider { + return FolioReaderSharingProvider(subject: "a subject", text: "some text", html: "foo") + } + + func providerWithoutHTML() -> FolioReaderSharingProvider { + return FolioReaderSharingProvider(subject: "a subject", text: "some text", html: nil) + } +} + diff --git a/Source/FolioReaderSharingProvider.swift b/Source/FolioReaderSharingProvider.swift index 21797b7df..b5344cf09 100644 --- a/Source/FolioReaderSharingProvider.swift +++ b/Source/FolioReaderSharingProvider.swift @@ -9,34 +9,28 @@ import UIKit class FolioReaderSharingProvider: UIActivityItemProvider { - - var subject: String! - var text: String! + + var subject: String + var text: String var html: String? - + init(subject: String, text: String, html: String?) { self.subject = subject self.text = text - if let ht = html { - self.html = ht - } + self.html = html + super.init(placeholderItem: "") } - + override func activityViewController(activityViewController: UIActivityViewController, subjectForActivityType activityType: String?) -> String { return subject } - + override func activityViewController(activityViewController: UIActivityViewController, itemForActivityType activityType: String) -> AnyObject? { - - if activityType == UIActivityTypeMail { - if let html = html { - return html - } else { - return text - } + if let html = html where activityType == UIActivityTypeMail { + return html } - + return text } }