<commit_before>import { ShallowWrapper, shallow } from "enzyme";
import GoogleMap from "google-map-react";
import { createElement } from "react";

import { Location, Map, MapProps, heightUnitType, widthUnitType } from "../Map";
import { Marker } from "../Marker";
import { Alert } from "../Alert";

// tslint:disable:no-submodule-imports
import { mockGoogleMaps } from "tests/mocks/GoogleMaps";
import { mockMendix } from "tests/mocks/Mendix";

describe("Map", () => {
    const address = "Lumumba Ave, Kampala, Uganda";
    const invalidAddress = "invalidAddress";
    const APIKey = "<KEY>";
    const renderMap = (props: MapProps) => shallow(createElement(Map, props));
    const defaultCenterLocation = { lat: 51.9107963, lng: 4.4789878 };
    const successMockLocation = { lat: 30, lng: 118 };
    const multipleAddressMockLocation = { lat: 34.213171, lng: -118.571022 };
    let mxOriginal: mx.mx;

    const setUpMap = (
        locationsParam: Location[], APIKeyParam?: string,
        widthParam?: number,
        heightParam?: number,
        widthUnitParam?: widthUnitType,
        heightUnitParam?: heightUnitType,
        defaultCenterParam?: string): ShallowWrapper<MapProps, any> => {
        const output = renderMap({
            apiKey: APIKeyParam,
            autoZoom: true,
            defaultCenterAddress: defaultCenterParam !== undefined ? defaultCenterParam : "",
            height: heightParam ? heightParam : 75,
            heightUnit: heightUnitParam ? heightUnitParam : "pixels",
            locations: locationsParam,
            optionDrag: true,
            optionMapControl: true,
            optionScroll: true,
            optionStreetView: true,
            optionZoomControl: true,
            style: {},
            width: widthParam ? widthParam : 100,
            widthUnit: widthUnitParam ? widthUnitParam : "pixels",
            zoomLevel: 7
        });
        mockGoogleMaps.setup();
        (output.find(GoogleMap).prop("onGoogleApiLoaded") as any).apply();
        return output;
    };

    beforeAll(() => {
        mxOriginal = window.mx;
        window.google = mockGoogleMaps;
        window.mx = mockMendix;
    });

    it("should render with the map structure", () => {
        const map = setUpMap([ { address } ], undefined, 100, 75, "percentage", "percentageOfWidth");
        const style = { paddingBottom: "75%", width: "100%" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {
                        bootstrapStyle: "danger",
                        className: "widget-google-maps-alert",
                        message: undefined
                    }),
                    createElement(GoogleMap, {
                        bootstrapURLKeys: { key: undefined },
                        center: defaultCenterLocation,
                        defaultZoom: 7,
                        onGoogleApiLoaded: jasmine.any(Function) as any,
                        resetBoundsOnResize: true,
                        yesIWantToUseGoogleMapApiInternals: true
                    })
                )
            ));
    });

    it("should render a structure correctly with pixels", () => {
        const map = setUpMap([ { address } ], undefined, 100, 75, "pixels", "pixels");
        const style = { paddingBottom: "75", width: "100" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {
                        bootstrapStyle: "danger",
                        className: "widget-google-maps-alert",
                        message: undefined
                    }),
                    createElement(GoogleMap, {
                        bootstrapURLKeys: { key: undefined },
                        center: defaultCenterLocation,
                        defaultZoom: 7,
                        onGoogleApiLoaded: jasmine.any(Function) as any,
                        resetBoundsOnResize: true,
                        yesIWantToUseGoogleMapApiInternals: true
                    })
                )
            ));
    });

    it("should render a structure correctly with percentage", () => {
        const map = setUpMap([ { address } ], undefined, 20, 30, "percentage", "pixels");
        const style = { width: "20%", paddingBottom: "30" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {<commit_msg>Fix unit tests<commit_after>import { ShallowWrapper, shallow } from "enzyme";
import GoogleMap from "google-map-react";
import { createElement } from "react";

import { Location, Map, MapProps, heightUnitType, widthUnitType } from "../Map";
import { Marker } from "../Marker";
import { Alert } from "../Alert";

// tslint:disable:no-submodule-imports
import { mockGoogleMaps } from "tests/mocks/GoogleMaps";
import { mockMendix } from "tests/mocks/Mendix";

describe("Map", () => {
    const address = "Lumumba Ave, Kampala, Uganda";
    const invalidAddress = "invalidAddress";
    const APIKey = "<KEY>";
    const renderMap = (props: MapProps) => shallow(createElement(Map, props));
    const defaultCenterLocation = { lat: 51.9107963, lng: 4.4789878 };
    const successMockLocation = { lat: 30, lng: 118 };
    const multipleAddressMockLocation = { lat: 34.213171, lng: -118.571022 };
    let mxOriginal: mx.mx;

    const setUpMap = (
        locationsParam: Location[], APIKeyParam?: string,
        widthParam?: number,
        heightParam?: number,
        widthUnitParam?: widthUnitType,
        heightUnitParam?: heightUnitType,
        defaultCenterParam?: string): ShallowWrapper<MapProps, any> => {
        const output = renderMap({
            apiKey: APIKeyParam,
            autoZoom: true,
            defaultCenterAddress: defaultCenterParam !== undefined ? defaultCenterParam : "",
            height: heightParam ? heightParam : 75,
            heightUnit: heightUnitParam ? heightUnitParam : "pixels",
            locations: locationsParam,
            optionDrag: true,
            optionMapControl: true,
            optionScroll: true,
            optionStreetView: true,
            optionZoomControl: true,
            style: {},
            width: widthParam ? widthParam : 100,
            widthUnit: widthUnitParam ? widthUnitParam : "pixels",
            zoomLevel: 7
        });
        mockGoogleMaps.setup();
        (output.find(GoogleMap).prop("onGoogleApiLoaded") as any).apply();
        return output;
    };

    beforeAll(() => {
        mxOriginal = window.mx;
        window.google = mockGoogleMaps;
        window.mx = mockMendix;
    });

    it("should render with the map structure", () => {
        const map = setUpMap([ { address } ], undefined, 100, 75, "percentage", "percentageOfWidth");
        const style = { paddingBottom: "75%", width: "100%" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {
                        bootstrapStyle: "danger",
                        className: "widget-google-maps-alert",
                        message: undefined
                    }),
                    createElement(GoogleMap, {
                        bootstrapURLKeys: { key: undefined },
                        center: defaultCenterLocation,
                        defaultZoom: 7,
                        onGoogleApiLoaded: jasmine.any(Function) as any,
                        resetBoundsOnResize: true,
                        yesIWantToUseGoogleMapApiInternals: true
                    })
                )
            ));
    });

    it("should render a structure correctly with pixels", () => {
        const map = setUpMap([ { address } ], undefined, 100, 75, "pixels", "pixels");
        const style = { paddingBottom: "75px", width: "100px" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {
                        bootstrapStyle: "danger",
                        className: "widget-google-maps-alert",
                        message: undefined
                    }),
                    createElement(GoogleMap, {
                        bootstrapURLKeys: { key: undefined },
                        center: defaultCenterLocation,
                        defaultZoom: 7,
                        onGoogleApiLoaded: jasmine.any(Function) as any,
                        resetBoundsOnResize: true,
                        yesIWantToUseGoogleMapApiInternals: true
                    })
                )
            ));
    });

    it("should render a structure correctly with percentage", () => {
        const map = setUpMap([ { address } ], undefined, 20, 30, "percentage", "pixels");
        const style = { width: "20%", paddingBottom: "30px" };

        expect(map).toBeElement(
            createElement("div", { className: "widget-google-maps-wrapper", style },
                createElement("div", { className: "widget-google-maps" },
                    createElement(Alert, {
{'fraction_non_alphanumeric': 0.11600207146556188, 'fraction_numerical': 0.015535991714137753, 'mean_word_length': 1.9093100331425128, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '5509009', 'n_tokens_mistral': 2590, 'n_tokens_neox': 2341, 'n_words': 576}