summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_editor_code_folding.js
blob: e902a7e761ad7154edd12fc32f58b63649ed21ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests for code folding appears in editor mode, does not appear in inline mode,
// and that folded code does not remain folded when switched to inline mode.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1581641

"use strict";

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Test JsTerm editor code folding";

add_task(async function () {
  await pushPref("devtools.webconsole.input.editor", true);

  const hud = await openNewTabAndConsole(TEST_URI);

  info("Check that code folding gutter & arrow are rendered in editor mode");

  const multilineExpression = `function() {
    // Silence is golden
  }`;
  await setInputValue(hud, multilineExpression);

  ok(
    await waitFor(() => getFoldArrowOpenElement(hud)),
    "code folding gutter was rendered in editor mode"
  );

  const foldingArrow = getFoldArrowOpenElement(hud);
  ok(foldingArrow, "code folding arrow was rendered in code folding gutter");
  is(getCodeLines(hud).length, 3, "There are 3 lines displayed");

  info("Check that code folds when gutter marker clicked");
  EventUtils.synthesizeMouseAtCenter(
    foldingArrow,
    {},
    foldingArrow.ownerDocument.defaultView
  );
  await waitFor(() => getCodeLines(hud).length === 1);
  ok(true, "The code was folded, there's only one line displayed now");

  info("Check that folded code is expanded when rendered inline");

  await toggleLayout(hud);

  is(
    getCodeLines(hud).length,
    3,
    "folded code is expended when rendered in inline"
  );

  info(
    "Check that code folding gutter is hidden when we switch to inline mode"
  );
  ok(
    !getFoldGutterElement(hud),
    "code folding gutter is hidden when we switsch to inline mode"
  );
});

function getCodeLines(hud) {
  return hud.ui.outputNode.querySelectorAll(
    ".CodeMirror-code pre.CodeMirror-line"
  );
}

function getFoldGutterElement(hud) {
  return hud.ui.outputNode.querySelector(".CodeMirror-foldgutter");
}

function getFoldArrowOpenElement(hud) {
  return hud.ui.outputNode.querySelector(".CodeMirror-foldgutter-open");
}