forked from angular-ui/bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackedMap.spec.js
52 lines (41 loc) · 1.57 KB
/
stackedMap.spec.js
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
describe('stacked map', function() {
var stackedMap;
beforeEach(module('ui.bootstrap.modal'));
beforeEach(inject(function ($$stackedMap) {
stackedMap = $$stackedMap.createNew();
}));
it('should add and remove objects by key', function() {
stackedMap.add('foo', 'foo_value');
expect(stackedMap.length()).toEqual(1);
expect(stackedMap.get('foo').key).toEqual('foo');
expect(stackedMap.get('foo').value).toEqual('foo_value');
stackedMap.remove('foo');
expect(stackedMap.length()).toEqual(0);
expect(stackedMap.get('foo')).toBeUndefined();
});
it('should support listing keys', function() {
stackedMap.add('foo', 'foo_value');
stackedMap.add('bar', 'bar_value');
expect(stackedMap.keys()).toEqual(['foo', 'bar']);
});
it('should get topmost element', function() {
stackedMap.add('foo', 'foo_value');
stackedMap.add('bar', 'bar_value');
expect(stackedMap.length()).toEqual(2);
expect(stackedMap.top().key).toEqual('bar');
expect(stackedMap.length()).toEqual(2);
});
it('should remove topmost element', function() {
stackedMap.add('foo', 'foo_value');
stackedMap.add('bar', 'bar_value');
expect(stackedMap.removeTop().key).toEqual('bar');
expect(stackedMap.removeTop().key).toEqual('foo');
});
it('should preserve semantic of an empty stackedMap', function() {
expect(stackedMap.length()).toEqual(0);
expect(stackedMap.top()).toBeUndefined();
});
it('should ignore removal of non-existing elements', function() {
expect(stackedMap.remove('non-existing')).toBeUndefined();
});
});