Format Long properties

Bug: 261331482

Test: npm run test:unit
Change-Id: If760435ad364205f1a1cc6823630ff3f45bd6707
This commit is contained in:
Pablo Gamito
2022-12-05 11:00:15 +00:00
parent fece7599ca
commit 891ea13545
2 changed files with 22 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Long from "long";
import { PropertiesTreeGenerator } from "viewers/common/properties_tree_generator";
import {PropertiesTreeNode} from "./ui_tree_utils";
@@ -41,6 +42,18 @@ describe("PropertiesTreeGenerator", () => {
expect(actual).toEqual(expected);
});
it("handles longs", () => {
const input = new Long(10, 100, false);
const actual = new PropertiesTreeGenerator().generate("root", input);
const expected: PropertiesTreeNode = {
propertyKey: "root",
propertyValue: "429496729610"
};
expect(actual).toEqual(expected);
});
it("handles string", () => {
const input = "value";
const actual = new PropertiesTreeGenerator().generate("root", input);

View File

@@ -57,6 +57,9 @@ class PropertiesTreeGenerator {
if (typeof value === "string") {
return value;
}
if (this.isLong(value)) {
return value.toString();
}
if (Array.isArray(value) && value.length === 0) {
return "[]";
}
@@ -65,6 +68,12 @@ class PropertiesTreeGenerator {
}
return undefined;
}
private isLong(value: any) {
return Object.prototype.hasOwnProperty.call(value, "high") &&
Object.prototype.hasOwnProperty.call(value, "low") &&
Object.prototype.hasOwnProperty.call(value, "unsigned");
}
}
export {PropertiesTreeGenerator};