Skip to content

Commit c270358

Browse files
committed
update
1 parent 5b3d30f commit c270358

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

Sources/sharelink-for-swiftui/uikit/TransportableItem.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// TransportableItem.swift
33
//
4-
// Created by Igor Shel on 29.10.2023.
4+
// Created by Igor Shelopaev on 29.10.2023.
55

66
#if canImport(UIKit)
77
import UIKit
@@ -22,6 +22,21 @@ final class TransportableItem<T: Transportable>: NSObject, UIActivityItemSource
2222
/// An optional icon for the item.
2323
private let icon: UIImage?
2424

25+
/// Provides a getter for the item to be shared.
26+
var getItem: T {
27+
return item
28+
}
29+
30+
/// Provides a getter for the title.
31+
var getTitle: String? {
32+
return title
33+
}
34+
35+
/// Provides a getter for the icon.
36+
var getIcon: UIImage? {
37+
return icon
38+
}
39+
2540
/// Initializes a new transportable item with optional title and icon.
2641
///
2742
/// - Parameters:

Tests/sharelinkTests/ShareLinkButtonTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ShareLinkButtonTests.swift
33
//
44
//
5-
// Created by Igor on 03.07.24.
5+
// Created by Igor Shelopaev on 03.07.24.
66
//
77

88
import XCTest
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// ShareLinkViewTests.swift
3+
//
4+
//
5+
// Created by Igor on 19.08.24.
6+
//
7+
8+
import XCTest
9+
@testable import sharelink_for_swiftui
10+
11+
class ShareLinkViewTests: XCTestCase {
12+
13+
/// A sample string to share.
14+
let sampleString = "This is a sample string to share."
15+
16+
/// A sample URL to share.
17+
let sampleURL = URL(string: "https://www.apple.com")!
18+
19+
func testInitializationWithData() {
20+
let data = [sampleURL]
21+
let shareLinkView = ShareLinkView(data: data)
22+
XCTAssertEqual(shareLinkView.data.count, 1)
23+
}
24+
25+
func testInitializationWithApplicationActivities() {
26+
let data = [sampleString]
27+
let activity = UIActivity()
28+
let shareLinkView = ShareLinkView(data: data, applicationActivities: [activity])
29+
XCTAssertEqual(shareLinkView.applicationActivities?.count, 1)
30+
}
31+
32+
func testInitializationWithExcludedActivityTypes() {
33+
let data = [sampleString]
34+
let excludedTypes: [UIActivity.ActivityType] = [.postToFacebook, .postToTwitter]
35+
let shareLinkView = ShareLinkView(data: data, excludedActivityTypes: excludedTypes)
36+
XCTAssertEqual(shareLinkView.excludedActivityTypes?.count, 2)
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import XCTest
2+
import UIKit
3+
import LinkPresentation
4+
@testable import sharelink_for_swiftui
5+
6+
final class TransportableItemTests: XCTestCase {
7+
8+
// Sample data for testing
9+
let sampleString = "This is a sample string to share."
10+
let sampleURL = URL(string: "https://www.apple.com")!
11+
12+
func testInitializationWithTitleAndIcon() {
13+
let icon = UIImage(systemName: "star")
14+
let title = "Example Title"
15+
let transportableItem = TransportableItem(item: sampleString, icon: icon, title: title)
16+
17+
XCTAssertEqual(transportableItem.getTitle, title)
18+
XCTAssertEqual(transportableItem.getIcon, icon)
19+
}
20+
21+
func testInitializationWithoutTitleAndIcon() {
22+
let transportableItem = TransportableItem(item: sampleURL)
23+
24+
XCTAssertNil(transportableItem.getTitle)
25+
XCTAssertNil(transportableItem.getIcon)
26+
}
27+
}

0 commit comments

Comments
 (0)