Skip to content

Commit 842a641

Browse files
MAGETWO-67352: Terms & Conditions validation not working in case of two entries
1 parent bab4284 commit 842a641

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ define([
2020
* @returns {Boolean}
2121
*/
2222
validate: function () {
23+
var isValid = true;
24+
2325
if (!agreementsConfig.isEnabled || $(agreementsInputPath).length === 0) {
2426
return true;
2527
}
2628

27-
return $.validator.validateSingleElement(agreementsInputPath, {
28-
errorElement: 'div'
29+
$(agreementsInputPath).each(function (index, element) {
30+
if (!$.validator.validateSingleElement(element, {
31+
errorElement: 'div'
32+
})) {
33+
isValid = false;
34+
}
2935
});
36+
37+
return isValid;
3038
}
3139
};
3240
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define(['squire', 'jquery'], function (Squire, $) {
7+
'use strict';
8+
9+
var injector = new Squire(),
10+
agreementsBlockSelector = '.payment-method._active div.checkout-agreements',
11+
agreementsBlock = $('<div class="payment-method _active"><div class="checkout-agreements"></div></div>'),
12+
obj,
13+
14+
/**
15+
* @param {Boolean} isChecked
16+
* @return {Object}
17+
*/
18+
getCheckboxMock = function (isChecked) {
19+
return $('<input type="checkbox" class="required-entry" name="some"/>').prop('checked', isChecked);
20+
};
21+
22+
beforeEach(function (done) {
23+
window.checkoutConfig = {
24+
checkoutAgreements: {
25+
isEnabled: true
26+
}
27+
};
28+
29+
$('body').append(agreementsBlock);
30+
31+
injector.require(['Magento_CheckoutAgreements/js/model/agreement-validator'], function (Validator) {
32+
obj = Validator;
33+
done();
34+
});
35+
});
36+
37+
afterEach(function () {
38+
$('.payment-method._active').remove();
39+
});
40+
41+
describe('Magento_CheckoutAgreements/js/model/agreement-validator', function () {
42+
describe('"validate" method', function () {
43+
it('Check with non existing checkboxes', function () {
44+
expect(obj.validate()).toBe(true);
45+
});
46+
47+
it('Check with unchecked checkboxes', function () {
48+
$(agreementsBlockSelector).html(getCheckboxMock(false));
49+
expect(obj.validate()).toBe(false);
50+
});
51+
52+
it('Check with checked checkboxes', function () {
53+
$(agreementsBlockSelector).html(getCheckboxMock(true));
54+
expect(obj.validate()).toBe(true);
55+
});
56+
57+
it('Check with several checkboxes', function () {
58+
$(agreementsBlockSelector).html(getCheckboxMock(true));
59+
$(agreementsBlockSelector).append(getCheckboxMock(false));
60+
expect(obj.validate()).toBe(false);
61+
62+
$(agreementsBlockSelector).html(getCheckboxMock(false));
63+
$(agreementsBlockSelector).append(getCheckboxMock(false));
64+
expect(obj.validate()).toBe(false);
65+
66+
$(agreementsBlockSelector).html(getCheckboxMock(true));
67+
$(agreementsBlockSelector).append(getCheckboxMock(true));
68+
expect(obj.validate()).toBe(true);
69+
});
70+
});
71+
});
72+
});

0 commit comments

Comments
 (0)