From 35dca45c60638bb6953f234e831bf3fad95bbfeb Mon Sep 17 00:00:00 2001 From: Mathijs Bernson Date: Fri, 23 Aug 2019 13:23:30 +0200 Subject: [PATCH] Add sharing subject test --- NetNewsWire.xcodeproj/project.pbxproj | 4 ++ Tests/NetNewsWireTests/SharingTests.swift | 67 +++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Tests/NetNewsWireTests/SharingTests.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 6e0218453..05a7e8764 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -322,6 +322,7 @@ D5F4EDB5200744A700B9E363 /* ScriptingObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F4EDB4200744A700B9E363 /* ScriptingObject.swift */; }; D5F4EDB720074D6500B9E363 /* Feed+Scriptability.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F4EDB620074D6500B9E363 /* Feed+Scriptability.swift */; }; D5F4EDB920074D7C00B9E363 /* Folder+Scriptability.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F4EDB820074D7C00B9E363 /* Folder+Scriptability.swift */; }; + DD82AB0A231003F6002269DF /* SharingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD82AB09231003F6002269DF /* SharingTests.swift */; }; DF999FF722B5AEFA0064B687 /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF999FF622B5AEFA0064B687 /* SafariView.swift */; }; /* End PBXBuildFile section */ @@ -942,6 +943,7 @@ D5F4EDB4200744A700B9E363 /* ScriptingObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptingObject.swift; sourceTree = ""; }; D5F4EDB620074D6500B9E363 /* Feed+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Feed+Scriptability.swift"; sourceTree = ""; }; D5F4EDB820074D7C00B9E363 /* Folder+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Folder+Scriptability.swift"; sourceTree = ""; }; + DD82AB09231003F6002269DF /* SharingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingTests.swift; sourceTree = ""; }; DF999FF622B5AEFA0064B687 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1792,6 +1794,7 @@ children = ( 84F9EAD0213660A100CF2DE4 /* ScriptingTests */, 84F9EAE3213660A100CF2DE4 /* NetNewsWireTests.swift */, + DD82AB09231003F6002269DF /* SharingTests.swift */, 84F9EAE4213660A100CF2DE4 /* Info.plist */, ); path = NetNewsWireTests; @@ -2582,6 +2585,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DD82AB0A231003F6002269DF /* SharingTests.swift in Sources */, 84F9EAEB213660A100CF2DE4 /* testIterativeCreateAndDeleteFeed.applescript in Sources */, 84F9EAF4213660A100CF2DE4 /* testGenericScript.applescript in Sources */, 84F9EAE6213660A100CF2DE4 /* ScriptingTests.swift in Sources */, diff --git a/Tests/NetNewsWireTests/SharingTests.swift b/Tests/NetNewsWireTests/SharingTests.swift new file mode 100644 index 000000000..4ce4455f9 --- /dev/null +++ b/Tests/NetNewsWireTests/SharingTests.swift @@ -0,0 +1,67 @@ +// +// SharingTests.swift +// NetNewsWireTests +// +// Created by Mathijs Bernson on 23/08/2019. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import XCTest +@testable import NetNewsWire +import Articles + +class SharingTests: XCTestCase { + + func testSharingSubject() { + let sharingServiceDelegate = SharingServiceDelegate(nil) + let sharingService = NSSharingService(title: "Chirpy", image: NSImage(size: NSSize.zero), alternateImage: nil, handler: {}) + + sharingService.delegate = sharingServiceDelegate + sharingService.perform(withItems: [ + ArticlePasteboardWriter(article: article(titled: "Immunization")), + ]) + + XCTAssertEqual("Immunization", sharingService.subject) + } + + func testSharingSubjectMultipleArticles() { + let sharingServiceDelegate = SharingServiceDelegate(nil) + let sharingService = NSSharingService(title: "Chirpy", image: NSImage(size: NSSize.zero), alternateImage: nil, handler: {}) + + sharingService.delegate = sharingServiceDelegate + sharingService.perform(withItems: [ + ArticlePasteboardWriter(article: article(titled: "NetNewsWire Status: Almost Beta")), + ArticlePasteboardWriter(article: article(titled: "No Algorithms Follow-Up")), + ]) + + XCTAssertEqual("NetNewsWire Status: Almost Beta, No Algorithms Follow-Up", sharingService.subject) + } + + private func article(titled title: String) -> Article { + let articleId = randomId() + return Article( + accountID: randomId(), + articleID: articleId, + feedID: randomId(), + uniqueID: randomId(), + title: title, + contentHTML: nil, + contentText: nil, + url: nil, + externalURL: nil, + summary: nil, + imageURL: nil, + bannerImageURL: nil, + datePublished: nil, + dateModified: nil, + authors: nil, + attachments: nil, + status: ArticleStatus(articleID: articleId, read: true, dateArrived: Date()) + ) + } + + private func randomId() -> String { + return UUID().uuidString + } + +}