App-Dochazka-WWW

 view release on metacpan or  search on metacpan

share/js/dochazka-www/canned-tests.js  view on Meta::CPAN

        mainareaFormFunc = function (assert, formId) {
            // asserts that #mainarea contains a form and that its form ID is
            // formID
            var mainarea = $('#mainarea'),
                htmlbuf = mainarea.html();
            // assert.ok(htmlbuf, "#mainarea html: " + htmlbuf);
            assert.strictEqual($('form', mainarea).length, 1, "#mainarea contains 1 form");
            assert.strictEqual($('form', mainarea)[0].id, formId, "that form is called " + formId);
        },
        stackFunc = function (assert, stackLen, afterWhat, tgtType, tgtName) {
            // asserts that stack has a certain length (stackLen) after doing
            // some action (afterWhat) and that the target on the top of the
            // stack is of type tgtType and has name tgtName
            var topTarget = stack.getTarget();
            assert.strictEqual(
                stack.getLength(),
                stackLen,
                stackLen + " item(s) on stack after " + afterWhat
            );
            assert.strictEqual(
                topTarget.type,
                tgtType,
                "Target on top of stack is of type \"" + tgtType + "\"",
            );
            assert.strictEqual(
                topTarget.name,
                tgtName,
                "Target on top of stack has name \"" + tgtName + "\"",
            );
        },
        submitLdapLookupFunc = function (assert, searchTerm) {
            // fill out form and initiate AJAX call
            assert.ok(
                true,
                "*** REACHED submitting ldapLookup for search term \"" + searchTerm + "\"",
            );
            $('input[name="entry0"]').val(searchTerm);
            $('input[name="sel"]').val('0');
            $('input[name="sel"]').focus();
            // $('input[name="sel"]').trigger($.Event("keydown", {keyCode: 13}));
            // trigger() does not work with dform, so send the keydown event
            // directory to mmKeyListener()
            start.mmKeyListener($.Event("keydown", {keyCode: 13}));
            assert.ok(true, "*** REACHED ldapLookup form submitted");
            ajaxCallInitiatedFunc(assert);
        };

    return {

        "ajaxCallInitiated": ajaxCallInitiatedFunc,

        "contains": containsFunc,

        "employeeCreate": function (assert, nick) {
            var rest = {
                    "method": 'POST',
                    "path": 'employee/nick',
                    "body": {
                        "nick": nick,
                        "fullname": nick + " user",
                        "password": nick,
                    },
                },
                // success callback
                sc = function (st) {
                    console.log("AJAX " + rest["path"] + " success:", st);
                    assert.strictEqual(st.code, 'DOCHAZKA_CUD_OK');
                },
                // failure callback
                fc = function (st) {
                    console.log("AJAX " + rest["path"] + " failure:", st);
                    assert.notOK(true, "createEmployee failed unexpectedly: " +
                        QUnit.dump.parse(st));
                };
            ajax(rest, sc, fc);
        },

        "employeeHasPriv": function (assert, nick, priv) {
            var rest = {
                    "method": 'GET',
                    "path": 'priv/nick/' + nick,
                },
                // success callback
                sc = function (st) {
                    console.log("AJAX " + rest["path"] + " success:", st);
                    assert.strictEqual(st.code, 'DISPATCH_EMPLOYEE_PRIV', "Status code is DISPATCH_EMPLOYEE_PRIV");
                    assert.strictEqual(st.payload.nick, nick, "Nick in payload checks out");
                    assert.strictEqual(st.payload.priv, priv, "Priv in payload checks out");
                },
                // failure callback
                fc = function (st) {
                    console.log("AJAX " + rest["path"] + " failure:", st);
                    assert.notOK(true, "employeeHasPriv failed unexpectedly: " +
                        QUnit.dump.parse(st));
                };
            ajax(rest, sc, fc);
        },

        "employeePriv": function (assert, nick, priv) {
            var rest = {
                    "method": 'POST',
                    "path": 'priv/history/nick/' + nick,
                    "body": {
                        "effective": "1892-01-01",
                        "priv": priv,
                    },
                },
                // success callback
                sc = function (st) {
                    console.log("AJAX: " + rest["path"] + " success", st);
                    if (st.code === 'DOCHAZKA_CUD_OK') {
                        // "DOCHAZKA_CUD_OK"
                        coreLib.displayResult(st.text);
                    } else {
                        coreLib.displayError("Unexpected status code " + st.code);
                    }
                },
                // failure callback
                fc = function (st) {
                    console.log("AJAX: " + rest["path"] + " failure", st);
                    coreLib.displayError(st.payload.message);



( run in 1.152 second using v1.01-cache-2.11-cpan-804bf51f3ce )