Skip to content

Commit

Permalink
Merge pull request #489 from tinkoff-mobile-tech/fix/EACQAPW-5657/car…
Browse files Browse the repository at this point in the history
…d_pay_bugs

* [EACQAPW-5657] Pay by Card email field bugfixes
  • Loading branch information
ivanglushko authored Jul 26, 2023
2 parents adcf52d + cc165c2 commit 5cbde37
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
### Fixed

* [EACQAPW-4285] Remove LOOP_CHECKING status in card attachment
* [EACQAPW-5657] Pay by Card email field bugfixes

## [3.1.1] - 2023-07-17Z

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,13 @@ extension MainFormPresenter {
return
}

let isCvcValid = dataState.hasCards ? savedCardPresenter.isValid : true
let isEmailValid = getReceiptSwitchPresenter.isOn ? emailPresenter.isEmailValid : true

payButtonPresenter.set(enabled: isCvcValid && isEmailValid)
if dataState.hasCards == false {
payButtonPresenter.set(enabled: true)
} else {
let isCvcValid = savedCardPresenter.isValid
let isEmailValid = getReceiptSwitchPresenter.isOn ? emailPresenter.isEmailValid : true
payButtonPresenter.set(enabled: isCvcValid && isEmailValid)
}
}

private func startPaymentWithSavedCard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension EmailViewPresenter {
}

private func viewSetTextFieldHeaderState() {
guard isFieldDidBeginEditing else {
guard isFieldDidBeginEditing || currentEmail.isEmpty == false else {
view?.setTextFieldHeaderNormal()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ final class EmailViewOutputMock: IEmailViewOutput {

var underlyingCurrentEmail = ""

var isEmailValidGetterCount = 0
var isEmailValidSetterCount = 0

var isEmailValid: Bool {
get { return underlyingIsEmailValid }
set(value) { underlyingIsEmailValid = value }
get {
isEmailValidGetterCount += 1
return underlyingIsEmailValid
}
set(value) {
isEmailValidSetterCount += 1
underlyingIsEmailValid = value
}
}

var underlyingIsEmailValid = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ final class SavedCardViewOutputMock: ISavedCardViewOutput {

var underlyingPresentationState: SavedCardPresentationState = .idle

var isValidGetterCount = 0
var isValidSetterCount = 0

var isValid: Bool {
get { return underlyingIsValid }
set(value) { underlyingIsValid = value }
get {
isValidGetterCount += 1
return underlyingIsValid
}
set(value) {
isValidSetterCount += 1
underlyingIsValid = value
}
}

var underlyingIsValid = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
final class SwitchViewOutputMock: ISwitchViewOutput {
var view: ISwitchViewInput?

var isOnGetterCount = 0
var isOnSetterCount = 0

var isOn: Bool {
get { return underlyingIsOn }
set(value) { underlyingIsOn = value }
get {
isOnGetterCount += 1
return underlyingIsOn
}
set(value) {
isOnSetterCount += 1
underlyingIsOn = value
}
}

var underlyingIsOn = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,28 @@ final class EmailViewPresenterTests: BaseTestCase {
// then
XCTAssertFalse(isValidEmail)
}

func test_setsHeaderError_for_invalid_filled_email() {
// given
let email = "EMAIL"

// when
setupSut(customerEmail: email, resetViewMock: false)

// then
XCTAssertEqual(viewMock.setTextFieldHeaderErrorCallsCount, 1)
}
}

// MARK: - Private methods

extension EmailViewPresenterTests {
private func setupSut(customerEmail: String = "") {
private func setupSut(customerEmail: String = "", resetViewMock: Bool = true) {
viewMock = EmailViewInputMock()
outputMock = EmailViewPresenterOutputMock()
sut = EmailViewPresenter(customerEmail: customerEmail, output: outputMock)
sut.view = viewMock

viewMock.fullReset()
if resetViewMock { viewMock.fullReset() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ final class MainFormPresenterTests: BaseTestCase {
XCTAssertEqual(viewMock.hideCommonSheetCallsCount, 1)
}

func test_viewDidLoad_when_primaryPaymentMethodCard_success() {
func test_viewDidLoad_when_primaryPaymentMethodCard_no_saved_cards_success() {
// given
let paymentFlow = PaymentFlow.fake()
setupSut(paymentFlow: paymentFlow)

let sbpPaymentMethod = MainFormPaymentMethod.card
let dataState = MainFormDataState.fake(
primaryPaymentMethod: sbpPaymentMethod,
primaryPaymentMethod: .card,
otherPaymentMethods: [],
cards: nil
)
Expand Down Expand Up @@ -195,11 +194,87 @@ final class MainFormPresenterTests: BaseTestCase {
XCTAssertEqual(savedCardMock.updatePresentationStateReceivedArguments, [])
XCTAssertEqual(payButtonMock.presentationState, .pay)
XCTAssertEqual(payButtonMock.setCallsCount, 1)
XCTAssertEqual(payButtonMock.setReceivedArguments, false)
XCTAssertEqual(payButtonMock.setReceivedArguments, true)
XCTAssertEqual(viewMock.reloadDataCallsCount, 1)
XCTAssertEqual(viewMock.hideCommonSheetCallsCount, 1)
}

func test_main_payment_method_card_no_saved_cards_setEnabled_true() {
// given
let paymentFlow = PaymentFlow.fake()
setupSut(paymentFlow: paymentFlow)

let dataState = MainFormDataState.fake(
primaryPaymentMethod: .card,
otherPaymentMethods: [],
cards: nil
)

dataStateLoaderMock.loadStateCompletionClosureInput = .success(dataState)

let savedCardMock = SavedCardViewOutputMock()
savedCardMock.presentationState = .selected(card: .fake())
savedCardViewPresenterAssemblyMock.buildReturnValue = savedCardMock

let payButtonMock = PayButtonViewOutputMock()
payButtonViewPresenterAssemblyMock.buildReturnValue = payButtonMock

let switchMock = SwitchViewOutputMock()
switchMock.underlyingIsOn = true
switchViewPresenterAssemblyMock.buildReturnValue = switchMock

let emailPresenterMock = emailViewPresenterAssemblyMock.buildReturnValue
emailPresenterMock.underlyingIsEmailValid = false

// when
sut.viewDidLoad()
// then
XCTAssertEqual(payButtonMock.presentationState, .pay)
XCTAssertEqual(payButtonMock.setCallsCount, 1)
XCTAssertEqual(payButtonMock.setReceivedArguments, true)
XCTAssertEqual(savedCardMock.isValidGetterCount, 0)
XCTAssertEqual(switchMock.isOnGetterCount, 1)
XCTAssertEqual(emailPresenterMock.isEmailValidGetterCount, 0)
}

func test_main_payment_method_card_has_saved_cards_setEnabled() {
// given
let paymentFlow = PaymentFlow.fake()
setupSut(paymentFlow: paymentFlow)

let dataState = MainFormDataState.fake(
primaryPaymentMethod: .card,
otherPaymentMethods: [],
cards: .fake()
)

dataStateLoaderMock.loadStateCompletionClosureInput = .success(dataState)

let savedCardMock = SavedCardViewOutputMock()
savedCardMock.presentationState = .selected(card: .fake())
savedCardViewPresenterAssemblyMock.buildReturnValue = savedCardMock

let payButtonMock = PayButtonViewOutputMock()
payButtonViewPresenterAssemblyMock.buildReturnValue = payButtonMock

let switchMock = SwitchViewOutputMock()
switchMock.underlyingIsOn = true
switchViewPresenterAssemblyMock.buildReturnValue = switchMock

let emailPresenterMock = emailViewPresenterAssemblyMock.buildReturnValue
emailPresenterMock.underlyingIsEmailValid = false

// when
sut.viewDidLoad()
// then
XCTAssertEqual(payButtonMock.presentationState, .pay)
XCTAssertEqual(payButtonMock.setCallsCount, 1)
XCTAssertEqual(payButtonMock.setReceivedArguments, false)
XCTAssertEqual(savedCardMock.isValidGetterCount, 1)
XCTAssertEqual(switchMock.isOnGetterCount, 2)
XCTAssertEqual(emailPresenterMock.isEmailValidGetterCount, 1)
}

func test_viewDidLoad_when_primaryPaymentMethodCard_failure() {
// given
let paymentFlow = PaymentFlow.fake()
Expand Down

0 comments on commit 5cbde37

Please sign in to comment.