<commit_before>import InternalControlContainer from "./InternalControl";

describe("<InternalControl />", () => {
    const initialState = {
        settings: {
            data: {},
            readahead: null,
            readaheadPending: false
        },
        references: {
            detail: {
                internalControl: null,
                id: "123abc",
                remotes_from: null
            }
        }
    };
    const store = mockStore(initialState);
    let wrapper;

    it("renders correctly", () => {
        wrapper = shallow(<InternalControlContainer store={store} />).dive();
        expect(wrapper).toMatchSnapshot();
    });
});<commit_msg>Update administration InternalControl component tests<commit_after>import InternalControlContainer from "./InternalControl";
import { AsyncTypeahead } from "react-bootstrap-typeahead";
import * as actions from "../../actions";
import * as refActions from "../../../references/actions";

describe("<InternalControl />", () => {
    let initialState;
    let store;
    let wrapper;

    it("renders correctly", () => {
        initialState = {
            settings: {
                data: {},
                readahead: null,
                readaheadPending: false
            },
            references: {
                detail: {
                    internal_control: "",
                    id: "123abc",
                    remotes_from: null
                }
            }
        };
        store = mockStore(initialState);
        wrapper = shallow(<InternalControlContainer store={store} />).dive();
        expect(wrapper).toMatchSnapshot();
    });

    describe("dispatch actions", () => {
        let spyReadahead;
        let spyUpdate;

        beforeAll(() => {
            spyReadahead = sinon.spy(actions, "getControlReadahead");
            spyUpdate = sinon.spy(refActions, "editReference");

            initialState = {
                settings: {
                    data: {},
                    readahead: ["foo", "bar"],
                    readaheadPending: false
                },
                references: {
                    detail: {
                        internal_control: "foo",
                        id: "123abc",
                        remotes_from: null
                    }
                }
            };
            store = mockStore(initialState);
            wrapper = mount(<InternalControlContainer store={store} />);
        });

        afterAll(() => {
            spyReadahead.restore();
            spyUpdate.restore();
        });

        it("typing in search term dispatches getControlReadahead action", () => {
            expect(spyReadahead.called).toBe(false);
            wrapper.find(AsyncTypeahead).prop("onSearch")("search-term");
            expect(spyReadahead.calledWith("123abc", "search-term")).toBe(true);
        });

        it("selecting a search term results in internal control setting updating", () => {
            expect(spyUpdate.called).toBe(false);
            wrapper.find(AsyncTypeahead).prop("onChange")([{ id: "bar" }]);
            expect(spyUpdate.calledWith("123abc", { internal_control: "bar" })).toBe(true);

            wrapper.find(AsyncTypeahead).prop("onChange")([]);
            expect(spyUpdate.calledWith("123abc", { internal_control: "" })).toBe(true);
        });

        it("renders menu items from search results", () => {
            const result = wrapper.find(AsyncTypeahead).prop("renderMenuItemChildren")({ id: "test", name: "example" });
            expect(result.type).toEqual("option");
        });

    });
});
{'fraction_non_alphanumeric': 0.13580931263858093, 'fraction_numerical': 0.004988913525498891, 'mean_word_length': 1.7507621951219512, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, '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': '3021791', 'n_tokens_mistral': 933, 'n_tokens_neox': 876, 'n_words': 169}