peteshow 0.7.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peteshow",
3
- "version": "0.7.9",
3
+ "version": "0.8.0",
4
4
  "description": "Plugin for filling out forms with fake data for testing purposes",
5
5
  "keywords": [
6
6
  "filler",
data/src/peteshow-core.js CHANGED
@@ -1,28 +1,36 @@
1
1
  +function($) {
2
2
  getDefaultRules = function() {
3
3
  return {
4
- 'input[type=password]' : 'password',
5
- 'input[type=text]' : Peteshow.randomLetters(8),
6
- 'input[type=email], input[name*=email]' : Peteshow.randomEmail(),
7
- 'input[name*=number], input[type=number]' : Peteshow.randomNumber(8),
8
- 'input[class*=number], input[class*=decimal]' : Peteshow.randomNumber(8),
9
- 'input[type=date]' : Peteshow.randomDate(),
10
- 'input[name*=phone]' : Faker.PhoneNumber.phoneNumberFormat(5),
11
- 'input[name*=first_name]' : Faker.Name.firstName(),
12
- 'input[name*=last_name]' : Faker.Name.lastName(),
13
- 'input[name*=company]' : Faker.Company.companyName(),
14
- 'input[name*=line1], input[name*=street]' : Faker.Address.streetName(),
15
- 'input[name*=line2], input[name*=suite]' : Faker.Address.secondaryAddress(),
16
- 'input[name*=city]' : Faker.Address.city(),
17
- 'input[name*=zip], input[name*=postal]' : Faker.Address.zipCodeFormat(0),
18
- 'input[name*=state]' : Faker.Address.usState(),
19
- 'input[name*=job_title]' : Faker.Company.catchPhrase(),
20
- 'input[name*=intent]' : Faker.Lorem.sentence(),
21
- 'input[name*=income], input[name*=amount]' : Peteshow.randomNumber(4),
22
- 'input[name*=branch], input[name*=routing]' : '400001',
23
- 'input[name*=card_type_cd]' : '001',
24
- 'input[name*=card_number]' : '4111111111111111',
25
- 'input[name*=cvv]' : '123'
4
+ 'input[type=password]' : 'password',
5
+ 'input[type=text]' : Peteshow.randomLetters(8),
6
+ 'input[type=email]' : Peteshow.randomEmail(),
7
+ 'input[type=number]' : Peteshow.randomNumber(8),
8
+ 'input[type=date]' : Peteshow.randomDate(),
9
+ 'input[name*=email]' : Peteshow.randomEmail(),
10
+ 'input[name*=number]' : Peteshow.randomNumber(8),
11
+ 'input[class*=number]' : Peteshow.randomNumber(8),
12
+ 'input[class*=decimal]' : Peteshow.randomNumber(8),
13
+ 'input[name*=phone]' : Faker.PhoneNumber.phoneNumberFormat(5),
14
+ 'input[name*=first_name]' : Faker.Name.firstName(),
15
+ 'input[name*=last_name]' : Faker.Name.lastName(),
16
+ 'input[name*=company]' : Faker.Company.companyName(),
17
+ 'input[name*=line1]' : Faker.Address.streetName(),
18
+ 'input[name*=street]' : Faker.Address.streetName(),
19
+ 'input[name*=suite]' : Faker.Address.secondaryAddress(),
20
+ 'input[name*=line2]' : Faker.Address.secondaryAddress(),
21
+ 'input[name*=city]' : Faker.Address.city(),
22
+ 'input[name*=zip]' : Faker.Address.zipCodeFormat(0),
23
+ 'input[name*=postal]' : Faker.Address.zipCodeFormat(0),
24
+ 'input[name*=state]' : Faker.Address.usState(),
25
+ 'input[name*=job_title]' : Faker.Company.catchPhrase(),
26
+ 'input[name*=intent]' : Faker.Lorem.sentence(),
27
+ 'input[name*=income]' : Peteshow.randomNumber(4),
28
+ 'input[name*=amount]' : Peteshow.randomNumber(4),
29
+ 'input[name*=branch]' : '400001',
30
+ 'input[name*=routing]' : '400001',
31
+ 'input[name*=card_type_cd]' : '001',
32
+ 'input[name*=card_number]' : '4111111111111111',
33
+ 'input[name*=cvv]' : '123'
26
34
  }
27
35
  }
28
36
 
@@ -67,26 +75,27 @@
67
75
  var key = (typeof e.which == 'number') ? e.which : e.keyCode,
68
76
  code = String.fromCharCode(e.keyCode)
69
77
 
78
+ // modifier keys
70
79
  if(e.ctrlKey) code = 'ctrl_'+code
71
80
  if(e.altKey || (e.originalEvent && e.originalEvent.metaKey)) code = 'alt_'+code
72
81
  if(e.shiftKey) code = 'shift_'+code
73
82
  if($.inArray(e.keyCode, [9,16,17,18, 91, 93, 224]) != -1) return
74
83
  if(e.metaKey) return
75
84
 
76
- if(e.keyCode == 192) { // `
85
+ if(e.keyCode == 192) // `
77
86
  Peteshow.toggle()
78
- }
79
87
 
80
88
  var action = $("[data-command='"+code+"']"),
81
89
  visible = $tools.is(':visible')
82
90
 
83
- if(action.length > 0 && visible) action.click()
91
+ if(action.length > 0 && visible)
92
+ action.click()
84
93
  }
85
94
 
86
95
  initCommands = function() {
87
96
  var base = "<li><a data-command='F' href='#' id='fill-out-forms'>Fill Out Forms</a></li>"
88
97
  base += "<li><a data-command='Q' href='#' id='fill-out-forms-and-submit'>Fill Out and Submit</a></li>"
89
- base += outputLocalStorage()
98
+ base += outputSavedFields()
90
99
  base += "<li><a data-command='H' href='#' id='hide-peteshow'>Hide</a></li>"
91
100
 
92
101
  $div.find($commands).html(_options.commands + base)
@@ -99,13 +108,12 @@
99
108
  [ $toggle, function() { Peteshow.toggle() } ],
100
109
  [ $('#fill-out-forms'), function() { Peteshow.fillOutForms() } ],
101
110
  [ $('#fill-out-forms-and-submit'), function() { Peteshow.fillOutForms(); Peteshow.submitForm() } ],
102
- [ $('#clear-localstorage'), function() { Peteshow.clearLocalStorage() } ],
111
+ [ $('#clear'), function() { Peteshow.clearSaved(); } ],
103
112
  [ $('#hide-peteshow'), function() { Peteshow.hide() } ]
104
113
  ]
105
114
 
106
115
  $.each(commands, function() {
107
116
  var command = $(this)
108
-
109
117
  $(command[0]).on('click', function() {
110
118
  command[1]()
111
119
  return false
@@ -141,10 +149,9 @@
141
149
  })
142
150
 
143
151
  // apply rules
144
- var rules = $.extend(true, getDefaultRules(), _options.rules || {})
145
- reused = {},
146
- ls = Peteshow.getLocalStorage(),
147
- local = (ls != null || ls != undefined) ? ls : {}
152
+ var rules = $.extend(true, getDefaultRules(), _options.rules || {})
153
+ reused = {},
154
+ saved = Peteshow.getSavedFields()
148
155
 
149
156
  // apply value to rule element, if visible and not in ignore list
150
157
  $.each(rules, function(element,v) {
@@ -163,55 +170,67 @@
163
170
  var url = _options.reuse[element]
164
171
 
165
172
  if($(element).length > 0) {
166
- // if element isnt in localstorage, save it in localstorage
167
- if(!(element in local))
168
- reused[element] = $(element).val()
173
+ // if element isnt in saved, save it
174
+ if(!(element in saved)) reused[element] = $(element).val()
169
175
 
170
- // if element is in localstorage and we're not on the reused url, save it in localstorage
171
- if((element in local) && window.location.href.indexOf(url) < 0)
176
+ // if element is saved and we're not on the reused url, save it
177
+ if((element in saved) && window.location.href.indexOf(url) < 0)
172
178
  reused[element] = $(element).val()
173
179
  }
174
180
  })
175
181
 
176
- // save localstorage if found rules to reuse
182
+ // save if found rules to reuse
177
183
  if(!$.isEmptyObject(reused)) {
178
- $.extend(local, reused)
179
-
180
- localStorage.setItem('peteshow', JSON.stringify(local))
184
+ $.extend(saved, reused)
185
+ Peteshow.setSavedFields(JSON.stringify(saved))
181
186
  }
182
187
 
183
- // apply localstorage rule values if they exist and on the right page
184
- if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
185
- $.each(Peteshow.getLocalStorage(), function(element,v) {
188
+ // apply saved rule values if they exist and on the right page
189
+ if(savedFieldsExist()) {
190
+ $.each(Peteshow.getSavedFields(), function(element,v) {
186
191
  var url = _options.reuse[element]
187
-
188
- if(window.location.href.indexOf(url) > -1)
189
- $(element).val(v)
192
+ if(window.location.href.indexOf(url) > -1) $(element).val(v)
190
193
  })
191
-
192
194
  // reinit menu
193
195
  initCommands()
194
196
  }
195
197
  }
196
198
 
197
- outputLocalStorage = function() {
199
+ outputSavedFields = function() {
198
200
  var base = ''
199
- if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
201
+
202
+ if(savedFieldsExist()) {
200
203
  base += "<li class='list'>"
201
204
  base += "<div class='inner'>"
202
- $.each(Peteshow.getLocalStorage(), function(k,v) {
205
+ $.each(Peteshow.getSavedFields(), function(k,v) {
203
206
  base += '<div>' + k + '<span>' + v + '</span></div>'
204
207
  })
205
208
  base += "</div>"
206
209
  base += "</li>"
207
-
208
- base += "<li><a data-command='R' href='#' id='clear-localstorage'>Clear stored</a></li>"
210
+ base += "<li><a data-command='R' href='#' id='clear'>Clear stored</a></li>"
209
211
  }
212
+
210
213
  return base
211
214
  }
212
215
 
213
- Peteshow.getLocalStorage = function() {
214
- return JSON.parse(localStorage.getItem('peteshow'))
216
+ savedFieldsExist = function() {
217
+ var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
218
+ return (saved != undefined || saved != null)
219
+ }
220
+
221
+ Peteshow.setSavedFields = function(data) {
222
+ _options.cookies ? $.cookie('peteshow', data) : localStorage.setItem('peteshow', data)
223
+ }
224
+
225
+ Peteshow.getSavedFields = function() {
226
+ var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
227
+ return (saved != undefined || saved != null) ? JSON.parse(saved) : {}
228
+ }
229
+
230
+ Peteshow.clearSaved = function() {
231
+ Peteshow.clearLocalStorage()
232
+ Peteshow.clearCookies()
233
+ initCommands()
215
234
  }
216
235
 
217
236
  Peteshow.clearLocalStorage = function() {
@@ -219,6 +238,11 @@
219
238
  initCommands()
220
239
  }
221
240
 
241
+ Peteshow.clearCookies = function() {
242
+ $.removeCookie('peteshow')
243
+ initCommands()
244
+ }
245
+
222
246
  randomSelectValue = function(i,select) {
223
247
  var options = $(select).find('option'),
224
248
  filters = _options.filter.toString().replace(new RegExp(',', 'g'), '|'),
data/src/peteshow.js CHANGED
@@ -5,6 +5,7 @@ Peteshow.defaults = {
5
5
  emailDomain : 'example.com',
6
6
  form : '',
7
7
  blur : false,
8
+ cookies : false,
8
9
 
9
10
  rules : {},
10
11
  ignore : [],
@@ -16,14 +17,4 @@ Peteshow.defaults = {
16
17
  events : function(){},
17
18
  }
18
19
 
19
- if (typeof define == 'function'){
20
- define(function(){
21
- return Peteshow;
22
- });
23
-
24
- } else if(typeof module !== 'undefined' && module.exports) {
25
- module.exports = Peteshow;
26
-
27
- } else {
28
- window.Peteshow = Peteshow;
29
- }
20
+ window.Peteshow = Peteshow;
data/tests/index.html CHANGED
@@ -21,6 +21,8 @@
21
21
  <input name='phone' type='text' />
22
22
  <input name='tel' type='tel' >
23
23
  <input name='first_name' type='text /'>
24
+ <input name='middle_name' type='text /'>
25
+ <input name='custom_name' type='text /'>
24
26
  <input name='last_name' type='text /'>
25
27
  <input name='company' type='text /'>
26
28
  <input name='street' type='text /'>
@@ -45,6 +47,7 @@
45
47
 
46
48
  <script src='../vendor/faker.js'></script>
47
49
  <script src='../vendor/jquery.formatdatetime.js'></script>
50
+ <script src='../vendor/jquery.cookie.js'></script>
48
51
 
49
52
  <script src='../src/peteshow.js'></script>
50
53
  <script src='../src/peteshow-core.js'></script>
@@ -55,6 +58,7 @@
55
58
  <script src='./suite/keybindings.js'></script>
56
59
  <script src='./suite/options.js'></script>
57
60
  <script src='./suite/localstorage.js'></script>
61
+ <script src='./suite/cookies.js'></script>
58
62
  </div>
59
63
  </body>
60
64
  </html>
@@ -0,0 +1,60 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Peteshow.js Tests</title>
6
+ <link rel='stylesheet' href='../vendor/qunit/qunit.css'>
7
+ <link rel='stylesheet' href='../src/css/peteshow.css'>
8
+ <style>
9
+ body { padding-left: 200px; }
10
+ input[name=first_name] { border: 2px solid red; }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <form name='random'>
15
+ <input name='password' type='password' />
16
+ <input name='text' type='text' />
17
+ <input name='email' type='email' />
18
+ <input name='email2' type='text' />
19
+ <input name='number' type='number' >
20
+ <input name='date ' type='date' >
21
+ <input name='number' type='text' >
22
+ <input name='phone' type='text' />
23
+ <input name='tel' type='tel' >
24
+ <input name='first_name' type='text /'>
25
+ <input name='middle_name' type='text /'>
26
+ <input name='custom_name' type='text /'>
27
+ <input name='last_name' type='text /'>
28
+ <input name='company' type='text /'>
29
+ <input name='street' type='text /'>
30
+ <input name='line2' type='text /'>
31
+ <input name='city' type='text /'>
32
+ <input name='zip' type='text /'>
33
+ <input name='county' type='text /'>
34
+ <input name='postal' type='text /'>
35
+ <input name='state' type='text /'>
36
+ <input name='job_title' type='text /'>
37
+ <input name='intent' type='text /'>
38
+ <input name='income' type='text /'>
39
+ <input name='routing' type='text /'>
40
+ <input name='card_type_cd' type='text /'>
41
+ <input name='card_number' type='text /'>
42
+ <input name='cvv' type='text /'>
43
+ </form>
44
+
45
+ <script src='../vendor/qunit/jquery.js'></script>
46
+ <script src='../vendor/faker.js'></script>
47
+ <script src='../vendor/jquery.formatdatetime.js'></script>
48
+ <script src='../vendor/jquery.cookie.js'></script>
49
+ <script src='../src/peteshow.js'></script>
50
+ <script src='../src/peteshow-core.js'></script>
51
+ <script src='../src/peteshow-helpers.js'></script>
52
+
53
+ <script>
54
+ Peteshow.init({
55
+ cookies: true,
56
+ reuse: { 'input[name*=first_name]': '/tests' }
57
+ })
58
+ </script>
59
+ </body>
60
+ </html>
@@ -0,0 +1,36 @@
1
+ module('reusing values from cookies', {
2
+ setup: function() {
3
+ Peteshow.init({
4
+ cookies : true,
5
+ reuse : {
6
+ 'input[name*=first_name]' : '/tests',
7
+ }
8
+ });
9
+ },
10
+ teardown: function() {
11
+ Peteshow.destroy();
12
+ Peteshow.clearCookies();
13
+ }
14
+ });
15
+
16
+ test('fields are saved into cookies', function() {
17
+ Peteshow.fillOutForms(); // store initial values
18
+
19
+ var field = 'input[name*=first_name]',
20
+ input = $(field).val();
21
+
22
+ // field was saved
23
+ ok($.cookie('peteshow') != null, 'cookie isnt null')
24
+
25
+ var saved = Peteshow.getSavedFields();
26
+
27
+ // saved values equal the initial values
28
+ equal(saved[field], input, 'saved value equals initial input');
29
+
30
+ // clear form and re-fill
31
+ $(field).val('');
32
+ Peteshow.fillOutForms();
33
+
34
+ // value is reused on field
35
+ equal($(field).val(), saved[field], 'reused value equals initial input')
36
+ });
data/tests/suite/core.js CHANGED
@@ -1,7 +1,17 @@
1
1
  module('core plugin', {
2
2
  setup: function() {
3
+ NUMBER_REGEX = /^[0-9]*$/
4
+ TEXT_REGEX = /^[a-zA-Z0-9.',\/_ -]+$/
5
+ EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i
6
+ DATE_REGEX = /^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$/
7
+ PHONE_NUMBER_REGEX = /\(\d{3}\)\d{3}-\d{4}/
8
+
3
9
  Peteshow.init({
4
- rules : {'input[name*=zip]' : '60611', }
10
+ rules : {
11
+ 'input[name*=zip]' : '60611',
12
+ 'input[name*=middle_name]' : Faker.Name.firstName(),
13
+ 'input[name*=custom_name]' : function() { return 'Custom' },
14
+ }
5
15
  });
6
16
  },
7
17
  teardown: function() {
@@ -13,19 +23,9 @@ test('should have been added to the dom', function() {
13
23
  equal(1, $('#peteshow').length, 'peteshow exists')
14
24
  });
15
25
 
16
- test('should have valid values after filling out forms', function() {
26
+ test('should have valid values from defaults after filling out forms', function() {
17
27
  Peteshow.fillOutForms();
18
28
 
19
- NUMBER_REGEX = /^[0-9]*$/
20
- TEXT_REGEX = /^[a-zA-Z0-9.',\/_ -]+$/
21
- EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i
22
- DATE_REGEX = /^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$/
23
- PHONE_NUMBER_REGEX = /\(\d{3}\)\d{3}-\d{4}/
24
-
25
- // from plugin
26
- equal('60611', $('input[name*=zip]').val(), 'rule loaded from plugin, string');
27
-
28
- // from defaults
29
29
  var fields = {
30
30
  'input[type=password]' : 'password',
31
31
  'input[type=text]' : TEXT_REGEX,
@@ -50,10 +50,16 @@ test('should have valid values after filling out forms', function() {
50
50
  }
51
51
 
52
52
  $.each(fields, function(k,v) {
53
- if(v.hasOwnProperty('source')) { // is a regex
53
+ if(v.hasOwnProperty('source'))
54
54
  equal(true, v.test($(k).val()), 'testing ' + k + ' regex');
55
- } else {
55
+ else
56
56
  equal(v, $(k).val(), 'testing ' + k + ' string');
57
- }
58
57
  });
59
58
  });
59
+
60
+ test('should have valid values from plugin after filling out forms', function() {
61
+ Peteshow.fillOutForms();
62
+
63
+ equal('60611', $('input[name*=zip]').val(), 'rule loaded from plugin, string');
64
+ equal('Custom', $('input[name*=custom_name]').val(), 'rule loaded from plugin, function');
65
+ });
@@ -1,19 +1,29 @@
1
1
  module('helpers');
2
2
 
3
- test('peteshow functions exist', function() {
3
+ test('should be defined on window', function() {
4
4
  equal(true, $.isPlainObject(Peteshow), 'window.Peteshow exists');
5
+ });
5
6
 
6
- // helpers exist
7
- equal(true, $.isFunction(Peteshow.randomChars), 'randomChars helper is a function');
8
- equal(true, $.isFunction(Peteshow.randomLetters), 'randomLetershelper is a function');
9
- equal(true, $.isFunction(Peteshow.randomNumberRange), 'randomNumberRange helper is a function');
10
- equal(true, $.isFunction(Peteshow.randomNumber), 'randomNumber helper is a function');
11
- equal(true, $.isFunction(Peteshow.randomDate), 'randomDate helper is a function');
12
- equal(true, $.isFunction(Peteshow.randomEmail), 'randomEmail helper is a function');
13
- equal(true, $.isFunction(Peteshow.formatDate), 'formatDate helper is a function');
7
+ // replace this nonsense with functional tests
8
+ test('should exist in peteshow', function() {
9
+ equal(true, $.isFunction(Peteshow.randomChars), 'randomChars is a function');
10
+ equal(true, $.isFunction(Peteshow.randomLetters), 'randomLetters is a function');
11
+ equal(true, $.isFunction(Peteshow.randomNumberRange), 'randomNumberRange is a function');
12
+ equal(true, $.isFunction(Peteshow.randomNumber), 'randomNumber is a function');
13
+ equal(true, $.isFunction(Peteshow.randomDate), 'randomDate is a function');
14
+ equal(true, $.isFunction(Peteshow.randomEmail), 'randomEmail is a function');
15
+ equal(true, $.isFunction(Peteshow.formatDate), 'formatDate is a function');
14
16
 
15
- // core exists
16
17
  equal(true, $.isFunction(Peteshow.init), 'init helper is a function');
18
+ equal(true, $.isFunction(Peteshow.hide), 'hide helper is a function');
19
+ equal(true, $.isFunction(Peteshow.toggle), 'toggle helper is a function');
20
+ equal(true, $.isFunction(Peteshow.show), 'show helper is a function');
21
+ equal(true, $.isFunction(Peteshow.destroy), 'destroy helper is a function');
17
22
  equal(true, $.isFunction(Peteshow.fillOutForms), 'fillOutForms helper is a function');
18
23
  equal(true, $.isFunction(Peteshow.submitForm), 'submitForm helper is a function');
24
+ equal(true, $.isFunction(Peteshow.clearLocalStorage), 'clearLocalStorage helper is a function');
25
+ equal(true, $.isFunction(Peteshow.clearCookies), 'clearCookies helper is a function');
26
+ equal(true, $.isFunction(Peteshow.clearSaved), 'clearSaved helper is a function');
27
+ equal(true, $.isFunction(Peteshow.getSavedFields), 'getSavedFields helper is a function');
28
+ equal(true, $.isFunction(Peteshow.setSavedFields), 'setSavedFields helper is a function');
19
29
  });
@@ -21,13 +21,14 @@ test('should fill out forms when F is pressed', function() {
21
21
  ok($('form input').first().val() != '')
22
22
  });
23
23
 
24
- test('should clear localstorage when R is pressed', function() {
24
+ test('should clear saved fields when R is pressed', function() {
25
25
  var event = $.Event('keydown');
26
26
 
27
27
  event.keyCode = 82;
28
28
  $(document).trigger(event);
29
29
 
30
30
  ok(localStorage.getItem('peteshow') == null)
31
+ ok($.cookie('peteshow') == null)
31
32
  });
32
33
 
33
34
  test('should fill out forms and submit when Q is pressed', function() {
@@ -1,6 +1,35 @@
1
- module('localstorage');
2
-
3
- test('reusing values from localstorage', function() {
4
- ok(true)
1
+ module('reusing values from localstorage', {
2
+ setup: function() {
3
+ Peteshow.init({
4
+ reuse : {
5
+ 'input[name*=first_name]' : '/tests',
6
+ }
7
+ });
8
+ },
9
+ teardown: function() {
10
+ Peteshow.destroy();
11
+ Peteshow.clearLocalStorage();
12
+ }
5
13
  });
6
14
 
15
+ test('fields are saved into localstorage', function() {
16
+ Peteshow.fillOutForms(); // store initial values
17
+
18
+ var field = 'input[name*=first_name]',
19
+ input = $(field).val();
20
+
21
+ // field was saved
22
+ ok(localStorage.getItem('peteshow') != null, 'localstorge isnt null')
23
+
24
+ var saved = Peteshow.getSavedFields();
25
+
26
+ // saved values equal the initial values
27
+ equal(saved[field], input, 'saved value equals initial input');
28
+
29
+ // clear form and re-fill
30
+ $(field).val('');
31
+ Peteshow.fillOutForms();
32
+
33
+ // value is reused on field
34
+ equal($(field).val(), saved[field], 'reused value equals initial input')
35
+ });
@@ -24,7 +24,7 @@ test('should set email options', function() {
24
24
  test('should blur after filling out if true', function() {
25
25
  expect(1);
26
26
 
27
- $('input[type=email]').on('blur', function() {
27
+ $('input[name*=first_name]').on('blur', function() {
28
28
  ok(true, 'blur functionality works');
29
29
  });
30
30
 
@@ -0,0 +1,117 @@
1
+ /*!
2
+ * jQuery Cookie Plugin v1.4.1
3
+ * https://github.com/carhartl/jquery-cookie
4
+ *
5
+ * Copyright 2006, 2014 Klaus Hartl
6
+ * Released under the MIT license
7
+ */
8
+ (function (factory) {
9
+ if (typeof define === 'function' && define.amd) {
10
+ // AMD
11
+ define(['jquery'], factory);
12
+ } else if (typeof exports === 'object') {
13
+ // CommonJS
14
+ factory(require('jquery'));
15
+ } else {
16
+ // Browser globals
17
+ factory(jQuery);
18
+ }
19
+ }(function ($) {
20
+
21
+ var pluses = /\+/g;
22
+
23
+ function encode(s) {
24
+ return config.raw ? s : encodeURIComponent(s);
25
+ }
26
+
27
+ function decode(s) {
28
+ return config.raw ? s : decodeURIComponent(s);
29
+ }
30
+
31
+ function stringifyCookieValue(value) {
32
+ return encode(config.json ? JSON.stringify(value) : String(value));
33
+ }
34
+
35
+ function parseCookieValue(s) {
36
+ if (s.indexOf('"') === 0) {
37
+ // This is a quoted cookie as according to RFC2068, unescape...
38
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
39
+ }
40
+
41
+ try {
42
+ // Replace server-side written pluses with spaces.
43
+ // If we can't decode the cookie, ignore it, it's unusable.
44
+ // If we can't parse the cookie, ignore it, it's unusable.
45
+ s = decodeURIComponent(s.replace(pluses, ' '));
46
+ return config.json ? JSON.parse(s) : s;
47
+ } catch(e) {}
48
+ }
49
+
50
+ function read(s, converter) {
51
+ var value = config.raw ? s : parseCookieValue(s);
52
+ return $.isFunction(converter) ? converter(value) : value;
53
+ }
54
+
55
+ var config = $.cookie = function (key, value, options) {
56
+
57
+ // Write
58
+
59
+ if (arguments.length > 1 && !$.isFunction(value)) {
60
+ options = $.extend({}, config.defaults, options);
61
+
62
+ if (typeof options.expires === 'number') {
63
+ var days = options.expires, t = options.expires = new Date();
64
+ t.setTime(+t + days * 864e+5);
65
+ }
66
+
67
+ return (document.cookie = [
68
+ encode(key), '=', stringifyCookieValue(value),
69
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
70
+ options.path ? '; path=' + options.path : '',
71
+ options.domain ? '; domain=' + options.domain : '',
72
+ options.secure ? '; secure' : ''
73
+ ].join(''));
74
+ }
75
+
76
+ // Read
77
+
78
+ var result = key ? undefined : {};
79
+
80
+ // To prevent the for loop in the first place assign an empty array
81
+ // in case there are no cookies at all. Also prevents odd result when
82
+ // calling $.cookie().
83
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
84
+
85
+ for (var i = 0, l = cookies.length; i < l; i++) {
86
+ var parts = cookies[i].split('=');
87
+ var name = decode(parts.shift());
88
+ var cookie = parts.join('=');
89
+
90
+ if (key && key === name) {
91
+ // If second argument (value) is a function it's a converter...
92
+ result = read(cookie, value);
93
+ break;
94
+ }
95
+
96
+ // Prevent storing a cookie that we couldn't decode.
97
+ if (!key && (cookie = read(cookie)) !== undefined) {
98
+ result[name] = cookie;
99
+ }
100
+ }
101
+
102
+ return result;
103
+ };
104
+
105
+ config.defaults = {};
106
+
107
+ $.removeCookie = function (key, options) {
108
+ if ($.cookie(key) === undefined) {
109
+ return false;
110
+ }
111
+
112
+ // Must not alter options, thus extending a fresh object...
113
+ $.cookie(key, '', $.extend({}, options, { expires: -1 }));
114
+ return !$.cookie(key);
115
+ };
116
+
117
+ }));