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 {createElement, Overlay, createTextChild} from '../../../inspector_overlay/common.js';
8
9// Make sure typescript knows about the custom properties that are set on the window object.
10declare global {
11  interface Window {
12    platform: string;
13    viewportSize: object;
14    deviceScaleFactor: number;
15  }
16}
17
18describe('common helper', () => {
19  it('can create DOM elements', () => {
20    assert.instanceOf(createElement('div', 'test'), HTMLDivElement);
21  });
22
23  it('exposes DOM manipulation methods on DOM elements', () => {
24    const wrapper = document.createElement('div');
25
26    assert.isTrue(!!wrapper.createChild, 'createChild is available on DOM elements');
27    const child = wrapper.createChild('span', 'child');
28
29    assert.instanceOf(child, HTMLSpanElement, 'The right span element got created');
30    assert.strictEqual(child.className, 'child', 'The right className got set');
31
32    const textChild = createTextChild(wrapper, 'hello world');
33
34    assert.instanceOf(textChild, Text, 'The right text node got created');
35    assert.strictEqual(textChild.textContent, 'hello world', 'The right text content got set');
36
37    assert.isTrue(!!wrapper.removeChildren, 'removeChildren is available on DOM elements');
38    wrapper.removeChildren();
39
40    assert.strictEqual(wrapper.childElementCount, 0, 'All children got removed');
41  });
42
43  it('sets the right platform', () => {
44    const overlay = new Overlay(window);
45    const platform = 'mac';
46    overlay.setPlatform(platform);
47    assert.isTrue(document.body.classList.contains(`platform-${platform}`));
48  });
49});
50