<commit_before>import chai from "chai";// eslint-disable-line import/no-extraneous-dependencies
import SideMenuItem from "sidemenu/SideMenuItem";// eslint-disable-line import/no-extraneous-dependencies,import/no-unresolved
import TestUtils from "../TestUtils";

describe("sidemenu/SideMenuItem", () => {
    const props = {
        item: {
            text: "Manager",
            path: "app/modules/Manager",
            module: "Manager",
            icon: "fa-cogs",
            items: [
                {
                    text: "Parameters",
                    path: "app/modules/Parameters",
                    module: "Parameters",
                    icon: "fa-tachometer"
                }, {
                    text: "Parameters2",
                    path: "app/modules/Parameters2",
                    module: "Parameters2",
                    icon: "fa-tachometer"
                }]
        },
        onChange: () => { }
    };
    const item = TestUtils.mount(props, SideMenuItem, props);

    it("render", () => {
        let li = item.find(".SideMenu-item");
        chai.assert.isTrue(li.hasClass("SideMenu-item"), "initial class must be SideMenu-item");
        chai.assert.isTrue(li.find("i").hasClass(props.item.icon),
            "fa icon class must be same with the 'props.item.icon'.");

        chai.assert.equal(li.text(), props.item.text, "li text must be same with the 'props.item.text'");

        let ul = item.find(".out");

        chai.assert.equal(ul.find(".SideMenu-subitem").length, props.item.items.length,
            "It must be same child count with 'props.item.items.length'");
    });

    it("onClick", () => {
        let li = item.find(".SideMenu-item");
        chai.assert.isTrue(li.hasClass("SideMenu-item"), "initial class must be SideMenu-item");
        chai.assert.isDefined(item.find(".out").node, "Pre-click out must be defined");

        li.simulate("click");
        chai.assert.isTrue(li.hasClass("SideMenu-item-active"),
            "Post-click class must be SideMenu-item-active");
        chai.assert.isUndefined(item.find(".out").node, "Post-click out must be undefined");
        chai.assert.isDefined(item.find(".in").node, "Post-click in must be defined");

        let ul = item.find(".in");
        chai.assert.equal(ul.find(".SideMenu-subitem").length, props.item.items.length,
            "It must be same child count with 'props.item.items.length'");
    });

    it("componentDidMount", () => {
        props.selectedItem = props.item.path;
        const itemSelected = TestUtils.mount(props, SideMenuItem, props);

        chai.assert.isTrue(itemSelected.find(".SideMenu-item").hasClass("SideMenu-item-active"),
            "If 'props.selectedItem' is ending with 'props.item.module' class must be SideMenu-item-active");
        itemSelected.find(".SideMenu-item").simulate("click");
        chai.assert.isTrue(itemSelected.find(".SideMenu-item").hasClass("SideMenu-item-active"),
            "After Second click class must be SideMenu-item-active");
    });

    it("onChange", () => {
        props.selectedItem = props.item.path;
        const itemSelected = TestUtils.mount(props, SideMenuItem, props);

        chai.assert.equal(itemSelected.find(".SideMenu-subitem").length, props.item.items.length);
        itemSelected.find(".SideMenu-item").simulate("click");
        itemSelected.find(".SideMenu-subitem").first().find("div").simulate("click");
        chai.assert.equal(itemSelected.find(".SideMenu-subitem").length, props.item.items.length - 1, "Post-Click Non active Subitem lengthmust be 1 less than 'props.item.items.length'");
        chai.assert.equal(itemSelected.find(".SideMenu-subitem-active").length, 1);
        chai.assert.equal(itemSelected.find(".SideMenu-subitem-active").find("div").text(), "Parameters");<commit_msg>SideMenu Test fixed.<commit_after>import chai from "chai";// eslint-disable-line import/no-extraneous-dependencies
import SideMenuItem from "sidemenu/SideMenuItem";// eslint-disable-line import/no-extraneous-dependencies,import/no-unresolved
import TestUtils from "../TestUtils";
import {
    Collapse
} from "react-bootstrap";

describe("sidemenu/SideMenuItem", () => {
    const props = {
        item: {
            text: "Manager",
            path: "app/modules/Manager",
            module: "Manager",
            icon: "fa-cogs",
            items: [
                {
                    text: "Parameters",
                    path: "app/modules/Parameters",
                    module: "Parameters",
                    icon: "fa-tachometer"
                }, {
                    text: "Parameters2",
                    path: "app/modules/Parameters2",
                    module: "Parameters2",
                    icon: "fa-tachometer"
                }]
        },
        onChange: () => { }
    };
    const item = TestUtils.mount(props, SideMenuItem, props);

    it("render", () => {
        let li = item.find(".SideMenu-item");
        chai.assert.isTrue(li.hasClass("SideMenu-item"), "initial class must be SideMenu-item");
        chai.assert.isTrue(li.find("i").hasClass(props.item.icon),
            "fa icon class must be same with the 'props.item.icon'.");
        chai.assert.equal(li.text(), props.item.text, "li text must be same with the 'props.item.text'");
        let ul = item.find("ul");
        chai.assert.equal(ul.find("li").length, props.item.items.length,
            "It must be same child count with 'props.item.items.length'");
    });

    it("onClick", () => {
        let li = item.find(".SideMenu-item");
        chai.assert.isTrue(li.hasClass("SideMenu-item"), "initial class must be SideMenu-item");
        chai.assert.isFalse(item.find(Collapse).prop("in"), "Pre-Click must be collapsed");
        li.simulate("click");
        chai.assert.isTrue(li.hasClass("SideMenu-item-active"),
            "Post-click class must be SideMenu-item-active");
        chai.assert.isTrue(item.find(Collapse).prop("in"), "Post-Click must be expanded");
        let ul = item.find(Collapse);
        chai.assert.equal(ul.find("li").length, props.item.items.length,
            "It must be same child count with 'props.item.items.length'");
    });

    it("componentDidMount", () => {
        props.selectedItem = props.item.path;
        const itemSelected = TestUtils.mount(props, SideMenuItem, props);

        chai.assert.isTrue(itemSelected.find(".SideMenu-item").hasClass("SideMenu-item-active"),
            "If 'props.selectedItem' is ending with 'props.item.module' class must be SideMenu-item-active");
        itemSelected.find(".SideMenu-item").simulate("click");
        chai.assert.isTrue(itemSelected.find(".SideMenu-item").hasClass("SideMenu-item-active"),
            "After Second click class must be SideMenu-item-active");
    });

    it("onChange", () => {
        props.selectedItem = props.item.path;
        const itemSelected = TestUtils.mount(props, SideMenuItem, props);

        chai.assert.equal(itemSelected.find(".SideMenu-subitem").length, props.item.items.length);
        itemSelected.find(".SideMenu-item").simulate("click");
        itemSelected.find(".SideMenu-subitem").first().find("div").simulate("click");
        chai.assert.equal(itemSelected.find(".SideMenu-subitem").length, props.item.items.length - 1, "Post-Click Non active Subitem lengthmust be 1 less than 'props.item.items.length'");
        chai.assert.equal(itemSelected.find(".SideMenu-subitem-active").length, 1);
        chai.assert.equal(itemSelected.find(".SideMenu-subitem-active").find("div").text(), "Parameters");
{'fraction_non_alphanumeric': 0.15849802371541502, 'fraction_numerical': 0.0015810276679841897, 'mean_word_length': 2.5438842203548084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '509960', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2175, 'n_words': 395}