|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +const testPackage = require('../../helpers/test-package'); |
| 9 | +const Dgeni = require('dgeni'); |
| 10 | + |
| 11 | +describe('checkForUnusedExampleRegions', () => { |
| 12 | + var processor, exampleMap; |
| 13 | + |
| 14 | + beforeEach(function() { |
| 15 | + const dgeni = new Dgeni([testPackage('examples-package', true)]); |
| 16 | + const injector = dgeni.configureInjector(); |
| 17 | + exampleMap = injector.get('exampleMap'); |
| 18 | + processor = injector.get('checkForUnusedExampleRegions'); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('$process()', () => { |
| 22 | + it('should error if there is a named example region which has not been used', () => { |
| 23 | + exampleMap['examples'] = { |
| 24 | + 'some/file': { |
| 25 | + regions: { |
| 26 | + '': {id: 'some/file#'}, |
| 27 | + 'used': {id: 'some/file#used', usedInDoc: {}}, |
| 28 | + 'not-used': {id: 'some/file#not-used'}, |
| 29 | + } |
| 30 | + } |
| 31 | + }; |
| 32 | + expect(() => processor.$process()) |
| 33 | + .toThrowError('There is 1 unused example region:\n - some/file#not-used'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should not error if there are no example folders', () => { |
| 37 | + expect(() => processor.$process()).not.toThrowError(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should not error if there are no example files', () => { |
| 41 | + exampleMap['examples'] = {}; |
| 42 | + expect(() => processor.$process()).not.toThrowError(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should not error if there are no example regions', () => { |
| 46 | + exampleMap['examples'] = { |
| 47 | + 'some/file': { |
| 48 | + regions: {}, |
| 49 | + }, |
| 50 | + }; |
| 51 | + expect(() => processor.$process()).not.toThrowError(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should not error if there are no named example regions', () => { |
| 55 | + exampleMap['examples'] = { |
| 56 | + 'some/file': { |
| 57 | + regions: { |
| 58 | + '': {id: 'some/file#'}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }; |
| 62 | + expect(() => processor.$process()).not.toThrowError(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should not error if there are no unused named example regions', () => { |
| 66 | + exampleMap['examples'] = { |
| 67 | + 'some/file': { |
| 68 | + regions: { |
| 69 | + '': {id: 'some/file#'}, |
| 70 | + 'used': {id: 'some/file#used', usedInDoc: {}}, |
| 71 | + } |
| 72 | + } |
| 73 | + }; |
| 74 | + expect(() => processor.$process()).not.toThrowError(); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments