|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | | -import { convertToSubscripts, convertSimulationToChartData } from "../../src/functions/Formatting"; |
| 2 | +import { |
| 3 | + convertToSubscripts, |
| 4 | + convertSimulationToChartData, |
| 5 | + convertExperimentResultsToChartDataTable, |
| 6 | + convertSimulationQueriesResultToChartDataTable, |
| 7 | +} from "../../src/functions/Formatting"; |
3 | 8 | import { SimulationResults } from "../../src/dto/SimulationResults"; |
4 | 9 | import { ModelInput } from "../../src/dto/ModelInput"; |
| 10 | +import { ExperimentResult } from "../../src/dto/ExperimentResult"; |
| 11 | +import { UseSimulationQueriesResult } from "../../src/hooks/useSimulationQueriesResult"; |
5 | 12 |
|
6 | 13 | describe("convertToSubscripts", () => { |
7 | 14 | it("should return empty div when provided an empty string", () => { |
@@ -42,3 +49,69 @@ describe("convertingSimulationToChartData", () => { |
42 | 49 | ]); |
43 | 50 | }); |
44 | 51 | }); |
| 52 | + |
| 53 | +describe("Table Data Conversion Functions", () => { |
| 54 | + describe("convertSimulationQueriesResultToChartDataTable", () => { |
| 55 | + it("should correctly convert simulation queries result to chart data table format", () => { |
| 56 | + const mockSimulationQueriesResult: UseSimulationQueriesResult = { |
| 57 | + data: { |
| 58 | + "Experiment 1": [ |
| 59 | + { |
| 60 | + modelInput: { |
| 61 | + modelId: "TOCOMO", |
| 62 | + concentrations: { CO2: 0.5, H2O: 0.3 }, |
| 63 | + parameters: { pressure: 1.2, temperature: 298, time: 100 }, |
| 64 | + }, |
| 65 | + finalConcentrations: { CO2: 0.4, H2O: 0.4, CH4: 0.2 }, |
| 66 | + panels: [], |
| 67 | + }, |
| 68 | + ], |
| 69 | + }, |
| 70 | + isLoading: false, |
| 71 | + }; |
| 72 | + |
| 73 | + const result = convertSimulationQueriesResultToChartDataTable(mockSimulationQueriesResult); |
| 74 | + |
| 75 | + expect(result).toHaveLength(1); |
| 76 | + expect(result[0]).toEqual({ |
| 77 | + label: "TOCOMO - Experiment 1", |
| 78 | + inputsConcentrations: { CO2: 0.5, H2O: 0.3 }, |
| 79 | + finalConcentration: { CO2: 0.4, H2O: 0.4, CH4: 0.2 }, |
| 80 | + parameters: { |
| 81 | + pressure: 1.2, |
| 82 | + temperature: 298, |
| 83 | + time: 100, |
| 84 | + }, |
| 85 | + }); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + describe("convertExperimentResultsToChartDataTable", () => { |
| 90 | + it("should correctly convert experiment results to chart data table format", () => { |
| 91 | + const mockExperimentResults: ExperimentResult[] = [ |
| 92 | + { |
| 93 | + name: "Lab Experiment 1", |
| 94 | + time: 120, |
| 95 | + temperature: 25, // Celsius |
| 96 | + pressure: 1.5, |
| 97 | + initialConcentrations: { CO2: 0.6, H2O: 0.2 }, |
| 98 | + finalConcentrations: { CO2: 0.3, H2O: 0.5, N2: 0.2 }, |
| 99 | + }, |
| 100 | + ]; |
| 101 | + |
| 102 | + const result = convertExperimentResultsToChartDataTable(mockExperimentResults); |
| 103 | + |
| 104 | + expect(result).toHaveLength(1); |
| 105 | + expect(result[0]).toEqual({ |
| 106 | + label: "Lab Experiment 1", |
| 107 | + inputsConcentrations: { CO2: 0.6, H2O: 0.2 }, |
| 108 | + finalConcentration: { CO2: 0.3, H2O: 0.5, N2: 0.2 }, |
| 109 | + parameters: { |
| 110 | + pressure: 1.5, |
| 111 | + temperature: 298, // 25 + 273 (converted to Kelvin) |
| 112 | + time: 120, |
| 113 | + }, |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments