1// Copyright 2024 The Pigweed Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may not 4// use this file except in compliance with the License. You may obtain a copy of 5// the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations under 13// the License. 14 15import { expect, assert } from '@open-wc/testing'; 16import { LocalStateStorage, StateService } from '../src/shared/state'; 17import { NodeType, Orientation, ViewNode } from '../src/shared/view-node'; 18 19describe('state', () => { 20 const mockColumnData = [ 21 { 22 fieldName: 'test', 23 characterLength: 0, 24 manualWidth: null, 25 isVisible: false, 26 }, 27 { 28 fieldName: 'foo', 29 characterLength: 0, 30 manualWidth: null, 31 isVisible: true, 32 }, 33 { 34 fieldName: 'bar', 35 characterLength: 0, 36 manualWidth: null, 37 isVisible: false, 38 }, 39 ]; 40 41 const mockState = { 42 rootNode: new ViewNode({ 43 type: NodeType.Split, 44 orientation: Orientation.Horizontal, 45 children: [ 46 new ViewNode({ 47 searchText: 'hello', 48 logViewId: 'child-node-1', 49 type: NodeType.View, 50 columnData: mockColumnData, 51 }), 52 new ViewNode({ 53 searchText: 'world', 54 logViewId: 'child-node-2', 55 type: NodeType.View, 56 columnData: mockColumnData, 57 }), 58 ], 59 }), 60 }; 61 62 const stateService = new StateService(new LocalStateStorage()); 63 stateService.saveState(mockState); 64 65 describe('state service', () => { 66 it('loads a stored state object', () => { 67 expect(stateService.loadState()).to.have.property('rootNode'); 68 assert.lengthOf(stateService.loadState().rootNode.children, 2); 69 }); 70 }); 71}); 72