Skip to content

Commit 0081cbb

Browse files
author
Mohan Ahuja
committed
ACP2E-711: "Invalid Form Key. Please refresh the page." error occurs when changing the product limit in categories
- Updated unit tests
1 parent 0e62945 commit 0081cbb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/PageCache/frontend/js/form-key-provider.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,31 @@ define([
3232
date.setTime(date.getTime() + 86400000);
3333
expires = '; expires=' + date.toUTCString();
3434
document.cookie = 'form_key=FAKE_COOKIE' + expires + '; path=/';
35-
formKeyInit();
35+
formKeyInit({'isPaginationCacheEnabled': 0});
3636
expect($(inputContainer).val()).toEqual('FAKE_COOKIE');
3737
});
3838

3939
it('widget sets value to input[form_key] in case it empty', function () {
4040
document.cookie = 'form_key= ; expires = Thu, 01 Jan 1970 00:00:00 GMT';
41-
formKeyInit();
41+
formKeyInit({'isPaginationCacheEnabled': 0});
4242
expect($(inputContainer).val()).toEqual(jasmine.any(String));
4343
expect($(inputContainer).val().length).toEqual(16);
4444
});
45+
46+
it('widget gets value from input[form_key] in case cookie is empty is pagination cache enabled', function () {
47+
document.cookie = 'form_key= ; expires = Thu, 01 Jan 1970 00:00:00 GMT';
48+
var formKey = 'TestInputStrings';
49+
$(inputContainer).val(formKey);
50+
formKeyInit({'isPaginationCacheEnabled': 1});
51+
expect($(inputContainer).val()).toEqual(jasmine.any(String));
52+
expect($(inputContainer).val().length).toEqual(16);
53+
expect(formKey).toEqual(getFormKeyCookie());
54+
});
55+
56+
function getFormKeyCookie() {
57+
var nameEQ = 'form_key=',
58+
cookieArr = document.cookie.split(';');
59+
return cookieArr[0].split(nameEQ)[1];
60+
}
4561
});
4662
});

0 commit comments

Comments
 (0)