react / wstein / node_modules / jest-cli / node_modules / node-haste / __tests__ / ResourceMap-test.js
80668 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*15* @emails [email protected] [email protected]16*/1718describe('ResourceMap', function() {1920var ResourceMap = require('../lib/ResourceMap');21var Resource = require('../lib/resource/Resource');22var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');2324it('should intialize from a list', function() {25var a, b;26var map = new ResourceMap([27a = new Resource('a'),28b = new Resource('b')29]);3031expect(map.getResource('Resource', 'a')).toBe(a);32expect(map.getResource('Resource', 'b')).toBe(b);33expect(map.getResource('Resource', 'c')).toBe(undefined);34expect(map.getAllResources()).toEqual([a, b]);35});3637it('should return elements from empty map', function() {38var map = new ResourceMap([]);39expect(map.getResource('JS', 'a')).toBe(undefined);40});4142it('should add elements', function() {43var a, b;44var map = new ResourceMap([45a = new Resource('a')46]);47map.addResource(b = new Resource('b'));4849expect(map.getResource('Resource', 'b')).toBe(b);50expect(map.getAllResources()).toEqual([a, b]);51});5253it('should update elements', function() {54var a1, a2;55var map = new ResourceMap([56a1 = new Resource('a')57]);58map.updateResource(a1, a2 = new Resource('a'));5960expect(map.getResource('Resource', 'a')).toBe(a2);61});6263it('should remove elements', function() {64var a, b;65var map = new ResourceMap([66a = new Resource('a'),67b = new Resource('b')68]);69map.removeResource(b);70expect(map.getResource('Resource', 'b')).toBe(undefined);71expect(map.getAllResources()).toEqual([a]);72expect(map.getAllResourcesByType('Resource')).toEqual([a]);73});7475it('should get all resources by type', function() {76var a, b, pa, pb;77var map = new ResourceMap([78a = new Resource('a'),79b = new Resource('b'),80pa = new ProjectConfiguration('pa.json'),81pb = new ProjectConfiguration('pb.json')82]);83expect(map.getAllResourcesByType('ProjectConfiguration')).toEqual([pa, pb]);84expect(map.getAllResourcesByType('Resource')).toEqual([a, b]);85});8687it('should get all resources by type', function() {88var a, b, pa, pb;89var map = new ResourceMap([90a = new Resource('a/a.js'),91b = new Resource('b/b.js'),92pa = new ProjectConfiguration('a/package.json', {})93]);94expect(map.getConfigurationByPath(a.path)).toBe(pa);95pb = new ProjectConfiguration('b/package.json', {});96map.addResource(pb);97expect(map.getConfigurationForResource(b)).toBe(pb);98});99});100101102