1717import assert from "node:assert" ;
1818import { describe , it , beforeEach } from "node:test" ;
1919import { v0_8 } from "@a2ui/web-lib" ;
20+ import { DataMap , DataValue } from "./types/types" ;
2021
2122// Helper function to strip reactivity for clean comparisons.
2223const toPlainObject = ( value : unknown ) : ReturnType < typeof JSON . parse > => {
@@ -87,8 +88,8 @@ describe("A2UIModelProcessor", () => {
8788
8889 const defaultSurface = surfaces . get ( "@default" ) ;
8990 assert . ok ( defaultSurface , "Default surface should exist" ) ;
90- assert . strictEqual ( defaultSurface . rootComponentId , "comp-a" ) ;
91- assert . deepStrictEqual ( defaultSurface . styles , { color : "blue" } ) ;
91+ assert . strictEqual ( defaultSurface ! . rootComponentId , "comp-a" ) ;
92+ assert . deepStrictEqual ( defaultSurface ! . styles , { color : "blue" } ) ;
9293 } ) ;
9394
9495 it ( "should handle `surfaceUpdate` by adding components" , ( ) => {
@@ -112,8 +113,8 @@ describe("A2UIModelProcessor", () => {
112113 if ( ! surface ) {
113114 assert . fail ( "No default surface" ) ;
114115 }
115- assert . strictEqual ( surface . components . size , 1 ) ;
116- assert . ok ( surface . components . has ( "comp-a" ) ) ;
116+ assert . strictEqual ( surface ! . components . size , 1 ) ;
117+ assert . ok ( surface ! . components . has ( "comp-a" ) ) ;
117118 } ) ;
118119
119120 it ( "should handle `deleteSurface`" , ( ) => {
@@ -290,10 +291,7 @@ describe("A2UIModelProcessor", () => {
290291 ) ;
291292
292293 // Check that it's a Map and has the first item.
293- assert . ok (
294- messagesData instanceof Map ,
295- "Data at /messages should be a Map"
296- ) ;
294+ assertIsDataMap ( messagesData ) ;
297295 assert . strictEqual ( messagesData . size , 1 ) ;
298296 assert . strictEqual ( messagesData . get ( key1 ) , message1 ) ;
299297
@@ -322,13 +320,10 @@ describe("A2UIModelProcessor", () => {
322320 ) ;
323321
324322 // 4. Check that the Map was additively updated and now has both items.
325- assert . ok (
326- messagesData instanceof Map ,
327- "Data at /messages should still be a Map"
328- ) ;
323+ assertIsDataMap ( messagesData ) ;
329324 assert . strictEqual ( messagesData . size , 2 , "Map should have 2 items total" ) ;
330325 assert . strictEqual (
331- messagesData . get ( key1 ) ,
326+ ( messagesData as DataMap ) . get ( key1 ) ,
332327 message1 ,
333328 "First item correct"
334329 ) ;
@@ -1311,26 +1306,32 @@ describe("A2UIModelProcessor", () => {
13111306 assert . ok ( surfaceA && surfaceB , "Both surfaces should exist" ) ;
13121307
13131308 // Check Surface A
1314- assert . strictEqual ( surfaceA . components . size , 1 ) ;
1315- assert . ok ( surfaceA . components . has ( "comp-a" ) ) ;
1316- assert . deepStrictEqual ( toPlainObject ( surfaceA . dataModel ) , {
1309+ assert . ok ( surfaceA , "Surface A exists." ) ;
1310+ assert . strictEqual ( surfaceA ! . components . size , 1 ) ;
1311+ assert . ok ( surfaceA ! . components . has ( "comp-a" ) ) ;
1312+ assert . deepStrictEqual ( toPlainObject ( surfaceA ! . dataModel ) , {
13171313 name : "Surface A Data" ,
13181314 } ) ;
13191315 assert . deepStrictEqual (
1320- toPlainObject ( surfaceA . componentTree ) . properties . text ,
1316+ toPlainObject ( surfaceA ! . componentTree ) . properties . text ,
13211317 { path : "/name" }
13221318 ) ;
13231319
13241320 // Check Surface B
1325- assert . strictEqual ( surfaceB . components . size , 1 ) ;
1326- assert . ok ( surfaceB . components . has ( "comp-b" ) ) ;
1327- assert . deepStrictEqual ( toPlainObject ( surfaceB . dataModel ) , {
1321+ assert . ok ( surfaceB , "Surface B exists." ) ;
1322+ assert . strictEqual ( surfaceB ! . components . size , 1 ) ;
1323+ assert . ok ( surfaceB ! . components . has ( "comp-b" ) ) ;
1324+ assert . deepStrictEqual ( toPlainObject ( surfaceB ! . dataModel ) , {
13281325 name : "Surface B Data" ,
13291326 } ) ;
13301327 assert . deepStrictEqual (
1331- toPlainObject ( surfaceB . componentTree ) . properties . text ,
1328+ toPlainObject ( surfaceB ! . componentTree ) . properties . text ,
13321329 { path : "/name" }
13331330 ) ;
13341331 } ) ;
13351332 } ) ;
13361333} ) ;
1334+
1335+ function assertIsDataMap ( obj : DataValue ) : asserts obj is DataMap {
1336+ assert . ok ( obj instanceof Map , `Data should be a DataMap` ) ;
1337+ }
0 commit comments