Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
CB3666201AF7550816B5CD6A /* NCContextMenuComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */; };
AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; };
B543154C2DA690B700981E7E /* NCNotificationText.swift in Sources */ = {isa = PBXBuildFile; fileRef = B543154B2DA690B700981E7E /* NCNotificationText.swift */; };
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
F31165022F9674A1009A1E37 /* AppIcon.icon in Resources */ = {isa = PBXBuildFile; fileRef = F31165012F9674A1009A1E37 /* AppIcon.icon */; };
Expand Down Expand Up @@ -1263,6 +1267,8 @@
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
B4C7A5B36D1ED178FB6B76CB /* NCContextMenuPlayerTracks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuPlayerTracks.swift; sourceTree = "<group>"; };
BB7697C94BA14450A0867940 /* NCContextMenuProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuProfile.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B543154B2DA690B700981E7E /* NCNotificationText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCNotificationText.swift; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2087,6 +2093,8 @@
children = (
F34BDB3B2F574A58007A222C /* BidiSafeFilenameTests.swift */,
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
B543154B2DA690B700981E7E /* NCNotificationText.swift */,
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
);
path = NextcloudUnitTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -4220,6 +4228,8 @@
F34BDB3C2F574A58007A222C /* BidiSafeFilenameTests.swift in Sources */,
F372087D2BAB4C0F006B5430 /* TestConstants.swift in Sources */,
F78E2D6C29AF02DB0024D4F3 /* Database.swift in Sources */,
B543154C2DA690B700981E7E /* NCNotificationText.swift in Sources */,
F7817CFE29801A3500FFBC65 /* Data+Extension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
85 changes: 85 additions & 0 deletions Tests/NextcloudUnitTests/NCNotificationText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// NCNotificationText.swift
// NextcloudUnitTests
//
// Created by Amrut Waghmare on 18/10/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import NextcloudKit

class NCNotificationText: XCTestCase {
var viewController : NCNotification!

override func setUpWithError() throws {
// Step 1. Create an instance of UIStoryboard
let storyboard = UIStoryboard(name: "NCNotification", bundle: nil)
// Step 2. Instantiate UIViewController with Storyboard ID
viewController = storyboard.instantiateViewController(withIdentifier: "NCNotification.storyboard") as? NCNotification

// Step 3. Make the viewDidLoad() execute.
viewController.loadViewIfNeeded()
}

override func tearDownWithError() throws {
viewController = nil
}

//Test that a cell with the correct reuse identifier is dequeued
func testTableViewCellDequeue() {
let notification = NKNotifications()
viewController.notifications = [notification]
let tableView = UITableView()
tableView.register(NCNotificationCell.self, forCellReuseIdentifier: "Cell")
let indexPath = IndexPath(row: 0, section: 0)
let cell = viewController.tableView(tableView, cellForRowAt: indexPath) as? NCNotificationCell
XCTAssertNotNil(cell)
XCTAssertEqual(cell?.reuseIdentifier, "Cell")
}

//Test that the cell's icon is set image
func testTableViewCellIcon() {
let notification = NKNotifications()
viewController.notifications = [notification]
let tableView = UITableView()
tableView.register(NCNotificationCell.self, forCellReuseIdentifier: "Cell")
let indexPath = IndexPath(row: 0, section: 0)
let cell = viewController.tableView(tableView, cellForRowAt: indexPath) as? NCNotificationCell
XCTAssertNotNil(cell?.icon.image)
}

//Test that the cell's primary and secondary buttons are set up correctly
func testTableViewCellButtons() {
let notification = NKNotifications()
notification.actions = Data("[{\"label\":\"OK\",\"primary\":true},{\"label\":\"Cancel\",\"primary\":false}]".utf8)
viewController.notifications = [notification]
let tableView = UITableView()
tableView.register(NCNotificationCell.self, forCellReuseIdentifier: "Cell")
let indexPath = IndexPath(row: 0, section: 0)
let cell = viewController.tableView(tableView, cellForRowAt: indexPath) as? NCNotificationCell
XCTAssertEqual(cell?.primary.title(for: .normal), "OK")
XCTAssertEqual(cell?.secondary.title(for: .normal), "Cancel")
}

//Test that the cell's date label is set correctly
func testTableViewCellDate() {
let notification = NKNotifications()
notification.date = NSDate()
viewController.notifications = [notification]
let tableView = UITableView()
tableView.register(NCNotificationCell.self, forCellReuseIdentifier: "Cell")
let indexPath = IndexPath(row: 0, section: 0)
let cell = viewController.tableView(tableView, cellForRowAt: indexPath) as? NCNotificationCell
XCTAssertEqual(cell?.date.text, "less than a minute ago")
}

//Test with a color that is image not nil
func testImageNotNil() {
let color = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0)
let image = UIImage().imageColor(color)
XCTAssertNotNil(image, "Image should not be nil.")

}
}
19 changes: 19 additions & 0 deletions iOSClient/Notification/NCNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate {
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// let notification = notifications[indexPath.row]

let notification = notifications[indexPath.row]

if notification.app == "files_sharing" {
NCActionCenter.shared.viewerFile(account: session.account, fileId: notification.objectId, viewController: self)
} else {
NCApplicationHandle().didSelectNotification(notification, viewController: self)
}
guard let notification = NCApplicationHandle().didSelectNotification(notifications[indexPath.row], viewController: self) else { return }

do {
if let subjectRichParameters = notification.subjectRichParameters,
let json = try JSONSerialization.jsonObject(with: subjectRichParameters, options: .mutableContainers) as? [String: Any],
Expand Down Expand Up @@ -322,6 +331,10 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate {
}
}

func tapMore(with notification: NKNotifications, sender: Any?) {
toggleMenu(notification: notification, sender: sender)
}

// MARK: - Load notification networking

@MainActor
Expand Down Expand Up @@ -400,9 +413,15 @@ class NCNotificationCell: UITableViewCell {
else { return }
delegate?.tapAction(with: notification, label: label, sender: sender)
}

@IBAction func touchUpInsideMore(_ sender: Any) {
guard let notification = notification else { return }
delegate?.tapMore(with: notification, sender: sender)
}
}

protocol NCNotificationCellDelegate: AnyObject {
func tapRemove(with notification: NKNotifications, sender: Any?)
func tapAction(with notification: NKNotifications, label: String, sender: Any?)
func tapMore(with notification: NKNotifications, sender: Any?)
}
Loading