|
| 1 | +// ***************************************************************************** |
| 2 | +// Copyright (C) 2024 EclipseSource and others. |
| 3 | +// |
| 4 | +// This program and the accompanying materials are made available under the |
| 5 | +// terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | +// http://www.eclipse.org/legal/epl-2.0. |
| 7 | +// |
| 8 | +// This Source Code may also be made available under the following Secondary |
| 9 | +// Licenses when the conditions for such availability set forth in the Eclipse |
| 10 | +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 |
| 11 | +// with the GNU Classpath Exception which is available at |
| 12 | +// https://www.gnu.org/software/classpath/license.html. |
| 13 | +// |
| 14 | +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 |
| 15 | +// ***************************************************************************** |
| 16 | +import { expect } from 'chai'; |
| 17 | +import { CompositeMenuNode } from './composite-menu-node'; |
| 18 | +import { CompoundMenuNodeRole } from './menu-types'; |
| 19 | + |
| 20 | +describe('composite-menu-node', () => { |
| 21 | + describe('updateOptions', () => { |
| 22 | + it('should update undefined node properties', () => { |
| 23 | + const node = new CompositeMenuNode('test-id'); |
| 24 | + node.updateOptions({ label: 'node-label', icon: 'icon', order: 'a', role: CompoundMenuNodeRole.Flat, when: 'node-condition' }); |
| 25 | + expect(node.label).to.equal('node-label'); |
| 26 | + expect(node.icon).to.equal('icon'); |
| 27 | + expect(node.order).to.equal('a'); |
| 28 | + expect(node.role).to.equal(CompoundMenuNodeRole.Flat); |
| 29 | + expect(node.when).to.equal('node-condition'); |
| 30 | + }); |
| 31 | + it('should update existing node properties', () => { |
| 32 | + const node = new CompositeMenuNode('test-id', 'test-label', { icon: 'test-icon', order: 'a1', role: CompoundMenuNodeRole.Submenu, when: 'test-condition' }); |
| 33 | + node.updateOptions({ label: 'NEW-label', icon: 'NEW-icon', order: 'a2', role: CompoundMenuNodeRole.Flat, when: 'NEW-condition' }); |
| 34 | + expect(node.label).to.equal('NEW-label'); |
| 35 | + expect(node.icon).to.equal('NEW-icon'); |
| 36 | + expect(node.order).to.equal('a2'); |
| 37 | + expect(node.role).to.equal(CompoundMenuNodeRole.Flat); |
| 38 | + expect(node.when).to.equal('NEW-condition'); |
| 39 | + }); |
| 40 | + it('should update only the icon without affecting other properties', () => { |
| 41 | + const node = new CompositeMenuNode('test-id', 'test-label', { icon: 'test-icon', order: 'a' }); |
| 42 | + node.updateOptions({ icon: 'NEW-icon' }); |
| 43 | + expect(node.label).to.equal('test-label'); |
| 44 | + expect(node.icon).to.equal('NEW-icon'); |
| 45 | + expect(node.order).to.equal('a'); |
| 46 | + }); |
| 47 | + it('should not allow to unset properties', () => { |
| 48 | + const node = new CompositeMenuNode('test-id', 'test-label', { icon: 'test-icon', order: 'a' }); |
| 49 | + node.updateOptions({ icon: undefined }); |
| 50 | + expect(node.label).to.equal('test-label'); |
| 51 | + expect(node.icon).to.equal('test-icon'); |
| 52 | + expect(node.order).to.equal('a'); |
| 53 | + }); |
| 54 | + it('should allow to set empty strings in properties', () => { |
| 55 | + const node = new CompositeMenuNode('test-id', 'test-label'); |
| 56 | + node.updateOptions({ label: '' }); |
| 57 | + expect(node.label).to.equal(''); |
| 58 | + }); |
| 59 | + it('should not cause side effects when updating a property to its existing value', () => { |
| 60 | + const node = new CompositeMenuNode('test-id', 'test-label', { icon: 'test-icon', order: 'a' }); |
| 61 | + node.updateOptions({ icon: 'test-icon' }); |
| 62 | + expect(node.label).to.equal('test-label'); |
| 63 | + expect(node.icon).to.equal('test-icon'); |
| 64 | + expect(node.order).to.equal('a'); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments