Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #48 from bkobilansky/sharing-provider-tests
Browse files Browse the repository at this point in the history
Sharing provider tests
  • Loading branch information
hebertialmeida committed Jan 26, 2016
2 parents b877cca + 4439fea commit ec8e478
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 = "<group>"; };
CA10C1351C572A4B0049165D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CAF233281C57E1F400CB930C /* SharingProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingProviderTests.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -122,6 +124,7 @@
isa = PBXGroup;
children = (
CA10C1331C572A4B0049165D /* FolioReaderTests.swift */,
CAF233281C57E1F400CB930C /* SharingProviderTests.swift */,
CA10C1351C572A4B0049165D /* Info.plist */,
);
path = FolioReaderTests;
Expand Down Expand Up @@ -367,6 +370,7 @@
buildActionMask = 2147483647;
files = (
CA10C1341C572A4B0049165D /* FolioReaderTests.swift in Sources */,
CAF233291C57E1F400CB930C /* SharingProviderTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
59 changes: 59 additions & 0 deletions Example/FolioReaderTests/SharingProviderTests.swift
Original file line number Diff line number Diff line change
@@ -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: "<html><body>foo</body></html>")
}

func providerWithoutHTML() -> FolioReaderSharingProvider {
return FolioReaderSharingProvider(subject: "a subject", text: "some text", html: nil)
}
}

28 changes: 11 additions & 17 deletions Source/FolioReaderSharingProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit ec8e478

Please sign in to comment.