お客様がファイルをアップロードするのを忘れた場合に、次のページに進む前に [続行] ボタンをクリックしたときに、sweetalert でウォームアップできるように、sweetalertをページに追加しようとしています。
ボタンのhtml:
<a href="/checkout/address" class="checkout-now continue-to-checkout">Checkout Now ></a>
クリック ハンドラー JavaScript:
$(HtmlIds.cart.checkoutBtn).click(function(e) {
if ($(HtmlIds.cart.missingUploadsTag).length !== 0) {
e.preventDefault();
var linkURL = $(this).attr("href");
SweetAlert({
title: "Missing Uploads",
text: "Your print job(s) are missing file uploads, which will cause a delay in the production of your order. " +
"To upload a file to a print job, please click on the 'Update Files' links in your shopping cart.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "I understand, proceed anyway"
}, function(isConfirm) {
if (isConfirm)
window.location.href = linkURL;
});
}
});
コードは正常に動作します。ただし、rspec とカピバラを介したテストに問題があります。次のページに移動しようとすると、テストが失敗し、次のページにいるかどうかを確認するときにカピバラ/ポルターガイスト エラーが発生します。
rspec/カピバラ テスト コード:
click_link "Checkout Now"
find(".sweet-alert").should have_content("Missing Uploads") #wait until sweet alert pops up
click_button "I understand, proceed anyway"
#page.execute_script('$(".confirm").click()')
page.should have_content("Checkout: Delivery")
エラーメッセージ:
2) checkout should be able to go through checkout via shipping
Failure/Error: page.should have_content("Checkout: Delivery")
expected #has_content?("Checkout: Delivery") to return true, got false
ボタンが存在しないというエラーが発生しないため、クリックボタンを使用するとカピバラはクリックを登録するようですが、次のページに進むことはありません。コメントアウトされた強制jqueryコードも機能しません。私のコードからsweetalertを削除すると(そして私のテストでのクリック)、ユーザーはテストに合格しても続行します。