|
| 1 | +/** |
| 2 | + * This source file is part of the Swift.org open source project |
| 3 | + * |
| 4 | + * Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 5 | + * Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + * |
| 7 | + * See https://swift.org/LICENSE.txt for license information |
| 8 | + * See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +*/ |
| 10 | + |
| 11 | +import AppStore from 'docc-render/stores/AppStore'; |
| 12 | +import { filterInactiveReferences } from 'docc-render/utils/references'; |
| 13 | + |
| 14 | +const aa = { |
| 15 | + identifier: 'doc://A/documentation/A/a', |
| 16 | + url: '/documentation/A/a', |
| 17 | + title: 'A.A', |
| 18 | + type: 'topic', |
| 19 | +}; |
| 20 | +const ab = { |
| 21 | + identifier: 'doc://A/documentation/A/b', |
| 22 | + url: '/documentation/A/b', |
| 23 | + title: 'A.B', |
| 24 | + type: 'topic', |
| 25 | +}; |
| 26 | +const bb = { |
| 27 | + identifier: 'doc://B/documentation/B/b', |
| 28 | + url: '/documentation/B/b', |
| 29 | + title: 'B.B', |
| 30 | + type: 'topic', |
| 31 | +}; |
| 32 | +const bbb = { |
| 33 | + identifier: 'doc://BB/documentation/BB/b', |
| 34 | + url: '/documentation/BB/b#b', |
| 35 | + title: 'BB.B', |
| 36 | + type: 'section', |
| 37 | +}; |
| 38 | +const c = { |
| 39 | + identifier: 'https://abc.dev', |
| 40 | + url: 'https://abc.dev', |
| 41 | + title: 'C', |
| 42 | + type: 'link', |
| 43 | +}; |
| 44 | + |
| 45 | +const references = { |
| 46 | + [aa.identifier]: aa, |
| 47 | + [ab.identifier]: ab, |
| 48 | + [bb.identifier]: bb, |
| 49 | + [bbb.identifier]: bbb, |
| 50 | + [c.identifier]: c, |
| 51 | +}; |
| 52 | + |
| 53 | +describe('filterInactiveReferences', () => { |
| 54 | + it('does not filter any refs when `includedArchiveIdentifiers` is empty', () => { |
| 55 | + AppStore.setIncludedArchiveIdentifiers([]); |
| 56 | + expect(filterInactiveReferences(references)).toEqual(references); |
| 57 | + }); |
| 58 | + |
| 59 | + it('does not filter any refs when `includedArchiveIdentifiers` includes all ref archives', () => { |
| 60 | + AppStore.setIncludedArchiveIdentifiers(['A', 'B', 'BB']); |
| 61 | + expect(filterInactiveReferences(references)).toEqual(references); |
| 62 | + }); |
| 63 | + |
| 64 | + it('removes `url` from non-external refs that aren\'t part of included archive', () => { |
| 65 | + AppStore.setIncludedArchiveIdentifiers(['B']); |
| 66 | + const filteredRefs = filterInactiveReferences(references); |
| 67 | + |
| 68 | + expect(Object.keys(filteredRefs)).toEqual(Object.keys(references)); |
| 69 | + |
| 70 | + expect(filteredRefs[aa.identifier].url).toBeFalsy(); |
| 71 | + expect(filteredRefs[ab.identifier].url).toBeFalsy(); |
| 72 | + expect(filteredRefs[bb.identifier].url).toBe(bb.url); |
| 73 | + expect(filteredRefs[bbb.identifier].url).toBeFalsy(); |
| 74 | + expect(filteredRefs[c.identifier].url).toBe(c.url); |
| 75 | + }); |
| 76 | +}); |
0 commit comments