Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
adding few more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Apr 27, 2023
1 parent a6822b2 commit 9594dbc
Showing 1 changed file with 64 additions and 30 deletions.
94 changes: 64 additions & 30 deletions Tests/BraveWalletTests/AssetDetailStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ class AssetDetailStoreTests: XCTestCase {
.store(in: &cancellables)
store.$isLoadingPrice
.dropFirst()
.sink {
.collect(2)
.sink { values in
defer { assetDetailException.fulfill() }
XCTAssertFalse($0)
guard let value = values.last
else {
XCTFail("Unexpected isLoadingPrice")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)
store.$isInitialState
Expand All @@ -193,16 +199,20 @@ class AssetDetailStoreTests: XCTestCase {
.store(in: &cancellables)
store.$isLoadingChart
.dropFirst()
.sink {
.collect(2)
.sink { values in
defer { assetDetailException.fulfill() }
XCTAssertFalse($0)
guard let value = values.last
else {
XCTFail("Unexpected isLoadingChart")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)

store.update()
waitForExpectations(timeout: 1) { error in
XCTAssertNil(error)
}
wait(for: [assetDetailException], timeout: 1)
}

func testUpdateWithCoinMarket() {
Expand Down Expand Up @@ -274,95 +284,107 @@ class AssetDetailStoreTests: XCTestCase {
assetDetailType: .coinMarket(.previewCoinMarketBitcoin)
)

let assetDetailException = expectation(description: "update-coinMarket-bitcoin")
assetDetailException.expectedFulfillmentCount = 11
let assetDetailBitcoinException = expectation(description: "update-coinMarket-bitcoin")
assetDetailBitcoinException.expectedFulfillmentCount = 11
store.$isBuySupported
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertFalse($0)
}
.store(in: &cancellables)
store.$isSendSupported
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertFalse($0)
}
.store(in: &cancellables)
store.$isSwapSupported
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertFalse($0)
}
.store(in: &cancellables)
store.$btcRatio
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertEqual($0, "1 BTC")
}
.store(in: &cancellables)
store.$priceHistory
.dropFirst()
.sink { priceHistory in
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertEqual(priceHistory.count, 1)
XCTAssertEqual(priceHistory[0].price, "0.99")
}
.store(in: &cancellables)
store.$price
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertEqual($0, "$28,324.00")
}
.store(in: &cancellables)
store.$priceIsDown
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertFalse($0)
}
.store(in: &cancellables)
store.$priceDelta
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertEqual($0, "0.58%")
}
.store(in: &cancellables)
store.$isLoadingPrice
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
XCTAssertFalse($0)
.collect(2)
.sink { values in
defer { assetDetailBitcoinException.fulfill() }
guard let value = values.last
else {
XCTFail("Unexpected isLoadingPrice")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)
store.$isInitialState
.dropFirst()
.sink {
defer { assetDetailException.fulfill() }
defer { assetDetailBitcoinException.fulfill() }
XCTAssertFalse($0)
}
.store(in: &cancellables)
store.$isLoadingChart
.dropFirst()
.sink {
.collect(2)
.sink { values in
defer {
XCTAssertNil(store.network)
XCTAssertTrue(store.accounts.isEmpty)
XCTAssertTrue(store.transactionSummaries.isEmpty)
assetDetailException.fulfill()

assetDetailBitcoinException.fulfill()
}
XCTAssertFalse($0)
guard let value = values.last
else {
XCTFail("Unexpected isLoadingChart")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)

store.update()
wait(for: [assetDetailException], timeout: 1)
wait(for: [assetDetailBitcoinException], timeout: 1)
cancellables.removeAll()

// setup store
Expand Down Expand Up @@ -444,9 +466,15 @@ class AssetDetailStoreTests: XCTestCase {
.store(in: &cancellables)
store.$isLoadingPrice
.dropFirst()
.sink {
.collect(2)
.sink { values in
defer { assetDetailNonBitcoinException.fulfill() }
XCTAssertFalse($0)
guard let value = values.last
else {
XCTFail("Unexpected isLoadingPrice")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)
store.$isInitialState
Expand All @@ -458,15 +486,21 @@ class AssetDetailStoreTests: XCTestCase {
.store(in: &cancellables)
store.$isLoadingChart
.dropFirst()
.sink {
.collect(2)
.sink { values in
defer {
XCTAssertNil(store.network)
XCTAssertTrue(store.accounts.isEmpty)
XCTAssertTrue(store.transactionSummaries.isEmpty)

assetDetailNonBitcoinException.fulfill()
}
XCTAssertFalse($0)
guard let value = values.last
else {
XCTFail("Unexpected isLoadingChart")
return
}
XCTAssertFalse(value)
}
.store(in: &cancellables)

Expand Down

0 comments on commit 9594dbc

Please sign in to comment.