<commit_before>// import Nevow.Test.WidgetUtil
// import Methanal.Tests.Util
// import Methanal.Widgets
// import Methanal.Util



//Methanal.Widgets.Table.subclass(
//    Methanal.Tests.TestWidgets, 'MockTable').methods(
//    function __init__(self, args) {
//        var node = Nevow.Test.WidgetUtil.makeWidgetNode();
//        Methanal.Tests.TestWidgets.MockTable.upcall(
//            self, '__init__', node, args);
//        var tableNode = document.createElement('table');
//        tableNode.appendChild(document.createElement('thead'));
//        tableNode.appendChild(document.createElement('tbody'));
//        node.appendChild(tableNode);
//        document.body.appendChild(node);
//    });



Methanal.Widgets.Action.subclass(
    Methanal.Tests.TestWidgets, 'DisabledAction').methods(
        function enableForRow(self, row) {
            return false;
        });



Methanal.Tests.Util.TestCase.subclass(
    Methanal.Tests.TestWidgets, 'TableTest').methods(
    function createTable(self, columnValues, actions, defaultAction) {
        var cells = {};
        var columns = [];
        for (var columnID in columnValues) {
            var values = columnValues[columnID];
            columns.push(values.type(columnID, 'title'));
            cells[columnID] = Methanal.Widgets.Cell(values.value, values.link);
        }
        var node = Nevow.Test.WidgetUtil.makeWidgetNode();
        var rows = [Methanal.Widgets.Row(0, cells)];
        var args = {'columns': columns, 'rows': rows};
        var table = Methanal.Widgets.Table(node, args);
        table.actions = actions || null;
        table.defaultAction = defaultAction || null;
        document.body.appendChild(node);
        Methanal.Util.nodeInserted(table);
        return table;
    },


    function test_createTableWithEnabledAction(self) {
        var columnValues = {
            'col1': {type: Methanal.Widgets.BooleanColumn,
                     value: false,
                     link: null}};
        var actions = [Methanal.Widgets.Action('foo', 'Foo')];
        var table = self.createTable(columnValues, actions);
    },


    function test_createTableWithDisabledAction(self) {
        var columnValues = {
            'col1': {type: Methanal.Widgets.BooleanColumn,
                     value: false,
                     link: null}};
        var actions = [Methanal.Tests.TestWidgets.DisabledAction('foo',
                                                                 'Foo')];
        var table = self.createTable(columnValues, actions);
    });


/**
 * Create and test trivial Column types.
 *
 * @ivar columnType: Column type to create.
 *
 * @ivar columnValues: A mapping of column identifiers to mappings of values
 *     for keys named C{id}, C{link}, C{nodeValue}.
 *
 * @ivar columns: A sequence of L{Methanal.Widgets.Column} instances.
 *
 * @ivar rowData: L{Methanal.Widgets.Row} constructed from L{columnValues}.
 */
Methanal.Tests.Util.TestCase.subclass(
    Methanal.Tests.TestWidgets, 'SimpleColumnTest').methods(
    function setUp(self) {
        var _cells = {};
        self.columns = [];
        for (var columnID in self.columnValues) {
            var values = self.columnValues[columnID];
            self.columns.push(self.columnType(columnID, 'title'));
            _cells[columnID] = Methanal.Widgets.Cell(values.value, values.link);
        }
        self.rowData = Methanal.Widgets.Row(0, _cells);
    },<commit_msg>Complete tests for Tables with Actions that return false from enableForRow.<commit_after>// import Nevow.Test.WidgetUtil
// import Methanal.Widgets
// import Methanal.Util
// import Methanal.Tests.Util
// import Methanal.Tests.MockBrowser



/**
 * A L{Methanal.Widgets.Action} that returns C{false} for C{enableForRow}.
 */
Methanal.Widgets.Action.subclass(
    Methanal.Tests.TestWidgets, 'DisabledAction').methods(
        function enableForRow(self, row) {
            return false;
        });



/**
 * Tests for L{Methanal.Widgets.Table}.
 */
Methanal.Tests.Util.TestCase.subclass(
    Methanal.Tests.TestWidgets, 'TableTest').methods(
    /**
     * Create a L{Methanal.Wigets.Table} widget.
     *
     * @param columnValues: Mapping of column names to mappings of C{'type'},
     *     C{'value'} and C{'link'}, used for creating cells.
     *
     * @type  actions: C{Array} of L{Methanal.Widgets.Action}
     * @param actions: Optional table actions.
     *
     * @type  defaultAction: L{Methanal.Widgets.Action}
     * @param defaultAction: Optional default table action.
     *
     * @rtype: C{Methanal.Widgets.Table}
     */
    function createTable(self, columnValues, actions/*=undefined*/,
        defaultAction/*=undefined*/) {
        var cells = {};
        var columns = [];
        for (var columnID in columnValues) {
            var values = columnValues[columnID];
            columns.push(values.type(columnID, 'title'));
            cells[columnID] = Methanal.Widgets.Cell(values.value, values.link);
        }
        var node = Nevow.Test.WidgetUtil.makeWidgetNode();
        var rows = [Methanal.Widgets.Row(0, cells)];
        var args = {
            'columns': columns,
            'rows': rows};
        var table = Methanal.Widgets.Table(node, args);
        table.actions = actions || null;
        table.defaultAction = defaultAction || null;
        var tableNode = Methanal.Tests.Util.makeWidgetChildNode(
            table, 'table');
        document.body.appendChild(node);
        Methanal.Util.nodeInserted(table);
        return table;
    },


    /**
     * Get an C{Array} of DOM nodes for a table's actions.
     */
    function _getActionNodes(self, table) {
        var rows = table.getBody().rows;
        self.assertIdentical(rows.length > 0, true,
            'Table has no rows.');
        var cells = rows[0].cells;
        if (cells.length < table._columns.length + 1) {
            throw new Error('No actions column.');
        }
        var actionsCell = cells[table._columns.length/* + 1 - 1*/];
        return actionsCell.getElementsByTagName('a');
    },


    /**
     * Assert that C{table} has action DOM nodes that match an C{Array} of
     * L{Methanal.Widgets.Action}.
     */
    function assertHasActions(self, table, actions) {
        var actionDisplayNames = [];
        for (var i = 0; i < actions.length; ++i) {
            actionDisplayNames.push(actions[i].displayName);
        }
        actionDisplayNames.sort();

        var anchors = self._getActionNodes(table);
        self.assertIdentical(anchors.length, actions.length,
            'Number of action nodes does not match number of actions.');

        var textValues = []
        for (var i = 0; i < anchors.length; ++i) {
            var children = anchors[i].childNodes;
            for (var j = 0; j < children.length; ++j) {
                if (children[j].nodeType == children[j].TEXT_NODE) {
                    textValues.push(children[j].nodeValue);
                    break;
                }
            }
        }
        textValues.sort();

        self.assertArraysEqual(actionDisplayNames, textValues);
    },


    /**
     * Assert that C{table} has no action DOM nodes.
     */
    function assertHasNoActions(self, table) {
        var anchors = self._getActionNodes(table);
        self.assertIdentical(anchors.length, 0,
            'Table has ' + anchors.length + ' actions, expected 0.');
    },


    /**
     * Create a table with actions.
     */
    function test_createTableWithEnabledAction(self) {
        var columnValues = {
            'col1': {type: Methanal.Widgets.BooleanColumn,
                     value: false,
                     link: null}};
        var actions = [Methanal.Widgets.Action('foo', 'Foo')];
        var table = self.createTable(columnValues, actions);

        self.assertHasActions(table, actions);
    },


    /**
     * Create a table with actions that are disabled. An "actions" column
     * should still appear, in this case.
     */
    function test_createTableWithDisabledAction(self) {
        var columnValues = {
            'col1': {type: Methanal.Widgets.BooleanColumn,
                     value: false,
                     link: null}};
        var actions = [
            Methanal.Tests.TestWidgets.DisabledAction('foo', 'Foo')];
        var table = self.createTable(columnValues, actions);

        self.assertHasNoActions(table);
    });


/**
 * Create and test trivial Column types.
 *
 * @ivar columnType: Column type to create.
 *
 * @ivar columnValues: A mapping of column identifiers to mappings of values
 *     for keys named C{id}, C{link}, C{nodeValue}.
 *
 * @ivar columns: A sequence of L{Methanal.Widgets.Column} instances.
 *
 * @ivar rowData: L{Methanal.Widgets.Row} constructed from L{columnValues}.
 */
Methanal.Tests.Util.TestCase.subclass(
    Methanal.Tests.TestWidgets, 'SimpleColumnTest').methods(
    function setUp(self) {
        var _cells = {};
        self.columns = [];
        for (var columnID in self.columnValues) {
            var values = self.columnValues[columnID];
            self.columns.push(self.columnType(columnID, 'title'));
            _cells[columnID] = Methanal.Widgets.Cell(values.value, values.link);
        }
        self.rowData = Methanal.Widgets.Row(0, _cells);
    },
{'fraction_non_alphanumeric': 0.1250269222485462, 'fraction_numerical': 0.0019384018953262977, 'mean_word_length': 2.310873440285205, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '239560', 'n_tokens_mistral': 2730, 'n_tokens_neox': 2634, 'n_words': 595}