Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/PaymentMollieTest.php
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | public function testAutoPaymentSetup(): void | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->click('@links .link-wallet') | ->click('@links .link-wallet') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Top up your wallet') | $browser->assertSeeIn('@title', 'Top up your wallet') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | ->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | ||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | |||||
->click('@body #mandate-form button') | ->click('@body #mandate-form button') | ||||
->assertSeeIn('@title', 'Add auto-payment') | ->assertSeeIn('@title', 'Add auto-payment') | ||||
->assertSeeIn('@body label[for="mandate_amount"]', 'Fill up by') | ->assertSeeIn('@body label[for="mandate_amount"]', 'Fill up by') | ||||
->assertValue('@body #mandate_amount', PaymentProvider::MIN_AMOUNT / 100) | ->assertValue('@body #mandate_amount', PaymentProvider::MIN_AMOUNT / 100) | ||||
->assertSeeIn('@body label[for="mandate_balance"]', 'when account balance is below') // phpcs:ignore | ->assertSeeIn('@body label[for="mandate_balance"]', 'when account balance is below') // phpcs:ignore | ||||
->assertValue('@body #mandate_balance', '0') | ->assertValue('@body #mandate_balance', '0') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@button-action', 'Continue') | ->assertSeeIn('@button-action', 'Continue') | ||||
Show All 30 Lines | public function testAutoPaymentSetup(): void | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$expected = 'Auto-payment is set to fill up your account by 100 CHF every' | $expected = 'Auto-payment is set to fill up your account by 100 CHF every' | ||||
. ' time your account balance gets under 0 CHF. You will be charged' | . ' time your account balance gets under 0 CHF. You will be charged' | ||||
. ' via Mastercard (**** **** **** 6787).'; | . ' via Mastercard (**** **** **** 6787).'; | ||||
$browser->assertSeeIn('@title', 'Top up your wallet') | $browser->assertSeeIn('@title', 'Top up your wallet') | ||||
->waitFor('#mandate-info') | ->waitFor('#mandate-info') | ||||
->assertSeeIn('#mandate-info p:first-child', $expected) | ->assertSeeIn('#mandate-info p:first-child', $expected) | ||||
->assertMissing('@body .alert') | |||||
->click('@button-cancel'); | ->click('@button-cancel'); | ||||
}); | }); | ||||
}); | }); | ||||
// Test updating auto-payment | // Test updating (disabled) auto-payment | ||||
$this->browse(function (Browser $browser) use ($user) { | $this->browse(function (Browser $browser) use ($user) { | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->setSetting('mandate_disabled', 1); | $wallet->setSetting('mandate_disabled', 1); | ||||
$browser->refresh() | $browser->refresh() | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->waitFor('@body #mandate-info') | $browser->waitFor('@body #mandate-info') | ||||
->assertSeeIn( | ->assertSeeIn( | ||||
'@body #mandate-info p.disabled-mandate', | '@body #mandate-info .disabled-mandate', | ||||
'The configured auto-payment has been disabled' | 'The configured auto-payment has been disabled' | ||||
) | ) | ||||
->assertSeeIn('@body #mandate-info button.btn-primary', 'Change auto-payment') | ->assertSeeIn('@body #mandate-info button.btn-primary', 'Change auto-payment') | ||||
->click('@body #mandate-info button.btn-primary') | ->click('@body #mandate-info button.btn-primary') | ||||
->assertSeeIn('@title', 'Update auto-payment') | ->assertSeeIn('@title', 'Update auto-payment') | ||||
->assertSeeIn( | ->assertSeeIn( | ||||
'@body form p.disabled-mandate', | '@body form .disabled-mandate', | ||||
'The auto-payment is disabled.' | 'The auto-payment is disabled.' | ||||
) | ) | ||||
->assertValue('@body #mandate_amount', '100') | ->assertValue('@body #mandate_amount', '100') | ||||
->assertValue('@body #mandate_balance', '0') | ->assertValue('@body #mandate_balance', '0') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@button-action', 'Submit') | ->assertSeeIn('@button-action', 'Submit') | ||||
// Test error handling | // Test error handling | ||||
->type('@body #mandate_amount', 'aaa') | ->type('@body #mandate_amount', 'aaa') | ||||
->click('@button-action') | ->click('@button-action') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->assertVisible('@body #mandate_amount.is-invalid') | ->assertVisible('@body #mandate_amount.is-invalid') | ||||
->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ||||
// Submit valid data | // Submit valid data | ||||
->type('@body #mandate_amount', '50') | ->type('@body #mandate_amount', '50') | ||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->waitUntilMissing('#payment-dialog') | ->waitUntilMissing('#payment-dialog') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been updated.') | ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been updated.') | ||||
// Open the dialog again and make sure the "disabled" text isn't there | // Open the dialog again and make sure the "disabled" text isn't there | ||||
->click('@main button') | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertMissing('@body #mandate-info p.disabled-mandate') | $browser->assertMissing('@body #mandate-info .disabled-mandate') | ||||
->click('@body #mandate-info button.btn-primary') | ->click('@body #mandate-info button.btn-primary') | ||||
->assertMissing('@body form p.disabled-mandate') | ->assertMissing('@body form .disabled-mandate') | ||||
->click('@button-cancel'); | ->click('@button-cancel'); | ||||
}); | }); | ||||
}); | }); | ||||
// Test deleting auto-payment | // Test deleting auto-payment | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->on(new WalletPage()) | $browser->on(new WalletPage()) | ||||
->click('@main button') | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@body #mandate-info button.btn-danger', 'Cancel auto-payment') | $browser->assertSeeIn('@body #mandate-info button.btn-danger', 'Cancel auto-payment') | ||||
->click('@body #mandate-info button.btn-danger') | ->click('@body #mandate-info button.btn-danger') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') | ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') | ||||
->assertVisible('@body #mandate-form') | ->assertVisible('@body #mandate-form') | ||||
->assertMissing('@body #mandate-info'); | ->assertMissing('@body #mandate-info') | ||||
->click('@button-cancel'); | |||||
}); | |||||
}); | |||||
// Test pending and failed mandate | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->on(new WalletPage()) | |||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | |||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | |||||
->click('@body #mandate-form button') | |||||
->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertMissing('@body .alert') | |||||
// Submit valid data | |||||
->type('@body #mandate_amount', '100') | |||||
->type('@body #mandate_balance', '0') | |||||
->click('@button-action'); | |||||
}) | |||||
->on(new PaymentMollie()) | |||||
->submitValidCreditCard('open') | |||||
->waitForLocation('/wallet') | |||||
->visit('/wallet?paymentProvider=mollie') | |||||
->on(new WalletPage()) | |||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$expected = 'Auto-payment is set to fill up your account by 100 CHF every' | |||||
. ' time your account balance gets under 0 CHF. You will be charged' | |||||
. ' via Credit Card.'; | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->waitFor('#mandate-info') | |||||
->assertSeeIn('#mandate-info p:first-child', $expected) | |||||
->assertSeeIn( | |||||
'#mandate-info .alert-warning', | |||||
'The setup of the automatic payment is still in progress.' | |||||
) | |||||
->assertSeeIn('@body #mandate-info .btn-danger', 'Cancel auto-payment') | |||||
->assertSeeIn('@body #mandate-info .btn-primary', 'Change auto-payment') | |||||
// Delete the mandate | |||||
->click('@body #mandate-info .btn-danger') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') | |||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | |||||
->click('@body #mandate-form button') | |||||
->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertMissing('@body .alert') | |||||
// Submit valid data | |||||
->type('@body #mandate_amount', '100') | |||||
->type('@body #mandate_balance', '0') | |||||
->click('@button-action'); | |||||
}) | |||||
->on(new PaymentMollie()) | |||||
->submitValidCreditCard('failed') | |||||
->waitForLocation('/wallet') | |||||
->visit('/wallet?paymentProvider=mollie') | |||||
->on(new WalletPage()) | |||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->waitFor('#mandate-form') | |||||
->assertMissing('#mandate-info') | |||||
->assertSeeIn('#mandate-form p', 'Add auto-payment') | |||||
->waitFor('#mandate-form .alert-danger') | |||||
->assertSeeIn( | |||||
'#mandate-form .alert-danger', | |||||
'The setup of automatic payments failed. Restart the process to enable' | |||||
) | |||||
->assertSeeIn('@body #mandate-form .btn-primary', 'Set up auto-payment'); | |||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
} | } |