<commit_before>/**
 * Copyright © 2013 Environmental Systems Research Institute, Inc. (Esri)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at<br>
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define(["cmwapi/cmwapi", "cmwapi-adapter/cmwapi-adapter", "cmwapi-adapter/EsriOverlayManager",
        "test/mock/esriMap", "test/mock/OWF", "test/mock/Ozone"],
        function(CommonMapApi, Adapter, OverlayManager, Map, OWF, Ozone) {

    describe("To test Common Map Widget API ESRI overlay manager", function() {
        describe("Overlay functions", function() {
            var overlayManager;
            var adapter;

            beforeEach(function() {
                window.OWF = OWF;
                window.Ozone = Ozone;
                window.Map = Map;

                adapter = new Adapter(new Map());
                overlayManager = adapter.overlayManager;
            });

            afterEach(function() {
                // Remove our mock objects from the window so neither they nor
                // any spies upon them hang around for other test suites.
                delete window.OWF;
                delete window.Ozone;
                delete window.Map;
            });

            it("verify the overlay create without parent", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(1);
            });

            it("verify the overlay create of two, one with parent", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(1);
                expect(overlays['1111']).toBeDefined();
                expect(overlays['1111'].children).toBeDefined();
                expect(Object.keys(overlays["1111"].children).length).toBe(0)

                overlayManager.overlay.createOverlay("FakeWidget 1", "2222", "Name 2", "1111");
                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(2);
                expect(overlays['1111']).toBeDefined();
                expect(overlays['1111'].children).toBeDefined();
                expect(Object.keys(overlays["1111"].children).length).toBe(1)
                expect(overlays["1111"].children["2222"]).toBeDefined();

                overlays["2222"].name = "New Name 2";
                expect(overlays["1111"].children["2222"].name).toBe("New Name 2");
            });


            it("verify overlay create with duplicate id calls update", function() {
                var update = spyOn(overlayManager.overlay, 'updateOverlay').andCallThrough();

                expect(Object.keys(overlayManager.getOverlays()).length).toBe(0);

                //create the overlay
                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                expect(update).not.toHaveBeenCalled();

                //create with same ID
                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 2");

                expect(update).toHaveBeenCalledWith("FakeWidget", "1111", "Name 2", undefined);
            });

            it("verify overlay remove of one", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("fake widget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(1);

                overlayManager.overlay.removeOverlay("FakeWidget2", "1111")
                overlays = overlayManager.getOverlays();<commit_msg>Updating a test to handle the change to createOverlay not issues updates for exisiting overlays.  Updates should be done through the update method.<commit_after>/**
 * Copyright © 2013 Environmental Systems Research Institute, Inc. (Esri)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at<br>
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define(["cmwapi/cmwapi", "cmwapi-adapter/cmwapi-adapter", "cmwapi-adapter/EsriOverlayManager",
        "test/mock/esriMap", "test/mock/OWF", "test/mock/Ozone"],
        function(CommonMapApi, Adapter, OverlayManager, Map, OWF, Ozone) {

    describe("To test Common Map Widget API ESRI overlay manager", function() {
        describe("Overlay functions", function() {
            var overlayManager;
            var adapter;

            beforeEach(function() {
                window.OWF = OWF;
                window.Ozone = Ozone;
                window.Map = Map;

                adapter = new Adapter(new Map());
                overlayManager = adapter.overlayManager;
            });

            afterEach(function() {
                // Remove our mock objects from the window so neither they nor
                // any spies upon them hang around for other test suites.
                delete window.OWF;
                delete window.Ozone;
                delete window.Map;
            });

            it("verify the overlay create without parent", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(1);
            });

            it("verify the overlay create of two, one with parent", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(1);
                expect(overlays['1111']).toBeDefined();
                expect(overlays['1111'].children).toBeDefined();
                expect(Object.keys(overlays["1111"].children).length).toBe(0)

                overlayManager.overlay.createOverlay("FakeWidget 1", "2222", "Name 2", "1111");
                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(2);
                expect(overlays['1111']).toBeDefined();
                expect(overlays['1111'].children).toBeDefined();
                expect(Object.keys(overlays["1111"].children).length).toBe(1)
                expect(overlays["1111"].children["2222"]).toBeDefined();

                overlays["2222"].name = "New Name 2";
                expect(overlays["1111"].children["2222"].name).toBe("New Name 2");
            });


            it("verify overlay create with duplicate id is a no-op and does not update an overlay.", function() {
                var update = spyOn(overlayManager.overlay, 'updateOverlay').andCallThrough();

                expect(Object.keys(overlayManager.getOverlays()).length).toBe(0);

                //create the overlay
                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 1");

                expect(update).not.toHaveBeenCalled();

                //create with same ID
                overlayManager.overlay.createOverlay("FakeWidget", "1111", "Name 2");

                expect(update).not.toHaveBeenCalled();
                
                var overlays = overlayManager.getOverlays();
                expect(overlays["1111"].name).toEqual("Name 1");
            });

            it("verify overlay remove of one", function() {
                var overlays = overlayManager.getOverlays();

                expect(Object.keys(overlays).length).toBe(0);

                overlayManager.overlay.createOverlay("fake widget", "1111", "Name 1");

                overlays = overlayManager.getOverlays();
                expect(Object.keys(overlays).length).toBe(1);

                overlayManager.overlay.removeOverlay("FakeWidget2", "1111")
                overlays = overlayManager.getOverlays();
{'fraction_non_alphanumeric': 0.11921518447430156, 'fraction_numerical': 0.023245894647046277, 'mean_word_length': 2.2097878165639973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3828562', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2317, 'n_words': 583}