@@ -154,3 +154,129 @@ describe("MilitaryScenario Environment", () => {
154154 expect ( scenario . environment ?. scenarioTime ) . toBe ( "2025-07-09T11:11:00Z" ) ;
155155 } ) ;
156156} ) ;
157+
158+ describe ( "Environment creation" , ( ) => {
159+ it ( "should create an empty Environment using create()" , ( ) => {
160+ const environment = Environment . create ( ) ;
161+ expect ( environment ) . toBeInstanceOf ( Environment ) ;
162+ expect ( environment . element ) . toBeInstanceOf ( Element ) ;
163+ expect ( environment . scenarioTime ) . toBeUndefined ( ) ;
164+ expect ( environment . areaOfInterest ) . toBeUndefined ( ) ;
165+ } ) ;
166+
167+ it ( "should allow setting scenarioTime programmatically" , ( ) => {
168+ const environment = Environment . create ( ) ;
169+ environment . scenarioTime = "2025-12-31T23:59:59Z" ;
170+ expect ( environment . scenarioTime ) . toBe ( "2025-12-31T23:59:59Z" ) ;
171+ expect ( environment . element . outerHTML ) . toContain (
172+ "<ScenarioTime>2025-12-31T23:59:59Z</ScenarioTime>" ,
173+ ) ;
174+ } ) ;
175+
176+ it ( "should allow setting areaOfInterest programmatically" , ( ) => {
177+ const environment = Environment . create ( ) ;
178+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
179+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
180+ const rectangleArea = RectangleArea . create ( upperRight , lowerLeft ) ;
181+ rectangleArea . name = "Test Area" ;
182+
183+ environment . areaOfInterest = rectangleArea ;
184+
185+ expect ( environment . areaOfInterest ) . toBeInstanceOf ( RectangleArea ) ;
186+ expect ( environment . areaOfInterest ?. name ) . toBe ( "Test Area" ) ;
187+ expect ( environment . element . outerHTML ) . toContain ( "<AreaOfInterest>" ) ;
188+ } ) ;
189+
190+ it ( "should allow removing areaOfInterest" , ( ) => {
191+ const environment = new Environment (
192+ parseFromString ( ENVIRONMENT_SAMPLE_MGRS ) ,
193+ ) ;
194+ expect ( environment . areaOfInterest ) . toBeInstanceOf ( RectangleArea ) ;
195+
196+ environment . areaOfInterest = undefined ;
197+ expect ( environment . areaOfInterest ) . toBeUndefined ( ) ;
198+ expect ( environment . element . outerHTML ) . not . toContain ( "<AreaOfInterest>" ) ;
199+ } ) ;
200+ } ) ;
201+
202+ describe ( "RectangleArea creation" , ( ) => {
203+ it ( "should create a RectangleArea using create()" , ( ) => {
204+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
205+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
206+ const rectangleArea = RectangleArea . create ( upperRight , lowerLeft ) ;
207+
208+ expect ( rectangleArea ) . toBeInstanceOf ( RectangleArea ) ;
209+ expect ( rectangleArea . upperRight ) . toBeInstanceOf ( MsdlCoordinates ) ;
210+ expect ( rectangleArea . lowerLeft ) . toBeInstanceOf ( MsdlCoordinates ) ;
211+ } ) ;
212+
213+ it ( "should allow setting name on created RectangleArea" , ( ) => {
214+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
215+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
216+ const rectangleArea = RectangleArea . create ( upperRight , lowerLeft ) ;
217+
218+ rectangleArea . name = "My Area" ;
219+ expect ( rectangleArea . name ) . toBe ( "My Area" ) ;
220+ expect ( rectangleArea . element . outerHTML ) . toContain ( "<Name>My Area</Name>" ) ;
221+ } ) ;
222+
223+ it ( "should compute correct bounding box for created RectangleArea" , ( ) => {
224+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
225+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
226+ const rectangleArea = RectangleArea . create ( upperRight , lowerLeft ) ;
227+
228+ const bbox = rectangleArea . toBoundingBox ( ) ;
229+ expect ( bbox ) . toBeDefined ( ) ;
230+ expect ( bbox ) . toHaveLength ( 4 ) ;
231+ expect ( bbox ! [ 0 ] ) . toBeCloseTo ( 5 , 5 ) ;
232+ expect ( bbox ! [ 1 ] ) . toBeCloseTo ( 15 , 5 ) ;
233+ expect ( bbox ! [ 2 ] ) . toBeCloseTo ( 10 , 5 ) ;
234+ expect ( bbox ! [ 3 ] ) . toBeCloseTo ( 20 , 5 ) ;
235+ } ) ;
236+ } ) ;
237+
238+ describe ( "RectangleArea.fromModel" , ( ) => {
239+ it ( "should create a RectangleArea from a valid model object" , ( ) => {
240+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
241+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
242+ const model = {
243+ name : "Test AOI" ,
244+ upperRight,
245+ lowerLeft,
246+ } ;
247+ const area = RectangleArea . fromModel ( model ) ;
248+ expect ( area ) . toBeInstanceOf ( RectangleArea ) ;
249+ expect ( area . name ) . toBe ( "Test AOI" ) ;
250+ expect ( area . upperRight . location ) . toEqual ( [ 10 , 20 , 0 ] ) ;
251+ expect ( area . lowerLeft . location ) . toEqual ( [ 5 , 15 , 0 ] ) ;
252+ } ) ;
253+
254+ it ( "should throw if upperRight is missing" , ( ) => {
255+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
256+ const model = {
257+ name : "Test AOI" ,
258+ lowerLeft,
259+ } ;
260+ expect ( ( ) => RectangleArea . fromModel ( model as any ) ) . toThrow ( ) ;
261+ } ) ;
262+
263+ it ( "should throw if lowerLeft is missing" , ( ) => {
264+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
265+ const model = {
266+ name : "Test AOI" ,
267+ upperRight,
268+ } ;
269+ expect ( ( ) => RectangleArea . fromModel ( model as any ) ) . toThrow ( ) ;
270+ } ) ;
271+
272+ it ( "should set name to undefined if not provided" , ( ) => {
273+ const upperRight = MsdlCoordinates . createGDCLocation ( [ 10 , 20 , 0 ] ) ;
274+ const lowerLeft = MsdlCoordinates . createGDCLocation ( [ 5 , 15 , 0 ] ) ;
275+ const model = {
276+ upperRight,
277+ lowerLeft,
278+ } ;
279+ const area = RectangleArea . fromModel ( model ) ;
280+ expect ( area . name ) . toBeUndefined ( ) ;
281+ } ) ;
282+ } ) ;
0 commit comments