1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {CollapsibleSections} from './collapsible_sections'; 18import {CollapsibleSectionType} from './collapsible_section_type'; 19 20describe('AddDiffsPropertiesTree', () => { 21 let collapsibleSections: CollapsibleSections; 22 23 beforeEach(() => { 24 const sections = [ 25 { 26 type: CollapsibleSectionType.RECTS, 27 label: 'LAYERS', 28 isCollapsed: false, 29 }, 30 { 31 type: CollapsibleSectionType.HIERARCHY, 32 label: 'HIERARCHY', 33 isCollapsed: true, 34 }, 35 { 36 type: CollapsibleSectionType.PROPERTIES, 37 label: 'PROTO DUMP', 38 isCollapsed: false, 39 }, 40 ]; 41 collapsibleSections = new CollapsibleSections(sections); 42 }); 43 44 it('returns true if all sections expanded', () => { 45 expect(collapsibleSections.areAllSectionsExpanded()).toBeFalse(); 46 collapsibleSections.onCollapseStateChange( 47 CollapsibleSectionType.HIERARCHY, 48 false, 49 ); 50 expect(collapsibleSections.areAllSectionsExpanded()).toBeTrue(); 51 }); 52 53 it('returns collapsed sections', () => { 54 expect(collapsibleSections.getCollapsedSections()).toEqual([ 55 { 56 type: CollapsibleSectionType.HIERARCHY, 57 label: 'HIERARCHY', 58 isCollapsed: true, 59 }, 60 ]); 61 }); 62 63 it('returns section of given type if available', () => { 64 expect( 65 collapsibleSections.getSection(CollapsibleSectionType.HIERARCHY), 66 ).toEqual({ 67 type: CollapsibleSectionType.HIERARCHY, 68 label: 'HIERARCHY', 69 isCollapsed: true, 70 }); 71 expect( 72 collapsibleSections.getSection( 73 CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 74 ), 75 ).toBeUndefined(); 76 }); 77 78 it('returns collapse state of given section type', () => { 79 expect( 80 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY), 81 ).toBeTrue(); 82 expect( 83 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.RECTS), 84 ).toBeFalse(); 85 86 // robust to given section type not present 87 expect( 88 collapsibleSections.isSectionCollapsed( 89 CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 90 ), 91 ).toBeFalse(); 92 }); 93 94 it('changes collapse state of given section type', () => { 95 expect( 96 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY), 97 ).toBeTrue(); 98 99 collapsibleSections.onCollapseStateChange( 100 CollapsibleSectionType.HIERARCHY, 101 false, 102 ); 103 expect( 104 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY), 105 ).toBeFalse(); 106 107 collapsibleSections.onCollapseStateChange( 108 CollapsibleSectionType.HIERARCHY, 109 true, 110 ); 111 expect( 112 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY), 113 ).toBeTrue(); 114 115 // no change in state 116 collapsibleSections.onCollapseStateChange( 117 CollapsibleSectionType.HIERARCHY, 118 true, 119 ); 120 expect( 121 collapsibleSections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY), 122 ).toBeTrue(); 123 124 // robust to given section type not present 125 expect(() => { 126 collapsibleSections.onCollapseStateChange( 127 CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 128 true, 129 ); 130 }).not.toThrowError(); 131 }); 132}); 133