Skip to content

Commit

Permalink
test: Added test for pathname distinction options
Browse files Browse the repository at this point in the history
  • Loading branch information
pjjonesnz committed Jan 21, 2020
1 parent c6cfb8f commit 48741f1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions spec/suites/saveMyForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ describe('saveMyForm', function() {
});

it('can clear entire element_list from localStorage', function() {
expect(localStorage.getItem('elementList_' + form_id)).not.toEqual(null);
expect(getLocalStorage('elementList_' + form_id)).not.toEqual(null);
$('#' + form_id).saveMyForm('clearElementList');
expect(localStorage.getItem('elementList_' + form_id)).toEqual(null);
expect(getLocalStorage('elementList_' + form_id)).toEqual(null);
});

it('unnamed elements can have their value changed but...', function() {
Expand All @@ -200,11 +200,14 @@ describe('saveMyForm WITH custom options', function() {

var save_formname = 'my_formname';
var addPathToName = true;
var addPathLength = -10;

function locSt(field) {
var pathName = window.location.pathname;
pathName = pathName.slice(addPathLength);
return getLocalStorage(
save_formname +
(addPathToName ? '___' + window.location.pathname : '') +
(addPathToName ? '___' + pathName : '') +
'_' +
field
);
Expand All @@ -223,14 +226,22 @@ describe('saveMyForm WITH custom options', function() {
include: ':input:not(#checkbox_2)',
resetOnSubmit: false,
formName: save_formname,
addPathToName: addPathToName
addPathToName: addPathToName,
addPathLength: addPathLength
});
});

afterEach(function() {
$('#' + form_id).remove();
});

it('adds a pathname to the field and form name to distinguish it', function() {
$('#text_input')
.val('very happy')
.change();
expect(locSt('text_input')).toEqual('very happy');
});

it("doesn't reset localStorage when resetOnSubmit is false", function() {
$('#text_input')
.val('very happy')
Expand Down

0 comments on commit 48741f1

Please sign in to comment.