You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.6 KiB

5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
  1. //
  2. // FunctionTest.swift
  3. // GMERemittanceTests
  4. //
  5. // Created by InKwon Devik Kim on 09/07/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import XCTest
  9. @testable import GME_Remit
  10. class FunctionTest: XCTestCase {
  11. func testExpireDate() {
  12. guard let remindDay = Utility.calculateDDay(registDate: "7/12/2018 4:19:37 PM")
  13. else {
  14. XCTAssert(false)
  15. return
  16. }
  17. print("remindDay: \(remindDay)")
  18. XCTAssert(true)
  19. }
  20. func testDateFormat() {
  21. let dateFormatter = DateFormatter()
  22. dateFormatter.dateFormat = "M/d/yyyy h:mm:ss a"
  23. dateFormatter.locale = Locale(identifier: "ko_kr")
  24. dateFormatter.timeZone = TimeZone(abbreviation: "KST")
  25. var dateComponent = DateComponents()
  26. dateComponent.year = 1
  27. let resigstDate = "7/11/2019 4:19:37 PM"
  28. guard
  29. let date = dateFormatter.date(from: resigstDate) else {
  30. XCTAssert(false)
  31. return
  32. }
  33. print("Date: \(date)")
  34. }
  35. func testIDValid() {
  36. let extractID = "l.e ibn$iz@55_good-)(*&".extract(regex: "[A-Z0-9a-z._@-]")
  37. print("Extract ID: \(extractID)")
  38. XCTAssertEqual(extractID, "l.eibniz@55_good-")
  39. }
  40. func testASCIIAndSpace() {
  41. let extractID = "l.e ibn$iz@55_good-)(*&".extract(regex: "[A-Z0-9a-z\\s]")
  42. print("Extract ID: \(extractID)")
  43. let textField = UITextField()
  44. textField.text = "l.e ibn$iz@55_good-)(*&"
  45. textField.filterBy(type: .alphabetNumberic, isSendAction: true)
  46. XCTAssertEqual(extractID, "le ibniz55good")
  47. XCTAssertEqual(textField.text ?? "", "le ibniz55good")
  48. }
  49. func testDynamicFieldMap() {
  50. let models = [FieldModel]()
  51. let textFields = [ValidationTextField]()
  52. let dynamicField = [
  53. "Bank Name": 0,
  54. "Branch Name": 1,
  55. "Account No.": 2,
  56. "Id Type": 3,
  57. "ID Number": 4,
  58. "First Name": 5,
  59. "Middle Name": 6,
  60. "Last Name": 7,
  61. "Full Name": 8,
  62. "First Name in Local": 9,
  63. "Middle Name in Local": 10,
  64. "Last Name in Local": 11,
  65. "Local Name": 12,
  66. "Mobile Number": 13,
  67. "Province": 14,
  68. "State": 15,
  69. "City": 16,
  70. "Address": 17,
  71. "Realation Group": 18,
  72. "Transfer Reason": 19
  73. ]
  74. models.forEach { property in
  75. guard
  76. let key = property.fieldName,
  77. let tag = dynamicField[key],
  78. let textField = textFields.filter({ $0.tag == tag }).first,
  79. let isRequire = property.required,
  80. let isHidden = isRequire == "H" ? true : false,
  81. let min = property.minLength,
  82. let max = property.maxLength,
  83. let keyboardType = property.keyBoardType
  84. else {return}
  85. textField.isHidden = isHidden
  86. textField.validCondition = { $0.count > min && $0.count < max }
  87. switch keyboardType {
  88. case "AN":
  89. textField.keyboardType = .asciiCapable
  90. textField.removeNonASCII()
  91. case "N":
  92. textField.keyboardType = .numberPad
  93. case "ANS":
  94. textField.keyboardType = .asciiCapable
  95. default:
  96. textField.keyboardType = .asciiCapable
  97. textField.removeNonASCII()
  98. }
  99. }
  100. }
  101. func testDecimalToCurrency() {
  102. var amount = "10000"
  103. XCTAssert(amount.decimalToCurrency() == "10,000", amount.decimalToCurrency())
  104. amount = "10000.00"
  105. XCTAssert(amount.decimalToCurrency() == "10,000", amount.decimalToCurrency())
  106. amount = "11345.00"
  107. XCTAssert(amount.decimalToCurrency() == "11,345", amount.decimalToCurrency())
  108. amount = "11345.94"
  109. XCTAssert(amount.decimalToCurrency() == "11,345.94", amount.decimalToCurrency())
  110. amount = "0.11"
  111. XCTAssert(amount.decimalToCurrency() == "0.11", amount.decimalToCurrency())
  112. amount = "10000"
  113. XCTAssert(
  114. amount.decimalToCurrency(as: .krw, isFront: true) == "JPY 10,000",
  115. amount.decimalToCurrency(as: .krw, isFront: true)
  116. )
  117. amount = "10000.00"
  118. XCTAssert(
  119. amount.decimalToCurrency(as: .krw, isFront: false) == "10,000 JPY",
  120. amount.decimalToCurrency(as: .krw, isFront: false)
  121. )
  122. amount = "11345.00"
  123. XCTAssert(
  124. amount.decimalToCurrency(as: .usd, isFront: true) == "USD 11,345",
  125. amount.decimalToCurrency(as: .usd, isFront: true)
  126. )
  127. amount = "11345.94"
  128. XCTAssert(
  129. amount.decimalToCurrency(as: .usd, isFront: false) == "11,345.94 USD",
  130. amount.decimalToCurrency(as: .usd, isFront: false)
  131. )
  132. amount = "0.11"
  133. XCTAssert(
  134. amount.decimalToCurrency(as: .usd, isFront: true) == "USD 0.11",
  135. amount.decimalToCurrency(as: .usd, isFront: true)
  136. )
  137. }
  138. func testCurrencyToDecimal() {
  139. var amount = "10,000"
  140. XCTAssert(amount.currencyToDecimal() == "10000", amount.currencyToDecimal())
  141. amount = "10,000.00"
  142. XCTAssert(amount.currencyToDecimal() == "10000.00", amount.currencyToDecimal())
  143. amount = "11,345.94"
  144. XCTAssert(amount.currencyToDecimal() == "11345.94", amount.currencyToDecimal())
  145. amount = "0.11"
  146. XCTAssert(amount.currencyToDecimal() == "0.11", amount.currencyToDecimal())
  147. amount = "JPY 10,000"
  148. XCTAssert(amount.currencyToDecimal() == "10000", amount.currencyToDecimal())
  149. amount = "USD 11,345"
  150. XCTAssert(amount.currencyToDecimal() == "11345", amount.currencyToDecimal())
  151. amount = "11,345.94 USD"
  152. XCTAssert(amount.currencyToDecimal() == "11345.94", amount.currencyToDecimal())
  153. amount = "USD 0.11"
  154. XCTAssert(amount.currencyToDecimal() == "0.11", amount.currencyToDecimal())
  155. }
  156. func testCreditCard() {
  157. XCTAssert(CreditCardType.validate(cardNumber: "5365100675887315") == Optional(.mastercard))
  158. }
  159. }