1// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const {assert} = chai;
6
7import * as UI from '../../../../front_end/ui/ui.js';
8
9describe('ShortcutTreeNode', () => {
10  it('can be instantiated without issues', () => {
11    const node = new UI.ShortcutRegistry.ShortcutTreeNode(0, 0);
12    assert.isEmpty(node.actions(), 'node should not have any actions upon instantiation');
13    assert.isFalse(node.hasChords(), 'node should not have any chords');
14    assert.strictEqual(node.key(), 0, 'node should set key property');
15  });
16
17  it('can add a mapping', () => {
18    const node = new UI.ShortcutRegistry.ShortcutTreeNode(0, 0);
19    node.addKeyMapping([12, 154, 36], 'test action');
20    const leafNode = node.getNode(12)?.getNode(154)?.getNode(36);
21    assert.ok(leafNode, 'node should have a descendant for the mapping');
22    assert.include(
23        leafNode?.actions() || [], 'test action', 'the mapping\'s node should have the \'test action\' action');
24    assert.isTrue(node.hasChords(), 'node should have chords');
25    assert.ok(node.getNode(12), 'node should have a child for key=12');
26    assert.notOk(node.getNode(154), 'node should not have a direct child for key=154');
27  });
28
29  it('can clear itself', () => {
30    const node = new UI.ShortcutRegistry.ShortcutTreeNode(0, 0);
31    node.addKeyMapping([12, 154, 36], 'test action');
32    node.addAction('another action');
33    node.clear();
34    assert.isEmpty(node.actions(), 'node should not have any actions after being cleared');
35    assert.isFalse(node.hasChords(), 'node should not have any chords after being cleared');
36  });
37});
38