This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 520
/
storage_test.coffee
134 lines (105 loc) · 3.79 KB
/
storage_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{ assert, Browser } = require("./helpers")
test = (scope)->
describe "initial", ->
storage = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
done()
it "should start with no keys", ->
assert.equal storage.length, 0
it "should handle key() with no key", ->
assert !storage.key(1)
it "should handle getItem() with no item", ->
it assert !storage.getItem("nosuch")
it "should handle removeItem() with no item", ->
assert.doesNotThrow ->
storage.removeItem("nosuch")
it "should handle clear() with no items", ->
assert.doesNotThrow ->
storage.clear()
describe "add some items", ->
storage = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
done()
it "should count all items in length", ->
assert.equal storage.length, 2
it "should make key available", ->
keys = [storage.key(0), storage.key(1)].sort()
assert.deepEqual keys, ["is", "wants"]
it "should make value available", ->
assert.equal storage.getItem("is"), "hungry"
assert.equal storage.getItem("wants"), "brains"
describe "change an item", ->
storage = keys = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
storage.setItem "is", "dead"
keys = [storage.key(0), storage.key(1)].sort()
done()
it "should leave length intact", ->
assert.equal storage.length, 2
it "should keep key position", ->
assert.deepEqual [storage.key(0), storage.key(1)].sort(), keys
it "should change value", ->
assert.equal storage.getItem("is"), "dead"
it "should not change other values", ->
assert.equal storage.getItem("wants"), "brains"
describe "remove an item", ->
storage = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
storage.removeItem "is"
done()
it "should drop item from length", ->
assert.equal storage.length, 1
it "should forget key", ->
assert.equal storage.key(0), "wants"
assert !storage.key(1)
it "should forget value", ->
assert !storage.getItem("is")
assert.equal storage.getItem("wants"), "brains"
describe "clean all items", ->
storage = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
storage.clear()
done()
it "should reset length to zero", ->
assert.equal storage.length, 0
it "should forget all keys", ->
assert !storage.key(0)
it "should forget all values", ->
assert !storage.getItem("is")
assert !storage.getItem("wants")
describe "store null", ->
storage = null
before (done)->
Browser.visit "http://localhost:3003/storage", (_, browser)->
storage = scope(browser.window)
storage.setItem "null", null
done()
it "should store that item", ->
assert.equal storage.length, 1
it "should return null for key", ->
assert.equal storage.getItem("null"), null
describe "Storage", ->
describe "local storage", ->
test.call this, (window)->
window.localStorage
describe "session storage", ->
test.call this, (window)->
window.sessionStorage