forked from assaf/zombie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_test.coffee
126 lines (103 loc) · 3.74 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
{ assert, brains, Browser } = require("./helpers")
test = (scope)->
describe "initial", ->
before (done)->
Browser.visit "/storage", (error, browser)=>
@storage = scope(browser.window)
done(error)
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", ->
before (done)->
Browser.visit "/storage", (error, browser)=>
@storage = scope(browser.window)
@storage.setItem "is", "hungry"
@storage.setItem "wants", "brains"
done(error)
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", ->
before (done)->
Browser.visit "/storage", (error, 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(error)
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", ->
before (done)->
Browser.visit "/storage", (error, browser)=>
@storage = scope(browser.window)
@storage.setItem "is", "hungry"
@storage.setItem "wants", "brains"
@storage.removeItem "is"
done(error)
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", ->
before (done)->
Browser.visit "/storage", (error, browser)=>
@storage = scope(browser.window)
@storage.setItem "is", "hungry"
@storage.setItem "wants", "brains"
@storage.clear()
done(error)
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", ->
before (done)->
Browser.visit "/storage", (error, browser)=>
@storage = scope(browser.window)
@storage.setItem "null", null
done(error)
it "should store that item", ->
assert.equal @storage.length, 1
it "should return null for key", ->
assert.equal @storage.getItem("null"), null
describe "Storage", ->
before (done)->
brains.get "/storage", (req, res)->
res.send ""
brains.ready done
describe "local storage", ->
test.call this, (window)->
window.localStorage
describe "session storage", ->
test.call this, (window)->
window.sessionStorage