From 79e25a555fe2adf58f31c089f765abfdeca88624 Mon Sep 17 00:00:00 2001 From: Mingbo Peng Date: Sun, 29 Sep 2024 13:02:50 +0800 Subject: [PATCH] test(Ts): test for both HB and DF --- src/TypeScriptSDK.Tests/.gitignore | 28 ++ src/TypeScriptSDK.Tests/jest.config.js | 7 - src/TypeScriptSDK.Tests/jest.config.ts | 201 ++++++++++++++ src/TypeScriptSDK.Tests/package.json | 14 +- src/TypeScriptSDK.Tests/src/Model.test.ts | 244 +++++++++++++++++ src/TypeScriptSDK.Tests/src/Room2D.test.ts | 299 +++++++++++++++++++++ src/TypeScriptSDK.Tests/src/jest.setup.ts | 1 + src/TypeScriptSDK.Tests/src/sum.test.ts | 27 +- src/TypeScriptSDK.Tests/tsconfig.json | 14 +- 9 files changed, 813 insertions(+), 22 deletions(-) create mode 100644 src/TypeScriptSDK.Tests/.gitignore delete mode 100644 src/TypeScriptSDK.Tests/jest.config.js create mode 100644 src/TypeScriptSDK.Tests/jest.config.ts create mode 100644 src/TypeScriptSDK.Tests/src/Model.test.ts create mode 100644 src/TypeScriptSDK.Tests/src/Room2D.test.ts create mode 100644 src/TypeScriptSDK.Tests/src/jest.setup.ts diff --git a/src/TypeScriptSDK.Tests/.gitignore b/src/TypeScriptSDK.Tests/.gitignore new file mode 100644 index 0000000..b88c813 --- /dev/null +++ b/src/TypeScriptSDK.Tests/.gitignore @@ -0,0 +1,28 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/src/TypeScriptSDK.Tests/jest.config.js b/src/TypeScriptSDK.Tests/jest.config.js deleted file mode 100644 index f5d30d1..0000000 --- a/src/TypeScriptSDK.Tests/jest.config.js +++ /dev/null @@ -1,7 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} **/ -module.exports = { - testEnvironment: "node", - transform: { - "^.+.tsx?$": ["ts-jest",{}], - }, -}; \ No newline at end of file diff --git a/src/TypeScriptSDK.Tests/jest.config.ts b/src/TypeScriptSDK.Tests/jest.config.ts new file mode 100644 index 0000000..d00111b --- /dev/null +++ b/src/TypeScriptSDK.Tests/jest.config.ts @@ -0,0 +1,201 @@ +/** + * For a detailed explanation regarding each configuration property, visit: + * https://jestjs.io/docs/configuration + */ + +import type {Config} from 'jest'; + +const config: Config = { + // All imported modules in your tests should be mocked automatically + // automock: false, + + // Stop running tests after `n` failures + // bail: 0, + + // The directory where Jest should store its cached dependency information + // cacheDirectory: "C:\\Users\\mingo\\AppData\\Local\\Temp\\jest", + + // Automatically clear mock calls, instances, contexts and results before every test + clearMocks: true, + + // Indicates whether the coverage information should be collected while executing the test + // collectCoverage: false, + + // An array of glob patterns indicating a set of files for which coverage information should be collected + // collectCoverageFrom: undefined, + + // The directory where Jest should output its coverage files + // coverageDirectory: undefined, + + // An array of regexp pattern strings used to skip coverage collection + // coveragePathIgnorePatterns: [ + // "\\\\node_modules\\\\" + // ], + + // Indicates which provider should be used to instrument code for coverage + // coverageProvider: "v8", + + // A list of reporter names that Jest uses when writing coverage reports + // coverageReporters: [ + // "json", + // "text", + // "lcov", + // "clover" + // ], + + // An object that configures minimum threshold enforcement for coverage results + // coverageThreshold: undefined, + + // A path to a custom dependency extractor + // dependencyExtractor: undefined, + + // Make calling deprecated APIs throw helpful error messages + // errorOnDeprecated: false, + + // The default configuration for fake timers + // fakeTimers: { + // "enableGlobally": false + // }, + + // Force coverage collection from ignored files using an array of glob patterns + // forceCoverageMatch: [], + + // A path to a module which exports an async function that is triggered once before all test suites + // globalSetup: undefined, + + // A path to a module which exports an async function that is triggered once after all test suites + // globalTeardown: undefined, + + // A set of global variables that need to be available in all test environments + // globals: {}, + + // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. + // maxWorkers: "50%", + + // An array of directory names to be searched recursively up from the requiring module's location + // moduleDirectories: [ + // "node_modules" + // ], + + // An array of file extensions your modules use + // moduleFileExtensions: [ + // "js", + // "mjs", + // "cjs", + // "jsx", + // "ts", + // "tsx", + // "json", + // "node" + // ], + + // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module + // moduleNameMapper: {}, + + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader + // modulePathIgnorePatterns: [], + + // Activates notifications for test results + // notify: false, + + // An enum that specifies notification mode. Requires { notify: true } + // notifyMode: "failure-change", + + // A preset that is used as a base for Jest's configuration + // preset: undefined, + + // Run tests from one or more projects + // projects: undefined, + + // Use this configuration option to add custom reporters to Jest + // reporters: undefined, + + // Automatically reset mock state before every test + // resetMocks: false, + + // Reset the module registry before running each individual test + // resetModules: false, + + // A path to a custom resolver + // resolver: undefined, + + // Automatically restore mock state and implementation before every test + // restoreMocks: false, + + // The root directory that Jest should scan for tests and modules within + // rootDir: undefined, + + // A list of paths to directories that Jest should use to search for files in + // roots: [ + // "" + // ], + + // Allows you to use a custom runner instead of Jest's default test runner + // runner: "jest-runner", + + // The paths to modules that run some code to configure or set up the testing environment before each test + setupFiles: ['./src/jest.setup.ts'], + + // A list of paths to modules that run some code to configure or set up the testing framework before each test + // setupFilesAfterEnv: [], + + // The number of seconds after which a test is considered as slow and reported as such in the results. + // slowTestThreshold: 5, + + // A list of paths to snapshot serializer modules Jest should use for snapshot testing + // snapshotSerializers: [], + + // The test environment that will be used for testing + // testEnvironment: "jest-environment-node", + + // Options that will be passed to the testEnvironment + // testEnvironmentOptions: {}, + + // Adds a location field to test results + // testLocationInResults: false, + + // The glob patterns Jest uses to detect test files + // testMatch: [ + // "**/__tests__/**/*.[jt]s?(x)", + // "**/?(*.)+(spec|test).[tj]s?(x)" + // ], + + // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped + // testPathIgnorePatterns: [ + // "\\\\node_modules\\\\" + // ], + + // The regexp pattern or array of patterns that Jest uses to detect test files + // testRegex: [], + + // This option allows the use of a custom results processor + // testResultsProcessor: undefined, + + // This option allows use of a custom test runner + // testRunner: "jest-circus/runner", + + // A map from regular expressions to paths to transformers + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, + + // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation + // transformIgnorePatterns: [ + // "\\\\node_modules\\\\", + // "\\.pnp\\.[^\\\\]+$" + // ], + + // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them + // unmockedModulePathPatterns: undefined, + + // Indicates whether each individual test should be reported during the run + // verbose: undefined, + + // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode + // watchPathIgnorePatterns: [], + + // Whether to use watchman for file crawling + // watchman: true, +}; + +export default config; diff --git a/src/TypeScriptSDK.Tests/package.json b/src/TypeScriptSDK.Tests/package.json index 2798624..d19ebb8 100644 --- a/src/TypeScriptSDK.Tests/package.json +++ b/src/TypeScriptSDK.Tests/package.json @@ -1,18 +1,18 @@ { - "name": "typescriptsdk.tests", - "version": "1.0.0", - "description": "", - "main": "index.js", "scripts": { + "compile": "tsc", "test": "jest" }, - "keywords": [], - "author": "", - "license": "ISC", "devDependencies": { "@types/jest": "^29.5.13", "jest": "^29.7.0", + "reflect-metadata": "^0.2.2", "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", "typescript": "^5.6.2" + }, + "dependencies": { + "honeybee-schema": "latest", + "dragonfly-schema": "latest" } } diff --git a/src/TypeScriptSDK.Tests/src/Model.test.ts b/src/TypeScriptSDK.Tests/src/Model.test.ts new file mode 100644 index 0000000..4001d9f --- /dev/null +++ b/src/TypeScriptSDK.Tests/src/Model.test.ts @@ -0,0 +1,244 @@ +import { plainToClass } from "class-transformer"; +import { Model } from "dragonfly-schema"; +import { DoorModifierSetAbridged, Face3D, GlobalModifierSet, ModelProperties, Plastic, WallConstructionSetAbridged, WallModifierSetAbridged } from "honeybee-schema"; +import * as fs from 'fs'; +import * as path from 'path'; + +test('test model', () => { + const dir = path.dirname(path.dirname(path.dirname(__dirname))); + const sampleDir = path.join(dir, 'samples'); + console.log(sampleDir); + + const filePath = path.join(sampleDir, 'Room_with_complex_skylights.dfjson'); + const jsonData = fs.readFileSync(filePath, 'utf8'); + // console.log(jsonData); + + const json = JSON.parse(jsonData); + const model = Model.fromJS(json); + expect(model.identifier).toBe("unnamed_cb67f62e"); +// const + expect(model.validate()).resolves.toBe(true); + +} +); + +test('test wallSet', () => { + const data = { + interior_construction: "Generic Interior Wall", + exterior_construction: "Generic Exterior Wall", + type: "WallConstructionSetAbridged", + } + const obj = WallConstructionSetAbridged.fromJS(data); + expect(obj.validate()).resolves.toBe(true); + + const jsonObj = obj.toJSON(); + expect(jsonObj.type).toBe("WallConstructionSetAbridged"); + expect(jsonObj).toHaveProperty("interior_construction"); + expect(jsonObj.hasOwnProperty("ground_construction")).toBe(false); + +} +); + +const GlobalModifierSetData = { + "shade_set": { + "type": "ShadeModifierSetAbridged", + "interior_modifier": "generic_interior_shade_0.50", + "exterior_modifier": "generic_exterior_shade_0.35" + }, + "roof_ceiling_set": { + "type": "RoofCeilingModifierSetAbridged", + "interior_modifier": "generic_ceiling_0.80", + "exterior_modifier": "generic_ceiling_0.80" + }, + "context_modifier": "generic_context_0.20", + "modifiers": [ + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.5, + "identifier": "generic_wall_0.50", + "specularity": 0, + "b_reflectance": 0.5, + "r_reflectance": 0.5, + "type": "Plastic", + "roughness": 0 + }, + { + "b_transmissivity": 0.9584154328610596, + "r_transmissivity": 0.9584154328610596, + "modifier": null, + "identifier": "generic_interior_window_vis_0.88", + "refraction_index": null, + "type": "Glass", + "dependencies": [], + "g_transmissivity": 0.9584154328610596 + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.5, + "identifier": "generic_interior_shade_0.50", + "specularity": 0, + "b_reflectance": 0.5, + "r_reflectance": 0.5, + "type": "Plastic", + "roughness": 0 + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.2, + "identifier": "generic_floor_0.20", + "specularity": 0, + "b_reflectance": 0.2, + "r_reflectance": 0.2, + "type": "Plastic", + "roughness": 0 + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.8, + "identifier": "generic_ceiling_0.80", + "specularity": 0, + "b_reflectance": 0.8, + "r_reflectance": 0.8, + "type": "Plastic", + "roughness": 0 + }, + { + "b_transmissivity": 0.6975761815384331, + "r_transmissivity": 0.6975761815384331, + "modifier": null, + "identifier": "generic_exterior_window_vis_0.64", + "refraction_index": null, + "type": "Glass", + "dependencies": [], + "g_transmissivity": 0.6975761815384331 + }, + { + "r_reflectance": 1, + "b_reflectance": 1, + "roughness": 0, + "identifier": "air_boundary", + "type": "Trans", + "dependencies": [], + "g_reflectance": 1, + "specularity": 0, + "transmitted_diff": 1, + "transmitted_spec": 1, + "modifier": null + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.35, + "identifier": "generic_exterior_shade_0.35", + "specularity": 0, + "b_reflectance": 0.35, + "r_reflectance": 0.35, + "type": "Plastic", + "roughness": 0 + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.5, + "identifier": "generic_opaque_door_0.50", + "specularity": 0, + "b_reflectance": 0.5, + "r_reflectance": 0.5, + "type": "Plastic", + "roughness": 0 + }, + { + "dependencies": [], + "modifier": null, + "g_reflectance": 0.2, + "identifier": "generic_context_0.20", + "specularity": 0, + "b_reflectance": 0.2, + "r_reflectance": 0.2, + "type": "Plastic", + "roughness": 0 + } + ], + "wall_set": { + "type": "WallModifierSetAbridged", + "interior_modifier": "generic_wall_0.50", + "exterior_modifier": "generic_wall_0.50" + }, + "door_set": { + "exterior_glass_modifier": "generic_exterior_window_vis_0.64", + "interior_glass_modifier": "generic_interior_window_vis_0.88", + "overhead_modifier": "generic_opaque_door_0.50", + "exterior_modifier": "generic_opaque_door_0.50", + "interior_modifier": "generic_opaque_door_0.50", + "type": "DoorModifierSetAbridged" + }, + "floor_set": { + "type": "FloorModifierSetAbridged", + "interior_modifier": "generic_floor_0.20", + "exterior_modifier": "generic_floor_0.20" + }, + "type": "GlobalModifierSet", + "aperture_set": { + "interior_modifier": "generic_interior_window_vis_0.88", + "window_modifier": "generic_exterior_window_vis_0.64", + "skylight_modifier": "generic_exterior_window_vis_0.64", + "type": "ApertureModifierSetAbridged", + "operable_modifier": "generic_exterior_window_vis_0.64" + }, + "air_boundary_modifier": "air_boundary" +}; + +test('test GlobalModifierSet', () => { + const data = GlobalModifierSetData; + const obj = GlobalModifierSet.fromJS(data); + expect(obj.validate()).resolves.toBe(true); + expect(obj.modifiers?.at(0)).toBeInstanceOf(Plastic) + expect(obj.door_set).toBeInstanceOf(DoorModifierSetAbridged); + + const jsonObj = obj.toJSON(); + expect(jsonObj.type).toBe("GlobalModifierSet"); + expect(jsonObj).toHaveProperty("wall_set"); + expect(jsonObj.wall_set).toHaveProperty("interior_modifier"); + expect(jsonObj.wall_set.hasOwnProperty("ground_construction")).toBe(false); + +} +); + +test('test ModelProperties', () => { + const data = { + "radiance": + { + "global_modifier_set":GlobalModifierSetData + } + } + const obj = ModelProperties.fromJS(data); + // expect(obj.validate()).resolves.toBe(true); + expect(obj.radiance?.global_modifier_set?.wall_set).toBeInstanceOf(WallModifierSetAbridged); + + } +); + +test('test global wall set instance', () => { + const data = { + "properties": + { + "radiance": + { + "global_modifier_set":GlobalModifierSetData + } + } + } + + // const model = plainToClass(Model, data, { enableImplicitConversion: true }); + const obj = Model.fromJS(data); + expect(obj.properties.radiance?.global_modifier_set?.wall_set).toBeInstanceOf(WallModifierSetAbridged); + // expect(obj.validate()).resolves.toBe(true); + + } +); + + diff --git a/src/TypeScriptSDK.Tests/src/Room2D.test.ts b/src/TypeScriptSDK.Tests/src/Room2D.test.ts new file mode 100644 index 0000000..d09c41c --- /dev/null +++ b/src/TypeScriptSDK.Tests/src/Room2D.test.ts @@ -0,0 +1,299 @@ +import { plainToClass } from "class-transformer"; +import { Model, Room2D, Room2DPropertiesAbridged } from "dragonfly-schema"; +import { Face3D } from "honeybee-schema"; +import * as fs from 'fs'; +import * as path from 'path'; + +test('test room2d', () => { + const roomData = { + "type": "Room2D", + "identifier": "Room_e6ac360b-aaed-4c3b-a130-36b4c2ac9d13-000d1467", + "display_name": "Master Bedroom-206", + "properties": { + "type": "Room2DPropertiesAbridged", + "energy": { "type": "Room2DEnergyPropertiesAbridged" } + }, + "floor_boundary": [ + [1.061931517437636, 2.8994060214182706], + [-4.888068482562394, 2.899406021418289], + [-4.8880684825623835, -3.302593978581498], + [-1.378068482562382, -3.302593978581509], + [-1.3780684825623764, 0.038406021418214205], + [-0.18806848256237596, 0.03840602141821037], + [1.0619315174376316, 0.03840602141820621], + [1.0619315174376338, 1.358406021418206] + ], + "floor_height": 3.0000000000000004, + "floor_to_ceiling_height": 6.000000000000001, + "is_ground_contact": false, + "is_top_exposed": true, + "boundary_conditions": [ + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + } + ], + "window_parameters": [ + { + "type": "DetailedWindows", + "polygons": [ + [ + [3.0000000000000084, 2.6999999999999935], + [4.500000000000007, 2.6999999999999926], + [4.500000000000007, 0.0009143999999994932], + [3.0000000000000084, 0.0009144000000000347] + ] + ], + "are_doors": [false], + "user_data": {} + }, + { + "type": "DetailedWindows", + "polygons": [ + [ + [1.620999999999999, 0.04000000000000011], + [1.620999999999999, 2.0800000000000005], + [3.0809999999999995, 2.0800000000000005], + [3.0809999999999995, 0.04000000000000011] + ], + [ + [3.120999999999999, 0.04000000000000011], + [3.120999999999999, 2.0800000000000005], + [4.581, 2.0800000000000005], + [4.581, 0.04000000000000011] + ], + [ + [4.620999999999893, 0.04000000000000011], + [4.620999999999893, 2.0800000000000005], + [6.060999999999892, 2.0800000000000005], + [6.060999999999892, 0.04000000000000011] + ], + [ + [0.25884214488802365, 3.02], + [1.5809999999999995, 4.39435106696338], + [1.5809999999999995, 3.02] + ], + [ + [1.620999999999999, 4.435930098140318], + [2.9876230980831053, 5.856501708198367], + [3.080999999999999, 5.766670945649302], + [3.080999999999999, 3.02], + [1.6209999999999998, 3.02] + ], + [ + [3.121, 3.02], + [3.121, 5.728190010555089], + [4.581, 4.323635879616347], + [4.581, 3.02] + ], + [ + [4.6209999999999996, 3.02], + [4.6209999999999996, 4.285154944522135], + [5.9360979220485985, 3.02] + ], + [ + [0.14099999999999935, 2.12], + [0.14099999999999935, 2.897505944593588], + [0.22036120979381166, 2.9800000000000004], + [1.5809999999999993, 2.9800000000000004], + [1.5809999999999993, 2.12] + ], + [ + [1.6209999999999993, 2.12], + [1.6209999999999993, 2.9800000000000004], + [3.080999999999999, 2.9800000000000004], + [3.080999999999999, 2.12] + ], + [ + [3.121, 2.12], + [3.121, 2.9800000000000004], + [4.5809999999999995, 2.9800000000000004], + [4.5809999999999995, 2.12] + ], + [ + [4.620999999999999, 2.12], + [4.620999999999999, 2.9800000000000004], + [5.977676953225537, 2.9800000000000004], + [6.060999999999788, 2.899841281130703], + [6.060999999999788, 2.12] + ] + ], + "are_doors": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ], + "user_data": {} + }, + { + "type": "DetailedWindows", + "polygons": [ + [ + [1.4500000000000255, 0.0009143999999994932], + [1.4500000000000255, 2.6999999999999926], + [2.950000000000024, 2.6999999999999935], + [2.950000000000024, 0.0009144000000000347] + ] + ], + "are_doors": [false], + "user_data": {} + }, + null, + null, + null, + null, + null + ], + "user_data": {} + } + const obj = Room2D.fromJS(roomData); + expect(obj.identifier).toBe("Room_e6ac360b-aaed-4c3b-a130-36b4c2ac9d13-000d1467"); + expect(obj.validate()).resolves.toBe(true); + + const jsonObj = obj.toJSON(); + const prop = jsonObj["properties"]; + expect(prop["energy"].hasOwnProperty("hvac")).toBe(false); + expect(prop.hasOwnProperty("radiance")).toBe(false); + + +}); + +test('test room2d2', () => { + const roomData = { + "type": "Room2D", + "identifier": "Room_e6ac360b-aaed-4c3b-a130-36b4c2ac9d13-000d14cc", + "display_name": "Laundry-104", + "properties": { + "type": "Room2DPropertiesAbridged", + "energy": { "type": "Room2DEnergyPropertiesAbridged" }, + "radiance": { "type": "Room2DRadiancePropertiesAbridged" } + }, + "floor_boundary": [ + [10.001931517437631, -0.7441439785816385], + [8.290021124356155, -0.744143978581633], + [7.6424815174376315, -0.744143978581631], + [7.642481517437627, -3.3415939785816904], + [10.001931517437628, -3.3415939785816975], + [10.001931517437628, -2.5035939785815233] + ], + "floor_height": 0, + "floor_to_ceiling_height": 3, + "is_ground_contact": true, + "is_top_exposed": false, + "boundary_conditions": [ + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + }, + { + "type": "Outdoors", + "sun_exposure": true, + "wind_exposure": true, + "view_factor": { "type": "Autocalculate" } + } + ], + "user_data": {} + } + const obj = Room2D.fromJS(roomData); + expect(obj.identifier).toBe("Room_e6ac360b-aaed-4c3b-a130-36b4c2ac9d13-000d14cc"); + expect(obj.validate()).resolves.toBe(true); + + const jsonObj = obj.toJSON(); + const prop = jsonObj["properties"]; + expect(prop["energy"].hasOwnProperty("hvac")).toBe(false); + expect(prop.hasOwnProperty("radiance")).toBe(true); + +}); + +test('test roomProperty', () => { + const roomData = { + "type": "Room2DPropertiesAbridged", + "energy": { "type": "Room2DEnergyPropertiesAbridged" } + }; + const obj = Room2DPropertiesAbridged.fromJS(roomData); + expect(obj.validate()).resolves.toBe(true); + + const jsonObj = obj.toJSON(); + expect(jsonObj.type).toBe("Room2DPropertiesAbridged"); + expect(jsonObj).toHaveProperty("energy"); + expect(jsonObj.hasOwnProperty("radiance")).toBe(false); + +}); \ No newline at end of file diff --git a/src/TypeScriptSDK.Tests/src/jest.setup.ts b/src/TypeScriptSDK.Tests/src/jest.setup.ts new file mode 100644 index 0000000..359e0de --- /dev/null +++ b/src/TypeScriptSDK.Tests/src/jest.setup.ts @@ -0,0 +1 @@ +import 'reflect-metadata'; \ No newline at end of file diff --git a/src/TypeScriptSDK.Tests/src/sum.test.ts b/src/TypeScriptSDK.Tests/src/sum.test.ts index 418b2ed..65ef421 100644 --- a/src/TypeScriptSDK.Tests/src/sum.test.ts +++ b/src/TypeScriptSDK.Tests/src/sum.test.ts @@ -1,5 +1,30 @@ +// import { ProjectInfo } from 'honeybee-schema'; import { sum } from './sum'; +import { Room2D, Room2DPropertiesAbridged } from 'dragonfly-schema'; test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); -}); \ No newline at end of file +}); + +// test('tt', () => { +// const obj = new ProjectInfo(); +// obj.north = 10; +// const jsonObj = obj.toJSON(); +// expect(jsonObj.north).toBe(10); +// }); + + +test('test roomProperty', () => { + const roomData = { + "type": "Room2DPropertiesAbridged", + "energy": { "type": "Room2DEnergyPropertiesAbridged" } + }; + const obj = Room2DPropertiesAbridged.fromJS(roomData); + expect(obj.validate()).resolves.toBe(true); + + const jsonObj = obj.toJSON(); + expect(jsonObj.type).toBe("Room2DPropertiesAbridged"); + expect(jsonObj).toHaveProperty("energy"); + expect(jsonObj.hasOwnProperty("radiance")).toBe(false); + + }); \ No newline at end of file diff --git a/src/TypeScriptSDK.Tests/tsconfig.json b/src/TypeScriptSDK.Tests/tsconfig.json index 985af6d..d4a42f3 100644 --- a/src/TypeScriptSDK.Tests/tsconfig.json +++ b/src/TypeScriptSDK.Tests/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -25,9 +25,9 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + "module": "CommonJS", /* Specify what module code is generated. */ + // "rootDir": "./src", /* Specify the root folder within your source files. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ @@ -56,8 +56,8 @@ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "noEmit": true, /* Disable emitting files from a compilation. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "outFile": "./dist", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": ".", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -107,6 +107,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src/**/*.ts"], + "include": ["src/**/*"], "exclude": ["node_modules"] }