-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve usage of status writer for settings and view in SimulationTim…
…eSeriesMatrix (#424) Co-authored-by: Ruben Thoms <[email protected]>
- Loading branch information
1 parent
fd2c64a
commit 7f4cf4f
Showing
4 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
frontend/src/modules/SimulationTimeSeriesMatrix/utils/stringUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Utility function to make a display friendly string from an array of strings. | ||
* | ||
* Example: ["a", "b", "c"] -> "a, b and c" | ||
*/ | ||
export function joinStringArrayToHumanReadableString(stringArray: string[]): string { | ||
if (stringArray.length === 0) return ""; | ||
if (stringArray.length === 1) return stringArray[0]; | ||
|
||
return stringArray.slice(0, -1).join(", ") + " and " + stringArray[stringArray.length - 1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
frontend/tests/unit-tests/SimulationTimeSeriesMatrixUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { joinStringArrayToHumanReadableString } from "@modules/SimulationTimeSeriesMatrix/utils/stringUtils"; | ||
|
||
describe("Test of utility functions for SimulationTimeSeriesMatrix module", () => { | ||
test("Test join string array to human readable string", () => { | ||
expect(joinStringArrayToHumanReadableString(["a", "b", "c"])).toBe("a, b and c"); | ||
expect(joinStringArrayToHumanReadableString(["a"])).toBe("a"); | ||
expect(joinStringArrayToHumanReadableString([])).toBe(""); | ||
expect(joinStringArrayToHumanReadableString(["a", "b"])).toBe("a and b"); | ||
}); | ||
}); |