|
| 1 | +// |
| 2 | +// CollaboraTestCase.swift |
| 3 | +// NextcloudTests |
| 4 | +// |
| 5 | +// Created by A200073704 on 06/05/23. |
| 6 | +// Copyright © 2023 Marino Faggiana. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +@testable import Nextcloud |
| 10 | +import XCTest |
| 11 | +import NextcloudKit |
| 12 | + |
| 13 | +class CollaboraTestCase: XCTestCase { |
| 14 | + |
| 15 | + |
| 16 | + override func setUpWithError() throws { |
| 17 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 18 | + } |
| 19 | + |
| 20 | + override func tearDownWithError() throws { |
| 21 | + // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 22 | + } |
| 23 | + |
| 24 | + func testCollaboraDocumentIsPresent() { |
| 25 | + |
| 26 | + var viewForDocument: NCMenuAction? |
| 27 | + |
| 28 | + if let image = UIImage(named: "create_file_document") { |
| 29 | + viewForDocument = NCMenuAction(title: NSLocalizedString("_create_new_document_", comment: ""), icon: image, action: { _ in |
| 30 | + guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() as? UINavigationController else { |
| 31 | + return |
| 32 | + } |
| 33 | + |
| 34 | + let viewController = navigationController.topViewController as? NCCreateFormUploadDocuments |
| 35 | + viewController?.titleForm = NSLocalizedString("_create_new_document_", comment: "") |
| 36 | + }) |
| 37 | + } |
| 38 | + |
| 39 | + XCTAssertNotNil(viewForDocument) |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + func testCollaboraPresentationIsPresent() { |
| 44 | + |
| 45 | + var viewForPresentation: NCMenuAction? |
| 46 | + |
| 47 | + if let image = UIImage(named: "create_file_ppt") { |
| 48 | + viewForPresentation = NCMenuAction(title: NSLocalizedString("_create_new_presentation_", comment: ""), icon: image, action: { _ in |
| 49 | + guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() as? UINavigationController else { |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + let viewController = navigationController.topViewController as? NCCreateFormUploadDocuments |
| 54 | + viewController?.titleForm = NSLocalizedString("_create_new_presentation_", comment: "") |
| 55 | + }) |
| 56 | + } |
| 57 | + |
| 58 | + XCTAssertNotNil(viewForPresentation) |
| 59 | + |
| 60 | + } |
| 61 | + |
| 62 | + func testCollaboraSpreadsheetIsPresent() { |
| 63 | + |
| 64 | + var viewForSpreadsheet: NCMenuAction? |
| 65 | + |
| 66 | + if let image = UIImage(named: "create_file_xls") { |
| 67 | + viewForSpreadsheet = NCMenuAction(title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), icon: image, action: { _ in |
| 68 | + guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() as? UINavigationController else { |
| 69 | + return |
| 70 | + } |
| 71 | + |
| 72 | + let viewController = navigationController.topViewController as? NCCreateFormUploadDocuments |
| 73 | + viewController?.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "") |
| 74 | + }) |
| 75 | + } |
| 76 | + |
| 77 | + XCTAssertNotNil(viewForSpreadsheet) |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + func testTextDocumentIsPresent() { |
| 82 | + |
| 83 | + var textMenu: NCMenuAction? |
| 84 | + |
| 85 | + if let image = UIImage(named: "file_txt_menu") { |
| 86 | + textMenu = NCMenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""), icon: image, action: { _ in |
| 87 | + guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() as? UINavigationController else { |
| 88 | + return |
| 89 | + } |
| 90 | + |
| 91 | + let viewController = navigationController.topViewController as? NCCreateFormUploadDocuments |
| 92 | + viewController?.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "") |
| 93 | + }) |
| 94 | + } |
| 95 | + |
| 96 | + XCTAssertNotNil(textMenu) |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + func testTextDocumentAction() { |
| 101 | + |
| 102 | + let text = NCGlobal.shared.actionTextDocument |
| 103 | + XCTAssertNotNil(text, "Text Editor Should be opened") |
| 104 | + } |
| 105 | + |
| 106 | + func testTextFieldIsPresent() { |
| 107 | + |
| 108 | + let storyboard = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil) |
| 109 | + guard let viewController = storyboard.instantiateInitialViewController() as? NCCreateFormUploadDocuments else { |
| 110 | + return |
| 111 | + } |
| 112 | + |
| 113 | + // Verify that a text field is present in the view controller |
| 114 | + let textFields = viewController.view.subviews.filter { $0 is UITextField } |
| 115 | + XCTAssertFalse(textFields.isEmpty, "No text field found in NCCreateFormUploadDocuments") |
| 116 | + } |
| 117 | + |
| 118 | + func testSavePathFolder() { |
| 119 | + |
| 120 | + let viewController = NCCreateFormUploadDocuments() |
| 121 | + |
| 122 | + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor |
| 123 | + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow |
| 124 | + |
| 125 | + var row : XLFormRowDescriptor |
| 126 | + |
| 127 | + // the section with the title "Folder Destination" |
| 128 | + |
| 129 | + row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: "kNMCFolderCustomCellType", title: "") |
| 130 | + row.action.formSelector = #selector(viewController.changeDestinationFolder(_:)) |
| 131 | + |
| 132 | + // Verify that section was found |
| 133 | + XCTAssertNotNil(row, "Expected save path section to exist in form.") |
| 134 | + |
| 135 | + } |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +} |
0 commit comments