summaryrefslogtreecommitdiff
path: root/common/tests/functional/testEchoCommands.js
blob: 39d4f08c287fb38c7b05c3c85378f26e3e93b710 (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
75
76
77
78
var dactyllib = require("utils").module("dactyl");

var setupModule = function (module) {
    controller = mozmill.getBrowserController();
    dactyl = new dactyllib.Controller(controller);
};

var teardownModule = function (module) {
    dactyl.teardown();
}

var teardownTest = function (test) {
    dactyl.closeMessageWindow();
};

var testEchoCommand_SingleLineMessageAndClosedMOW_MessageDisplayedInMessageLine = function () {
    const output = "foobar";

    assertEchoGeneratesLineOutput({
        ECHO_COMMAND: "echo " + output.quote(),
        EXPECTED_OUTPUT: output
    });
};

var testEchoCommand_SingleLineMessageAndOpenMOW_MessageAppendedToMOW = function () {
    const output = "foobar";

    dactyl.openMessageWindow();

    assertEchoGeneratesWindowOutput({
        ECHO_COMMAND: "echo " + output.quote(),
        EXPECTED_OUTPUT: RegExp(output)
    });
};

var testEchoCommand_MultilineMessageAndClosedMOW_MessageDisplayedInMOW = function () {
    const output = "foo\nbar";

    assertEchoGeneratesWindowOutput({
        ECHO_COMMAND: "echo " + output.quote(),
        EXPECTED_OUTPUT: output
    });
};

var testEchoCommand_MultilineMessageAndOpenMOW_MessageAppendedToMOW = function () {
    const output = "foo\nbar";

    dactyl.openMessageWindow();

    assertEchoGeneratesWindowOutput({
        ECHO_COMMAND: "echo " + output.quote(),
        EXPECTED_OUTPUT: RegExp(output)
    });
};

var testEchoCommand_ObjectArgumentAndClosedMOW_MessageDisplayedInMOW = function () {
    assertEchoGeneratesWindowOutput({
        ECHO_COMMAND: "echo var obj = { x: 1, y: 2 }; obj;",
        EXPECTED_OUTPUT: "[object\u00A0Object]::\nx: 1\ny: 2\n"
    });
};

function executeCommand(command) {
    dactyl.runViCommand(":" + command);
    dactyl.runViCommand([["VK_RETURN"]]);
}

function assertEchoGeneratesWindowOutput({ ECHO_COMMAND, EXPECTED_OUTPUT }) {
    executeCommand(ECHO_COMMAND);
    dactyl.assertMessageWindow(EXPECTED_OUTPUT);
}

function assertEchoGeneratesLineOutput({ ECHO_COMMAND, EXPECTED_OUTPUT }) {
    executeCommand(ECHO_COMMAND);
    dactyl.assertMessageLine(EXPECTED_OUTPUT);
}

// vim: sw=4 ts=8 et: