Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected] [email protected]
17
*/
18
19
describe('ResourceMap', function() {
20
21
var ResourceMap = require('../lib/ResourceMap');
22
var Resource = require('../lib/resource/Resource');
23
var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');
24
25
it('should intialize from a list', function() {
26
var a, b;
27
var map = new ResourceMap([
28
a = new Resource('a'),
29
b = new Resource('b')
30
]);
31
32
expect(map.getResource('Resource', 'a')).toBe(a);
33
expect(map.getResource('Resource', 'b')).toBe(b);
34
expect(map.getResource('Resource', 'c')).toBe(undefined);
35
expect(map.getAllResources()).toEqual([a, b]);
36
});
37
38
it('should return elements from empty map', function() {
39
var map = new ResourceMap([]);
40
expect(map.getResource('JS', 'a')).toBe(undefined);
41
});
42
43
it('should add elements', function() {
44
var a, b;
45
var map = new ResourceMap([
46
a = new Resource('a')
47
]);
48
map.addResource(b = new Resource('b'));
49
50
expect(map.getResource('Resource', 'b')).toBe(b);
51
expect(map.getAllResources()).toEqual([a, b]);
52
});
53
54
it('should update elements', function() {
55
var a1, a2;
56
var map = new ResourceMap([
57
a1 = new Resource('a')
58
]);
59
map.updateResource(a1, a2 = new Resource('a'));
60
61
expect(map.getResource('Resource', 'a')).toBe(a2);
62
});
63
64
it('should remove elements', function() {
65
var a, b;
66
var map = new ResourceMap([
67
a = new Resource('a'),
68
b = new Resource('b')
69
]);
70
map.removeResource(b);
71
expect(map.getResource('Resource', 'b')).toBe(undefined);
72
expect(map.getAllResources()).toEqual([a]);
73
expect(map.getAllResourcesByType('Resource')).toEqual([a]);
74
});
75
76
it('should get all resources by type', function() {
77
var a, b, pa, pb;
78
var map = new ResourceMap([
79
a = new Resource('a'),
80
b = new Resource('b'),
81
pa = new ProjectConfiguration('pa.json'),
82
pb = new ProjectConfiguration('pb.json')
83
]);
84
expect(map.getAllResourcesByType('ProjectConfiguration')).toEqual([pa, pb]);
85
expect(map.getAllResourcesByType('Resource')).toEqual([a, b]);
86
});
87
88
it('should get all resources by type', function() {
89
var a, b, pa, pb;
90
var map = new ResourceMap([
91
a = new Resource('a/a.js'),
92
b = new Resource('b/b.js'),
93
pa = new ProjectConfiguration('a/package.json', {})
94
]);
95
expect(map.getConfigurationByPath(a.path)).toBe(pa);
96
pb = new ProjectConfiguration('b/package.json', {});
97
map.addResource(pb);
98
expect(map.getConfigurationForResource(b)).toBe(pb);
99
});
100
});
101
102