Initial commit
45
AntidoteTests/AntidoteTests-Bridging-Header.h
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import <objcTox/OCTCall.h>
|
||||
#import <objcTox/OCTChat.h>
|
||||
#import <objcTox/OCTDefaultFileStorage.h>
|
||||
#import <objcTox/OCTFriend.h>
|
||||
#import <objcTox/OCTFriendRequest.h>
|
||||
#import <objcTox/OCTManager.h>
|
||||
#import <objcTox/OCTManagerFactory.h>
|
||||
#import <objcTox/OCTManagerConfiguration.h>
|
||||
#import <objcTox/OCTManagerConstants.h>
|
||||
#import <objcTox/OCTMessageAbstract.h>
|
||||
#import <objcTox/OCTMessageCall.h>
|
||||
#import <objcTox/OCTMessageFile.h>
|
||||
#import <objcTox/OCTMessageText.h>
|
||||
#import <objcTox/OCTSubmanagerBootstrap.h>
|
||||
#import <objcTox/OCTSubmanagerCalls.h>
|
||||
#import <objcTox/OCTSubmanagerCallsDelegate.h>
|
||||
#import <objcTox/OCTSubmanagerChats.h>
|
||||
#import <objcTox/OCTSubmanagerFiles.h>
|
||||
#import <objcTox/OCTSubmanagerFilesProgressSubscriber.h>
|
||||
#import <objcTox/OCTSubmanagerFriends.h>
|
||||
#import <objcTox/OCTSubmanagerObjects.h>
|
||||
#import <objcTox/OCTSubmanagerUser.h>
|
||||
#import <objcTox/OCTTox.h>
|
||||
#import <objcTox/OCTToxEncryptSave.h>
|
||||
#import <objcTox/OCTToxConstants.h>
|
||||
#import <objcTox/OCTView.h>
|
||||
|
||||
#undef LOG_INFO
|
||||
#undef LOG_DEBUG
|
||||
#import "DDLog.h"
|
||||
#import "DDASLLogger.h"
|
||||
#import "DDTTYLogger.h"
|
||||
|
||||
#import <LNNotificationsUI/LNNotificationsUI.h>
|
||||
#import <SDCAlertView/SDCAlertController.h>
|
||||
#import <UITextView+Placeholder/UITextView+Placeholder.h>
|
||||
#import <JGProgressHUD/JGProgressHUD.h>
|
||||
|
||||
#import "ExceptionHandling.h"
|
||||
|
||||
#import "FBSnapshotTestCase.h"
|
15
AntidoteTests/CellSnapshotTest.swift
Normal file
@ -0,0 +1,15 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class CellSnapshotTest: SnapshotBaseTest {
|
||||
func updateCellLayout(_ cell: UITableViewCell) {
|
||||
let size = cell.systemLayoutSizeFitting(CGSize(width: 320, height: 1000))
|
||||
cell.frame = CGRect(x: 0, y: 0, width: 320, height: size.height)
|
||||
|
||||
cell.setNeedsLayout()
|
||||
cell.layoutIfNeeded()
|
||||
}
|
||||
}
|
37
AntidoteTests/ChatIncomingCallCellSnapshotTest.swift
Normal file
@ -0,0 +1,37 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatIncomingCallCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testAnsweredCall() {
|
||||
let model = ChatIncomingCallCellModel()
|
||||
model.callDuration = 137
|
||||
model.answered = true
|
||||
|
||||
let cell = ChatIncomingCallCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testNonAnsweredCall() {
|
||||
let model = ChatIncomingCallCellModel()
|
||||
model.callDuration = 137
|
||||
model.answered = false
|
||||
|
||||
let cell = ChatIncomingCallCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
109
AntidoteTests/ChatIncomingFileCellSnapshotTest.swift
Normal file
@ -0,0 +1,109 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
import MobileCoreServices
|
||||
|
||||
class ChatIncomingFileCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testWaitingState() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .waitingConfirmation
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testLoading() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .loading
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testPaused() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .paused
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testCancelled() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .cancelled
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testDone() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .done
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testDoneWithImage() {
|
||||
let model = ChatIncomingFileCellModel()
|
||||
model.state = .done
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let cell = ChatIncomingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.setButtonImage(image)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
67
AntidoteTests/ChatIncomingTextCellSnapshotTest.swift
Normal file
@ -0,0 +1,67 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatIncomingTextCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testSmallMessage() {
|
||||
let model = ChatBaseTextCellModel()
|
||||
model.message = "Hi"
|
||||
|
||||
let cell = ChatIncomingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testMediumMessage() {
|
||||
let model = ChatBaseTextCellModel()
|
||||
model.message = "Some nice medium message"
|
||||
|
||||
let cell = ChatIncomingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testHugeMessage() {
|
||||
let model = ChatBaseTextCellModel()
|
||||
model.message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "
|
||||
|
||||
let cell = ChatIncomingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
// Broken on Travic CI.
|
||||
// func testWithLink() {
|
||||
// let model = ChatBaseTextCellModel()
|
||||
// model.message = "Lorem ipsum dolor sit amet, https://tox.chat consectetur adipiscing elit, +1234567890"
|
||||
|
||||
// let cell = ChatIncomingTextCell()
|
||||
// cell.setupWithTheme(theme, model: model)
|
||||
|
||||
// updateCellLayout(cell)
|
||||
|
||||
// let expectation = self.expectation(description: "link rendering expectation")
|
||||
|
||||
// let delayTime = DispatchTime.now() + Double(Int64(0.5 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
||||
// DispatchQueue.main.asyncAfter(deadline: delayTime) { [weak self] in
|
||||
// self?.verifyView(cell)
|
||||
// expectation.fulfill()
|
||||
// }
|
||||
|
||||
// waitForExpectations(timeout: 1.0, handler: nil)
|
||||
// }
|
||||
}
|
62
AntidoteTests/ChatListCellSnapshotTest.swift
Normal file
@ -0,0 +1,62 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatListCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testDefault() {
|
||||
let model = ChatListCellModel()
|
||||
model.avatar = image
|
||||
model.nickname = "dvor"
|
||||
model.message = "Hi! This is some random message."
|
||||
model.dateText = "Yesterday"
|
||||
model.status = .offline
|
||||
model.isUnread = false
|
||||
|
||||
let cell = ChatListCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testLongMessage() {
|
||||
let model = ChatListCellModel()
|
||||
model.avatar = image
|
||||
model.nickname = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
||||
model.message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "
|
||||
model.dateText = "Yesterday"
|
||||
model.status = .online
|
||||
model.isUnread = false
|
||||
|
||||
let cell = ChatListCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testUnread() {
|
||||
let model = ChatListCellModel()
|
||||
model.avatar = image
|
||||
model.nickname = "dvor"
|
||||
model.message = "Hi! This is some random message."
|
||||
model.dateText = "10:37"
|
||||
model.status = .away
|
||||
model.isUnread = true
|
||||
|
||||
let cell = ChatListCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
||||
|
36
AntidoteTests/ChatMovableDateCellSnapshotTest.swift
Normal file
@ -0,0 +1,36 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatMovableDateCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testDefault() {
|
||||
let model = ChatMovableDateCellModel()
|
||||
model.dateString = "03:13"
|
||||
|
||||
let cell = ChatMovableDateCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testPanned() {
|
||||
let model = ChatMovableDateCellModel()
|
||||
model.dateString = "03:13"
|
||||
|
||||
let cell = ChatMovableDateCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
cell.movableOffset = -200.0
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
37
AntidoteTests/ChatOutgoingCallCellSnapshotTest.swift
Normal file
@ -0,0 +1,37 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatOutgoingCallCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testAnsweredCall() {
|
||||
let model = ChatOutgoingCallCellModel()
|
||||
model.callDuration = 137
|
||||
model.answered = true
|
||||
|
||||
let cell = ChatOutgoingCallCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testNonAnsweredCall() {
|
||||
let model = ChatOutgoingCallCellModel()
|
||||
model.callDuration = 137
|
||||
model.answered = false
|
||||
|
||||
let cell = ChatOutgoingCallCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
179
AntidoteTests/ChatOutgoingFileCellSnapshotTest.swift
Normal file
@ -0,0 +1,179 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
import MobileCoreServices
|
||||
|
||||
class ChatOutgoingFileCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testWaitingState() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .waitingConfirmation
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testLoading() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .loading
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testPaused() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .paused
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testCancelled() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .cancelled
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testDone() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .done
|
||||
model.fileName = "file.txt"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePlainText as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testWaitingStateWithImage() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .waitingConfirmation
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.setButtonImage(image)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testLoadingWithImage() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .loading
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
cell.setButtonImage(image)
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testPausedWithImage() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .paused
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let progressObject = MockedChatProgressProtocol()
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.progressObject = progressObject
|
||||
cell.setButtonImage(image)
|
||||
|
||||
progressObject.updateProgress?(0.43)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testCancelledWithImage() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .cancelled
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.setButtonImage(image)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testDoneWithImage() {
|
||||
let model = ChatOutgoingFileCellModel()
|
||||
model.state = .done
|
||||
model.fileName = "icon.png"
|
||||
model.fileSize = "3.14 KB"
|
||||
model.fileUTI = kUTTypePNG as String
|
||||
|
||||
let cell = ChatOutgoingFileCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
cell.setButtonImage(image)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
}
|
83
AntidoteTests/ChatOutgoingTextCellSnapshotTest.swift
Normal file
@ -0,0 +1,83 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class ChatOutgoingTextCellSnapshotTest: CellSnapshotTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testSmallMessage() {
|
||||
let model = ChatOutgoingTextCellModel()
|
||||
model.message = "Hi"
|
||||
model.delivered = true
|
||||
|
||||
let cell = ChatOutgoingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testMediumMessage() {
|
||||
let model = ChatOutgoingTextCellModel()
|
||||
model.message = "Some nice medium message"
|
||||
model.delivered = true
|
||||
|
||||
let cell = ChatOutgoingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testMediumMessageUndelivered() {
|
||||
let model = ChatOutgoingTextCellModel()
|
||||
model.message = "Some nice medium message"
|
||||
model.delivered = false
|
||||
|
||||
let cell = ChatOutgoingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
func testHugeMessage() {
|
||||
let model = ChatOutgoingTextCellModel()
|
||||
model.message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "
|
||||
model.delivered = true
|
||||
|
||||
let cell = ChatOutgoingTextCell()
|
||||
cell.setupWithTheme(theme, model: model)
|
||||
|
||||
updateCellLayout(cell)
|
||||
verifyView(cell)
|
||||
}
|
||||
|
||||
// Broken on Travic CI.
|
||||
// func testWithLink() {
|
||||
// let model = ChatOutgoingTextCellModel()
|
||||
// model.message = "Lorem ipsum dolor sit amet, https://tox.chat consectetur adipiscing elit, +1234567890"
|
||||
// model.delivered = true
|
||||
|
||||
// let cell = ChatOutgoingTextCell()
|
||||
// cell.setupWithTheme(theme, model: model)
|
||||
|
||||
// updateCellLayout(cell)
|
||||
|
||||
// let expectation = self.expectation(description: "link rendering expectation")
|
||||
|
||||
// let delayTime = DispatchTime.now() + Double(Int64(0.5 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
||||
// DispatchQueue.main.asyncAfter(deadline: delayTime) { [weak self] in
|
||||
// self?.verifyView(cell)
|
||||
// expectation.fulfill()
|
||||
// }
|
||||
|
||||
// waitForExpectations(timeout: 1.0, handler: nil)
|
||||
// }
|
||||
}
|
159
AntidoteTests/FriendListDataSourceTest.swift
Normal file
@ -0,0 +1,159 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import XCTest
|
||||
|
||||
class FriendListDataSourceTest: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
// Antidote/objcTox should be refactored to protocol oriented architecture, then testing will become possible :-)
|
||||
|
||||
// func testPerformFetch() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// // calling some method requiring both requests and friends controller
|
||||
// _ = dataSource.numberOfSections()
|
||||
|
||||
// XCTAssertTrue(requests.didPerformFetch)
|
||||
// XCTAssertTrue(friends.didPerformFetch)
|
||||
// }
|
||||
|
||||
// func testReset() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// dataSource.reset()
|
||||
|
||||
// XCTAssertTrue(requests.didReset)
|
||||
// XCTAssertTrue(friends.didReset)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_NoRequests_NoFriends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 1)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_NoRequests_OneFriendSection() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[ NSObject() ]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 1)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_NoRequests_MultipleFriendSection() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [
|
||||
// [NSObject()],
|
||||
// [NSObject()],
|
||||
// [NSObject()],
|
||||
// ])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 3)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_OneRequest_NoFriends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[ NSObject() ]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 2)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_MultipleRequest_NoFriends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// ]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 2)
|
||||
// }
|
||||
|
||||
// func testNumberOfSections_MultipleRequest_MultipleFriends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// ]])
|
||||
// let friends = MockedFetchedResultsController(objects: [
|
||||
// [NSObject()],
|
||||
// [NSObject()],
|
||||
// [NSObject()],
|
||||
// ])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfSections(), 4)
|
||||
// }
|
||||
|
||||
// func testNumberOfRows_Empty() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [[]])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(0), 0)
|
||||
// }
|
||||
|
||||
// func testNumberOfRows_NoRequest_Friends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[]])
|
||||
// let friends = MockedFetchedResultsController(objects: [
|
||||
// [NSObject()],
|
||||
// [NSObject(), NSObject()],
|
||||
// [NSObject(), NSObject(), NSObject()],
|
||||
// ])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(0), 1)
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(1), 2)
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(2), 3)
|
||||
// }
|
||||
|
||||
// func testNumberOfRows_Requests_Friends() {
|
||||
// let requests = MockedFetchedResultsController(objects: [[
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// NSObject(),
|
||||
// ]])
|
||||
// let friends = MockedFetchedResultsController(objects: [
|
||||
// [NSObject()],
|
||||
// [NSObject(), NSObject()],
|
||||
// [NSObject(), NSObject(), NSObject()],
|
||||
// ])
|
||||
|
||||
// let dataSource = FriendListDataSource(requestsController: requests, friendsController: friends)
|
||||
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(0), 4)
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(1), 1)
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(2), 2)
|
||||
// XCTAssertEqual(dataSource.numberOfRowsInSection(3), 3)
|
||||
// }
|
||||
}
|
24
AntidoteTests/Info.plist
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>30</string>
|
||||
</dict>
|
||||
</plist>
|
52
AntidoteTests/KeychainManagerTests.swift
Normal file
@ -0,0 +1,52 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import XCTest
|
||||
|
||||
class KeychainManagerTests: XCTestCase {
|
||||
func testToxPassword() {
|
||||
let manager = KeychainManager()
|
||||
|
||||
manager.toxPasswordForActiveAccount = nil
|
||||
XCTAssertNil(manager.toxPasswordForActiveAccount)
|
||||
|
||||
manager.toxPasswordForActiveAccount = "password"
|
||||
XCTAssertEqual(manager.toxPasswordForActiveAccount!, "password")
|
||||
|
||||
manager.toxPasswordForActiveAccount = "another"
|
||||
XCTAssertEqual(manager.toxPasswordForActiveAccount!, "another")
|
||||
|
||||
manager.toxPasswordForActiveAccount = nil
|
||||
XCTAssertNil(manager.toxPasswordForActiveAccount)
|
||||
|
||||
manager.toxPasswordForActiveAccount = "some pass"
|
||||
XCTAssertEqual(manager.toxPasswordForActiveAccount!, "some pass")
|
||||
|
||||
manager.deleteActiveAccountData()
|
||||
XCTAssertNil(manager.toxPasswordForActiveAccount)
|
||||
}
|
||||
|
||||
func testFailedPinAttemptsNumber() {
|
||||
let manager = KeychainManager()
|
||||
|
||||
manager.failedPinAttemptsNumber = nil
|
||||
XCTAssertNil(manager.failedPinAttemptsNumber)
|
||||
|
||||
manager.failedPinAttemptsNumber = 5
|
||||
XCTAssertEqual(manager.failedPinAttemptsNumber!, 5)
|
||||
|
||||
manager.failedPinAttemptsNumber = 8
|
||||
XCTAssertEqual(manager.failedPinAttemptsNumber!, 8)
|
||||
|
||||
manager.failedPinAttemptsNumber = nil
|
||||
XCTAssertNil(manager.failedPinAttemptsNumber)
|
||||
|
||||
manager.failedPinAttemptsNumber = 3
|
||||
XCTAssertEqual(manager.failedPinAttemptsNumber!, 3)
|
||||
|
||||
manager.deleteActiveAccountData()
|
||||
XCTAssertNil(manager.failedPinAttemptsNumber)
|
||||
}
|
||||
}
|
||||
|
18
AntidoteTests/LoginChoiceViewSnapshotTest.swift
Normal file
@ -0,0 +1,18 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class LoginChoiceViewSnapshotTest: SnapshotBaseTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
recordMode = false
|
||||
}
|
||||
|
||||
func testDefault() {
|
||||
let controller = LoginChoiceController(theme: theme)
|
||||
verifyView(controller.view)
|
||||
}
|
||||
}
|
10
AntidoteTests/MockedChatProgressProtocol.swift
Normal file
@ -0,0 +1,10 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import Foundation
|
||||
|
||||
class MockedChatProgressProtocol: ChatProgressProtocol {
|
||||
var updateProgress: ((_ progress: Float) -> Void)?
|
||||
var updateEta: ((_ eta: CFTimeInterval, _ bytesPerSecond: OCTToxFileSize) -> Void)?
|
||||
}
|
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 123 KiB |
44
AntidoteTests/SnapshotBaseTest.swift
Normal file
@ -0,0 +1,44 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import XCTest
|
||||
|
||||
class SnapshotBaseTest: FBSnapshotTestCase {
|
||||
var theme: Theme!
|
||||
|
||||
var image: UIImage {
|
||||
get {
|
||||
let bundle = Bundle(for: type(of: self))
|
||||
return UIImage(named: "icon", in:bundle, compatibleWith: nil)!
|
||||
}
|
||||
}
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
let filepath = Bundle.main.path(forResource: "default-theme", ofType: "yaml")!
|
||||
let yamlString = try! NSString(contentsOfFile:filepath, encoding:String.Encoding.utf8.rawValue) as String
|
||||
|
||||
theme = try! Theme(yamlString: yamlString)
|
||||
}
|
||||
|
||||
func verifyView(_ view: UIView) {
|
||||
FBSnapshotVerifyView(view, identifier: "normal")
|
||||
|
||||
view.forceRightToLeft()
|
||||
FBSnapshotVerifyView(view, identifier: "right-to-left")
|
||||
}
|
||||
}
|
||||
|
||||
private extension UIView {
|
||||
func forceRightToLeft() {
|
||||
if #available(iOS 9.0, *) {
|
||||
semanticContentAttribute = .forceRightToLeft
|
||||
}
|
||||
|
||||
for view in subviews {
|
||||
view.forceRightToLeft()
|
||||
}
|
||||
}
|
||||
}
|
125
AntidoteTests/SwiftSupport.swift
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#if swift(>=3)
|
||||
public extension FBSnapshotTestCase {
|
||||
public func FBSnapshotVerifyView(_ view: UIView, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
FBSnapshotVerifyViewOrLayer(view, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
|
||||
}
|
||||
|
||||
public func FBSnapshotVerifyLayer(_ layer: CALayer, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
FBSnapshotVerifyViewOrLayer(layer, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
|
||||
}
|
||||
|
||||
private func FBSnapshotVerifyViewOrLayer(_ viewOrLayer: AnyObject, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
let envReferenceImageDirectory = self.getReferenceImageDirectory(withDefault: FB_REFERENCE_IMAGE_DIR)
|
||||
var error: NSError?
|
||||
var comparisonSuccess = false
|
||||
|
||||
if let envReferenceImageDirectory = envReferenceImageDirectory {
|
||||
for suffix in suffixes {
|
||||
let referenceImagesDirectory = "\(envReferenceImageDirectory)\(suffix)"
|
||||
if viewOrLayer.isKind(of: UIView.self) {
|
||||
do {
|
||||
try compareSnapshot(of: viewOrLayer as! UIView, referenceImagesDirectory: referenceImagesDirectory, identifier: identifier, tolerance: tolerance)
|
||||
comparisonSuccess = true
|
||||
} catch let error1 as NSError {
|
||||
error = error1
|
||||
comparisonSuccess = false
|
||||
}
|
||||
} else if viewOrLayer.isKind(of: CALayer.self) {
|
||||
do {
|
||||
try compareSnapshot(of: viewOrLayer as! CALayer, referenceImagesDirectory: referenceImagesDirectory, identifier: identifier, tolerance: tolerance)
|
||||
comparisonSuccess = true
|
||||
} catch let error1 as NSError {
|
||||
error = error1
|
||||
comparisonSuccess = false
|
||||
}
|
||||
} else {
|
||||
assertionFailure("Only UIView and CALayer classes can be snapshotted")
|
||||
}
|
||||
|
||||
assert(recordMode == false, message: "Test ran in record mode. Reference image is now saved. Disable record mode to perform an actual snapshot comparison!", file: file, line: line)
|
||||
|
||||
if comparisonSuccess || recordMode {
|
||||
break
|
||||
}
|
||||
|
||||
assert(comparisonSuccess, message: "Snapshot comparison failed: \(error)", file: file, line: line)
|
||||
}
|
||||
} else {
|
||||
XCTFail("Missing value for referenceImagesDirectory - Set FB_REFERENCE_IMAGE_DIR as Environment variable in your scheme.")
|
||||
}
|
||||
}
|
||||
|
||||
func assert(_ assertion: Bool, message: String, file: StaticString, line: UInt) {
|
||||
if !assertion {
|
||||
XCTFail(message, file: file, line: line)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
public extension FBSnapshotTestCase {
|
||||
public func FBSnapshotVerifyView(view: UIView, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
FBSnapshotVerifyViewOrLayer(view, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
|
||||
}
|
||||
|
||||
public func FBSnapshotVerifyLayer(layer: CALayer, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
FBSnapshotVerifyViewOrLayer(layer, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
|
||||
}
|
||||
|
||||
private func FBSnapshotVerifyViewOrLayer(viewOrLayer: AnyObject, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
|
||||
let envReferenceImageDirectory = self.getReferenceImageDirectoryWithDefault(FB_REFERENCE_IMAGE_DIR)
|
||||
var error: NSError?
|
||||
var comparisonSuccess = false
|
||||
|
||||
if let envReferenceImageDirectory = envReferenceImageDirectory {
|
||||
for suffix in suffixes {
|
||||
let referenceImagesDirectory = "\(envReferenceImageDirectory)\(suffix)"
|
||||
if viewOrLayer.isKindOfClass(UIView) {
|
||||
do {
|
||||
try compareSnapshotOfView(viewOrLayer as! UIView, referenceImagesDirectory: referenceImagesDirectory, identifier: identifier, tolerance: tolerance)
|
||||
comparisonSuccess = true
|
||||
} catch let error1 as NSError {
|
||||
error = error1
|
||||
comparisonSuccess = false
|
||||
}
|
||||
} else if viewOrLayer.isKindOfClass(CALayer) {
|
||||
do {
|
||||
try compareSnapshotOfLayer(viewOrLayer as! CALayer, referenceImagesDirectory: referenceImagesDirectory, identifier: identifier, tolerance: tolerance)
|
||||
comparisonSuccess = true
|
||||
} catch let error1 as NSError {
|
||||
error = error1
|
||||
comparisonSuccess = false
|
||||
}
|
||||
} else {
|
||||
assertionFailure("Only UIView and CALayer classes can be snapshotted")
|
||||
}
|
||||
|
||||
assert(recordMode == false, message: "Test ran in record mode. Reference image is now saved. Disable record mode to perform an actual snapshot comparison!", file: file, line: line)
|
||||
|
||||
if comparisonSuccess || recordMode {
|
||||
break
|
||||
}
|
||||
|
||||
assert(comparisonSuccess, message: "Snapshot comparison failed: \(error)", file: file, line: line)
|
||||
}
|
||||
} else {
|
||||
XCTFail("Missing value for referenceImagesDirectory - Set FB_REFERENCE_IMAGE_DIR as Environment variable in your scheme.")
|
||||
}
|
||||
}
|
||||
|
||||
func assert(assertion: Bool, message: String, file: StaticString, line: UInt) {
|
||||
if !assertion {
|
||||
XCTFail(message, file: file, line: line)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
197
AntidoteTests/ThemeTest.swift
Normal file
@ -0,0 +1,197 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import XCTest
|
||||
|
||||
class ThemeTest: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testParsingFile() {
|
||||
let string =
|
||||
"version: 1\n" +
|
||||
"colors:\n" +
|
||||
" first: \"AABBCC\"\n" +
|
||||
" second: \"55667788\"\n" +
|
||||
"values:\n" +
|
||||
" login-background: second\n" +
|
||||
" login-gradient: first\n" +
|
||||
" login-tox-logo: second\n" +
|
||||
" login-button-text: first\n" +
|
||||
" login-button-background: second\n" +
|
||||
" login-description-label: first\n" +
|
||||
" login-form-background: second\n" +
|
||||
" login-form-text: first\n" +
|
||||
" login-link-color: second\n" +
|
||||
|
||||
" translucent-background: first\n" +
|
||||
|
||||
" normal-background: second\n" +
|
||||
" normal-text: first\n" +
|
||||
" link-text: second\n" +
|
||||
" connecting-background: first\n" +
|
||||
" connecting-text: second\n" +
|
||||
" separators-and-borders: first\n" +
|
||||
" offline-status: second\n" +
|
||||
" online-status: first\n" +
|
||||
" away-status: second\n" +
|
||||
" busy-status: first\n" +
|
||||
" status-background: second\n" +
|
||||
" friend-cell-status: first\n" +
|
||||
" chat-list-cell-message: second\n" +
|
||||
" chat-list-cell-unread-background: first\n" +
|
||||
" chat-input-background: second\n" +
|
||||
" chat-incoming-bubble: first\n" +
|
||||
" chat-outgoing-bubble: second\n" +
|
||||
" chat-information-text: second\n" +
|
||||
" tab-badge-background: first\n" +
|
||||
" tab-badge-text: second\n" +
|
||||
" tab-item-active: first\n" +
|
||||
" tab-item-inactive: second\n" +
|
||||
" notification-background: first\n" +
|
||||
" notification-text: second\n" +
|
||||
" settings-background: first\n" +
|
||||
" call-text-color: second\n" +
|
||||
" call-decline-button-background: first\n" +
|
||||
" call-answer-button-background: second\n" +
|
||||
" call-control-background: first\n" +
|
||||
" call-control-selected-background: second\n" +
|
||||
" call-button-icon-color: first\n" +
|
||||
" call-button-selected-icon-color: second\n" +
|
||||
" call-video-preview-background: first\n" +
|
||||
" rounded-button-text: second\n" +
|
||||
" rounded-positive-button-background: first\n" +
|
||||
" rounded-negative-button-background: second\n" +
|
||||
" empty-screen-placeholder-text: first\n" +
|
||||
" file-image-background-active: second\n" +
|
||||
" file-image-cancelled-text: first\n" +
|
||||
" file-image-accept-button-tint: second\n" +
|
||||
" file-image-cancel-button-tint: first\n" +
|
||||
" lock-gradient-top: second\n" +
|
||||
" lock-gradient-bottom: first\n" +
|
||||
""
|
||||
|
||||
let first = UIColor(red: 170.0 / 255.0, green: 187.0 / 255.0, blue: 204.0 / 255.0, alpha: 1.0)
|
||||
let second = UIColor(red: 85.0 / 255.0, green: 102.0 / 255.0, blue: 119.0 / 255.0, alpha: 136.0 / 255.0)
|
||||
|
||||
do {
|
||||
let theme = try Theme(yamlString: string)
|
||||
|
||||
XCTAssertEqual(second, theme.colorForType(.LoginBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.LoginGradient))
|
||||
XCTAssertEqual(second, theme.colorForType(.LoginToxLogo))
|
||||
XCTAssertEqual(first, theme.colorForType(.LoginButtonText))
|
||||
XCTAssertEqual(second, theme.colorForType(.LoginButtonBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.LoginDescriptionLabel))
|
||||
XCTAssertEqual(second, theme.colorForType(.LoginFormBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.LoginFormText))
|
||||
XCTAssertEqual(second, theme.colorForType(.LoginLinkColor))
|
||||
|
||||
XCTAssertEqual(first, theme.colorForType(.TranslucentBackground))
|
||||
|
||||
XCTAssertEqual(second, theme.colorForType(.NormalBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.NormalText))
|
||||
XCTAssertEqual(second, theme.colorForType(.LinkText))
|
||||
XCTAssertEqual(first, theme.colorForType(.ConnectingBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.ConnectingText))
|
||||
XCTAssertEqual(first, theme.colorForType(.SeparatorsAndBorders))
|
||||
XCTAssertEqual(second, theme.colorForType(.OfflineStatus))
|
||||
XCTAssertEqual(first, theme.colorForType(.OnlineStatus))
|
||||
XCTAssertEqual(second, theme.colorForType(.AwayStatus))
|
||||
XCTAssertEqual(first, theme.colorForType(.BusyStatus))
|
||||
XCTAssertEqual(second, theme.colorForType(.StatusBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.FriendCellStatus))
|
||||
XCTAssertEqual(second, theme.colorForType(.ChatListCellMessage))
|
||||
XCTAssertEqual(first, theme.colorForType(.ChatListCellUnreadBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.ChatInputBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.ChatIncomingBubble))
|
||||
XCTAssertEqual(second, theme.colorForType(.ChatOutgoingBubble))
|
||||
XCTAssertEqual(second, theme.colorForType(.ChatInformationText))
|
||||
XCTAssertEqual(first, theme.colorForType(.TabBadgeBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.TabBadgeText))
|
||||
XCTAssertEqual(first, theme.colorForType(.TabItemActive))
|
||||
XCTAssertEqual(second, theme.colorForType(.TabItemInactive))
|
||||
XCTAssertEqual(first, theme.colorForType(.NotificationBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.NotificationText))
|
||||
XCTAssertEqual(first, theme.colorForType(.SettingsBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.CallTextColor))
|
||||
XCTAssertEqual(first, theme.colorForType(.CallDeclineButtonBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.CallAnswerButtonBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.CallControlBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.CallControlSelectedBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.CallButtonIconColor))
|
||||
XCTAssertEqual(second, theme.colorForType(.CallButtonSelectedIconColor))
|
||||
XCTAssertEqual(first, theme.colorForType(.CallVideoPreviewBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.RoundedButtonText))
|
||||
XCTAssertEqual(first, theme.colorForType(.RoundedPositiveButtonBackground))
|
||||
XCTAssertEqual(second, theme.colorForType(.RoundedNegativeButtonBackground))
|
||||
XCTAssertEqual(first, theme.colorForType(.EmptyScreenPlaceholderText))
|
||||
XCTAssertEqual(second, theme.colorForType(.FileImageBackgroundActive))
|
||||
XCTAssertEqual(first, theme.colorForType(.FileImageCancelledText))
|
||||
XCTAssertEqual(second, theme.colorForType(.FileImageAcceptButtonTint))
|
||||
XCTAssertEqual(first, theme.colorForType(.FileImageCancelButtonTint))
|
||||
XCTAssertEqual(second, theme.colorForType(.LockGradientTop))
|
||||
XCTAssertEqual(first, theme.colorForType(.LockGradientBottom))
|
||||
}
|
||||
catch let error as ErrorTheme {
|
||||
XCTFail(error.debugDescription())
|
||||
}
|
||||
catch {
|
||||
XCTFail("Theme init failed for unknown reason")
|
||||
}
|
||||
}
|
||||
|
||||
func testVersionToHight() {
|
||||
let string =
|
||||
"version: 2\n" +
|
||||
"colors:\n" +
|
||||
" first: \"AABBCC\"\n" +
|
||||
"values:\n" +
|
||||
" login-background: first\n"
|
||||
|
||||
var didThrow = false
|
||||
|
||||
do {
|
||||
let _ = try Theme(yamlString: string)
|
||||
}
|
||||
catch ErrorTheme.wrongVersion(let description) {
|
||||
didThrow = description == String(localized: "theme_error_cannot_open")
|
||||
}
|
||||
catch {
|
||||
didThrow = false
|
||||
}
|
||||
|
||||
XCTAssertTrue(didThrow)
|
||||
}
|
||||
|
||||
func testVersionToLow() {
|
||||
let string =
|
||||
"version: 0\n" +
|
||||
"colors:\n" +
|
||||
" first: \"AABBCC\"\n" +
|
||||
"values:\n" +
|
||||
" login-background: first\n"
|
||||
|
||||
var didThrow = false
|
||||
|
||||
do {
|
||||
let _ = try Theme(yamlString: string)
|
||||
}
|
||||
catch ErrorTheme.wrongVersion(let description) {
|
||||
didThrow = description == String(localized: "theme_error_cannot_open")
|
||||
}
|
||||
catch {
|
||||
didThrow = false
|
||||
}
|
||||
|
||||
XCTAssertTrue(didThrow)
|
||||
}
|
||||
}
|
BIN
AntidoteTests/icon.png
Normal file
After Width: | Height: | Size: 2.7 KiB |