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
8 changes: 8 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.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 */; };
Expand Down Expand Up @@ -1329,6 +1332,8 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.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 @@ -2117,6 +2122,8 @@
isa = PBXGroup;
children = (
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
B543154B2DA690B700981E7E /* NCNotificationText.swift */,
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
);
path = NextcloudUnitTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -4143,6 +4150,7 @@
AA52EB472D42AC9E0089C348 /* Placeholder.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.")

}
}
Loading