|
| 1 | +/* |
| 2 | + * Copyright 2026, GeoSolutions Sas. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | +import expect from 'expect'; |
| 9 | +import React from 'react'; |
| 10 | +import { Provider } from 'react-redux'; |
| 11 | +import ReactDOM from 'react-dom'; |
| 12 | +import MapSettings from '../mapsettings/MapSettings'; |
| 13 | +import configureMockStore from 'redux-mock-store'; |
| 14 | + |
| 15 | +const mockStore = configureMockStore(); |
| 16 | + |
| 17 | +// Helper: render MapSettings inside a Provider with a Cesium store |
| 18 | +const renderCesium = (mapOptions = {}, extraProps = {}) => { |
| 19 | + const store = mockStore({ |
| 20 | + map: { present: { mapOptions } }, |
| 21 | + maptype: { mapType: 'cesium' } |
| 22 | + }); |
| 23 | + ReactDOM.render( |
| 24 | + <Provider store={store}> |
| 25 | + <MapSettings {...extraProps} /> |
| 26 | + </Provider>, |
| 27 | + document.getElementById('container') |
| 28 | + ); |
| 29 | +}; |
| 30 | + |
| 31 | +// Helper: render MapSettings inside a Provider with an OpenLayers store |
| 32 | +const renderOL = (mapOptions = {}) => { |
| 33 | + const store = mockStore({ |
| 34 | + map: { present: { mapOptions } }, |
| 35 | + maptype: { mapType: 'openlayers' } |
| 36 | + }); |
| 37 | + ReactDOM.render( |
| 38 | + <Provider store={store}><MapSettings /></Provider>, |
| 39 | + document.getElementById('container') |
| 40 | + ); |
| 41 | +}; |
| 42 | + |
| 43 | +describe('MapSettings component', () => { |
| 44 | + beforeEach((done) => { |
| 45 | + document.body.innerHTML = '<div id="container"></div>'; |
| 46 | + setTimeout(done); |
| 47 | + }); |
| 48 | + |
| 49 | + afterEach((done) => { |
| 50 | + ReactDOM.unmountComponentAtNode(document.getElementById('container')); |
| 51 | + document.body.innerHTML = ''; |
| 52 | + setTimeout(done); |
| 53 | + }); |
| 54 | + |
| 55 | + it('renders nothing when isCesium is false (OL map)', () => { |
| 56 | + renderOL(); |
| 57 | + const container = document.getElementById('container'); |
| 58 | + expect(container.innerHTML).toBeFalsy(); |
| 59 | + const form = document.querySelector('form'); |
| 60 | + expect(form).toBeFalsy(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('renders a form when isCesium is true', () => { |
| 64 | + renderCesium(); |
| 65 | + const form = document.querySelector('form'); |
| 66 | + expect(form).toBeTruthy(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('renders all 6 Cesium checkboxes', () => { |
| 70 | + renderCesium(); |
| 71 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 72 | + expect(checkboxes.length).toBe(6); |
| 73 | + }); |
| 74 | + |
| 75 | + it('renders the lighting select dropdown', () => { |
| 76 | + renderCesium(); |
| 77 | + const selects = document.querySelectorAll('.Select'); |
| 78 | + expect(selects.length).toBeGreaterThan(0); |
| 79 | + }); |
| 80 | + |
| 81 | + it('showSkyAtmosphere checkbox reflects mapOptions value when true', () => { |
| 82 | + renderCesium({ showSkyAtmosphere: true }); |
| 83 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 84 | + expect(checkboxes[0].checked).toBe(true); |
| 85 | + }); |
| 86 | + |
| 87 | + it('showSkyAtmosphere checkbox reflects mapOptions value when false', () => { |
| 88 | + renderCesium({ showSkyAtmosphere: false }); |
| 89 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 90 | + expect(checkboxes[0].checked).toBe(false); |
| 91 | + }); |
| 92 | + |
| 93 | + it('showGroundAtmosphere checkbox reflects mapOptions value', () => { |
| 94 | + renderCesium({ showGroundAtmosphere: true }); |
| 95 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 96 | + expect(checkboxes[1].checked).toBe(true); |
| 97 | + }); |
| 98 | + |
| 99 | + it('enableFog checkbox reflects mapOptions value', () => { |
| 100 | + renderCesium({ enableFog: true }); |
| 101 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 102 | + expect(checkboxes[2].checked).toBe(true); |
| 103 | + }); |
| 104 | + |
| 105 | + it('depthTestAgainstTerrain checkbox reflects mapOptions value', () => { |
| 106 | + renderCesium({ depthTestAgainstTerrain: true }); |
| 107 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 108 | + expect(checkboxes[3].checked).toBe(true); |
| 109 | + }); |
| 110 | + |
| 111 | + it('enableCollisionDetection defaults to true when not set in mapOptions', () => { |
| 112 | + renderCesium(); |
| 113 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 114 | + expect(checkboxes[4].checked).toBe(true); |
| 115 | + }); |
| 116 | + |
| 117 | + it('enableCollisionDetection reflects mapOptions value when explicitly set to false', () => { |
| 118 | + renderCesium({ enableCollisionDetection: false }); |
| 119 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 120 | + expect(checkboxes[4].checked).toBe(false); |
| 121 | + }); |
| 122 | + |
| 123 | + it('enableImageryLayersOverlay defaults to true when not set in mapOptions', () => { |
| 124 | + renderCesium(); |
| 125 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 126 | + expect(checkboxes[5].checked).toBe(true); |
| 127 | + }); |
| 128 | + |
| 129 | + it('enableImageryLayersOverlay reflects mapOptions value when explicitly set to false', () => { |
| 130 | + renderCesium({ enableImageryLayersOverlay: false }); |
| 131 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 132 | + expect(checkboxes[5].checked).toBe(false); |
| 133 | + }); |
| 134 | + |
| 135 | + it('does not render DateTime picker when lighting is sunlight', () => { |
| 136 | + renderCesium({ lighting: { value: 'sunlight' } }); |
| 137 | + const datePicker = document.querySelector('.lighting-dateTime-picker'); |
| 138 | + expect(datePicker).toBeFalsy(); |
| 139 | + }); |
| 140 | + |
| 141 | + it('does not render DateTime picker when lighting is flashlight', () => { |
| 142 | + renderCesium({ lighting: { value: 'flashlight' } }); |
| 143 | + const datePicker = document.querySelector('.lighting-dateTime-picker'); |
| 144 | + expect(datePicker).toBeFalsy(); |
| 145 | + }); |
| 146 | + |
| 147 | + it('renders DateTime picker when lighting is set to dateTime', () => { |
| 148 | + renderCesium({ lighting: { value: 'dateTime', dateTime: new Date().toISOString() } }); |
| 149 | + const datePicker = document.querySelector('.lighting-dateTime-picker'); |
| 150 | + expect(datePicker).toBeTruthy(); |
| 151 | + }); |
| 152 | + |
| 153 | + it('uses defaultMapOptions prop when map.mapOptions is empty', () => { |
| 154 | + renderCesium({}, { mapOptions: { cesium: { showSkyAtmosphere: true, enableFog: true } } }); |
| 155 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 156 | + expect(checkboxes[0].checked).toBe(true); |
| 157 | + expect(checkboxes[2].checked).toBe(true); |
| 158 | + }); |
| 159 | + |
| 160 | + it('map.mapOptions overrides defaultMapOptions prop', () => { |
| 161 | + renderCesium( |
| 162 | + { showSkyAtmosphere: false }, |
| 163 | + { mapOptions: { cesium: { showSkyAtmosphere: true } } } |
| 164 | + ); |
| 165 | + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); |
| 166 | + expect(checkboxes[0].checked).toBe(false); |
| 167 | + }); |
| 168 | +}); |
0 commit comments