Warning, /firebird/firebird-ng/src/lib-root-geometry/root-geo-navigation.spec.ts is written in an unsupported language. File is not indexed.
0001 /**
0002 * @date Created on July 10, 2024
0003 * @author Dmitry Romanov
0004 *
0005 * @license This file is part of Firebird display, which is released under a license agreement
0006 * available in the LICENSE file located in the root directory of this project source tree. This
0007 * file is subject to that license and is intended to be used in accordance with it.
0008 *
0009 * @summary Unit tests for CERN ROOT geometry navigation functions
0010 */
0011
0012 import { walkGeoNodes, GeoNodeWalkCallback, findGeoNodes} from './root-geo-navigation';
0013
0014 describe('walkGeoNodes', () => {
0015 let mockCallback: jasmine.Spy<GeoNodeWalkCallback>;
0016 const rootNode = {
0017 fName: "Root",
0018 fVolume: {
0019 fNodes: {
0020 arr: [
0021 { fName: "Child1", fVolume: { fNodes: { arr: [{ fName: "GrandChild1", fVolume: { fNodes: { arr: [] } } }] } } },
0022 { fName: "Child2", fVolume: { fNodes: { arr: [] } } }
0023 ]
0024 }
0025 }
0026 };
0027
0028 beforeEach(() => {
0029 mockCallback = jasmine.createSpy('GeoNodeWalkCallback').and.returnValue(true);;
0030 });
0031
0032 it('should not traverse beyond the specified max level', () => {
0033 walkGeoNodes(rootNode, mockCallback, 1);
0034 expect(mockCallback.calls.count()).toEqual(3); // Root, Child1, Child2
0035 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Root" }), 'Root', 0);
0036 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Child1" }), 'Root/Child1', 1);
0037 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Child2" }), 'Root/Child2', 1);
0038 });
0039
0040 it('should handle empty node volumes correctly', () => {
0041 const emptyNode = { fName: "Empty", fVolume: null };
0042 walkGeoNodes(emptyNode, mockCallback, 1);
0043 expect(mockCallback.calls.count()).toEqual(1); // Only the empty node should invoke the callback
0044 expect(mockCallback).toHaveBeenCalledWith(emptyNode, 'Empty', 0);
0045 });
0046
0047 it('should invoke callback for each node up to the specified max level', () => {
0048 walkGeoNodes(rootNode, mockCallback, Infinity); // Using Infinity to check all levels
0049 expect(mockCallback.calls.count()).toEqual(4); // Root, Child1, GrandChild1, Child2
0050 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Root" }), 'Root', 0);
0051 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Child1" }), 'Root/Child1', 1);
0052 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "GrandChild1" }), 'Root/Child1/GrandChild1', 2);
0053 expect(mockCallback).toHaveBeenCalledWith(jasmine.objectContaining({ fName: "Child2" }), 'Root/Child2', 1);
0054 });
0055 });
0056
0057
0058 describe('findGeoNodes', () => {
0059 const rootNode = {
0060 fName: "Root",
0061 fVolume: {
0062 fNodes: {
0063 arr: [
0064 { fName: "Child1", fVolume: { fNodes: { arr: [{ fName: "GrandChild1", fVolume: { fNodes: { arr: [] } } }] } } },
0065 { fName: "Child2", fVolume: { fNodes: { arr: [] } } }
0066 ]
0067 }
0068 }
0069 };
0070
0071 it('should return only nodes matching the specified pattern', () => {
0072 const pattern = "*Child2*";
0073 const results = findGeoNodes(rootNode, pattern);
0074 expect(results.length).toBe(1);
0075 expect(results[0].fullPath).toContain('Root/Child2');
0076 });
0077
0078 it('should return an empty array if no nodes match the pattern', () => {
0079 const pattern = "*NotExist*";
0080 const results = findGeoNodes(rootNode, pattern);
0081 expect(results.length).toBe(0);
0082 });
0083
0084 it('should stop search if maxLevel is reached', () => {
0085 const pattern = "*Child1";
0086 const results = findGeoNodes(rootNode, pattern, 1);
0087 expect(results.length).toBe(1);
0088 });
0089
0090 it('should handle patterns that match deeply nested nodes', () => {
0091 const pattern = "*GrandChild*";
0092 const results = findGeoNodes(rootNode, pattern);
0093 expect(results.length).toBe(1);
0094 expect(results[0].fullPath).toContain('Root/Child1/GrandChild1');
0095 });
0096 });
0097
0098