Skip to content

Commit

Permalink
Add unit tests and fix double formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegGordiichuk authored and vikmeup committed Feb 14, 2018
1 parent 2596bb6 commit 78c9bc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Trust.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
73D2683B202E8411009777A1 /* DecimalNumberFormatterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73D2683A202E8411009777A1 /* DecimalNumberFormatterTest.swift */; };
73ED85A520349BE400593BF3 /* StringFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED85A420349BE400593BF3 /* StringFormatter.swift */; };
73ED85A72034BFEF00593BF3 /* UITextFieldAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED85A62034BFEF00593BF3 /* UITextFieldAdditions.swift */; };
73ED85A92034C42D00593BF3 /* StringFormatterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */; };
771A8471202F067D00528D28 /* NetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771A8470202F067D00528D28 /* NetworksViewController.swift */; };
771A847320322F2500528D28 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771A847220322F2500528D28 /* PreferencesViewController.swift */; };
771A847520322FD700528D28 /* PreferencesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771A847420322FD700528D28 /* PreferencesViewModel.swift */; };
Expand Down Expand Up @@ -678,6 +679,7 @@
73D2683A202E8411009777A1 /* DecimalNumberFormatterTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalNumberFormatterTest.swift; sourceTree = "<group>"; };
73ED85A420349BE400593BF3 /* StringFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringFormatter.swift; sourceTree = "<group>"; };
73ED85A62034BFEF00593BF3 /* UITextFieldAdditions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITextFieldAdditions.swift; sourceTree = "<group>"; };
73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringFormatterTest.swift; sourceTree = "<group>"; };
771A8470202F067D00528D28 /* NetworksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworksViewController.swift; sourceTree = "<group>"; };
771A847220322F2500528D28 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
771A847420322FD700528D28 /* PreferencesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1381,6 +1383,7 @@
299573A11FA1F369006F17FD /* QRURLParserTests.swift */,
61FC5ED01FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift */,
73D2683A202E8411009777A1 /* DecimalNumberFormatterTest.swift */,
73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */,
);
path = Foundation;
sourceTree = "<group>";
Expand Down Expand Up @@ -2838,6 +2841,7 @@
771A84822032423800528D28 /* PreferencesController.swift in Sources */,
293E62731FA3165C00CB0A66 /* InitialWalletCreationCoordinatorTests.swift in Sources */,
29FF130A1F75F67200AFD326 /* Address.swift in Sources */,
73ED85A92034C42D00593BF3 /* StringFormatterTest.swift in Sources */,
29BDF19D1FEE50E90023A45F /* GasPriceConfigurationTests.swift in Sources */,
295996141FAB09A200DB66A8 /* DepositCoordinatorTests.swift in Sources */,
778EAF7D1FF10AF400C8E2AB /* SettingsCoordinatorTests.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion Trust/Transfer/ViewControllers/SendViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ class SendViewController: FormViewController {
if self.currentPair.left == viewModel.symbol {
amountString = amountRow?.value?.trimmed ?? ""
} else {
amountString = stringFormatter.formatter(for: self.pairValue).trimmed
guard let formatedValue = decimalFormatter.string(from: NSNumber(value: self.pairValue)) else {
return displayError(error: SendInputErrors.wrongInput)
}
amountString = formatedValue
}
guard let address = Address(string: addressString) else {
return displayError(error: Errors.invalidAddress)
Expand Down
12 changes: 12 additions & 0 deletions TrustTests/Foundation/StringFormatterTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright SIX DAY LLC. All rights reserved.

@testable import Trust
import XCTest

class StringFormatterTest: XCTestCase {
let stringFormatter = StringFormatter()
func testStringFormatter() {
XCTAssertEqual(stringFormatter.formatter(for: 0.00001), "0.000010")
XCTAssertEqual(stringFormatter.formatter(for: 0.1234, with: 2), "0.12")
}
}

0 comments on commit 78c9bc4

Please sign in to comment.