UNPKG

bonsai-analyzer

Version:
65 lines (60 loc) 2.62 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _getCollapsableParentOf = _interopRequireDefault(require("../getCollapsableParentOf")); var _getExtendedModulesById = _interopRequireDefault(require("../getExtendedModulesById")); var _defaults = require("../../__test_helpers__/defaults"); const ENTRY_ZERO = (0, _defaults.defaultModule)({ id: 0, reasons: [] }); const ENTRY_ONE = (0, _defaults.defaultModule)({ id: 1, reasons: [] }); const ZERO_A = (0, _defaults.defaultModule)({ id: 2, reasons: [(0, _defaults.reasonFromModule)(ENTRY_ZERO)] }); const COMMON = (0, _defaults.defaultModule)({ id: 3, reasons: [(0, _defaults.reasonFromModule)(ENTRY_ZERO), (0, _defaults.reasonFromModule)(ENTRY_ONE)] }); const COMMON_UTIL = (0, _defaults.defaultModule)({ id: 4, reasons: [(0, _defaults.reasonFromModule)(COMMON)] }); const BIG_MODULE = (0, _defaults.defaultModule)({ id: 5, reasons: [(0, _defaults.reasonFromModule)(ZERO_A), (0, _defaults.reasonFromModule)(COMMON)] }); const ENTRY_ONE_A = (0, _defaults.defaultModule)({ id: 600, reasons: [(0, _defaults.reasonFromModule)(ENTRY_ONE)] }); const ENTRY_ONE_B = (0, _defaults.defaultModule)({ id: 300, reasons: [(0, _defaults.reasonFromModule)(ENTRY_ONE_A)] }); const MODULES = [ENTRY_ZERO, ENTRY_ONE, ZERO_A, COMMON, COMMON_UTIL, BIG_MODULE, ENTRY_ONE_A, ENTRY_ONE_B]; const modulesById = (0, _getExtendedModulesById.default)(MODULES); describe('getCollapsableParentOf', () => { it('should return null when the requested moduleid is not in the map', () => { expect((0, _getCollapsableParentOf.default)(modulesById, 'foo')).toBeNull(); }); it('should return null when the requested module is not required by anything', () => { expect((0, _getCollapsableParentOf.default)(modulesById, ENTRY_ZERO.id)).toBeNull(); }); it('should return null when many things require this, but it has no children', () => { expect((0, _getCollapsableParentOf.default)(modulesById, BIG_MODULE.id)).toBeNull(); }); it('should be the collapsable parent when many things require this, and it has children', () => { const collapsable = (0, _getCollapsableParentOf.default)(modulesById, COMMON.id); expect(collapsable).not.toBeNull(); expect(collapsable).toEqual(expect.objectContaining(COMMON)); }); it('should travel up to find the collapsable parent', () => { const collapsable = (0, _getCollapsableParentOf.default)(modulesById, COMMON_UTIL.id); expect(collapsable).not.toBeNull(); expect(collapsable).toEqual(expect.objectContaining(COMMON)); }); });