deltachat_iosTests.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. @testable import deltachat_ios
  2. import XCTest
  3. class DeltachatTests: XCTestCase {
  4. var testContact: MRContact?
  5. override func setUp() {
  6. let contactIds = Utils.getContactIds()
  7. let contacts = contactIds.map { MRContact(id: $0) }
  8. testContact = contacts.filter { $0.name == "John Appleseed" }.first
  9. // Put setup code here. This method is called before the invocation of each test method in the class.
  10. }
  11. override func tearDown() {
  12. // Put teardown code here. This method is called after the invocation of each test method in the class.
  13. }
  14. func testContactSearchForSubsequences() {
  15. // this test will only success if run on a simulator (assuming one of the sample contacts is named John Appleseed)
  16. guard let appleseedContact = testContact else {
  17. return
  18. }
  19. XCTAssert(appleseedContact.name == "John Appleseed", "Test contacts name is John Appleseed")
  20. XCTAssert(appleseedContact.email == "John-Appleseed@mac.com", "Test contacts email is john.appleseed@mac.com")
  21. let indexDetailA = appleseedContact.contains(searchText: "jmc")
  22. XCTAssert(indexDetailA.count == 2)
  23. XCTAssert(indexDetailA[0].contactDetail == .NAME)
  24. XCTAssert(indexDetailA[0].indexes == [0])
  25. XCTAssert(indexDetailA[1].indexes == [15, 17])
  26. let indexDetailB = appleseedContact.contains(searchText: "joj")
  27. XCTAssert(indexDetailB[0].indexes == [0, 1])
  28. XCTAssert(indexDetailB[1].indexes == [0])
  29. let indexDetailC = appleseedContact.contains(searchText: "jojh")
  30. XCTAssert(indexDetailC[0].indexes == [0, 1])
  31. XCTAssert(indexDetailC[1].indexes == [0, 2])
  32. let indexDetailD = appleseedContact.contains(searchText: "joz")
  33. XCTAssert(indexDetailD.isEmpty)
  34. }
  35. func testPerformanceExample() {
  36. // This is an example of a performance test case.
  37. measure {
  38. // Put the code you want to measure the time of here.
  39. }
  40. }
  41. }