This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
/
DiagnosticsHistory.test.ts
97 lines (91 loc) · 3.32 KB
/
DiagnosticsHistory.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** @jest-environment jsdom */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
//
// This file incorporates work covered by the following copyright and
// permission notice:
//
// Copyright 2018-2021 Cruise LLC
//
// This source code is licensed under the Apache License, Version 2.0,
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.
import { TypedMessage } from "@foxglove-studio/app/players/types";
import { addMessages, defaultDiagnosticsBuffer } from "./DiagnosticsHistory";
import { computeDiagnosticInfo, DiagnosticInfo, DiagnosticStatusArrayMsg, LEVELS } from "./util";
const messageAtLevel = (level: number): TypedMessage<DiagnosticStatusArrayMsg> => ({
message: {
status: [
{
level,
name: "MCTM Logger",
message: "No triggers since launch!",
hardware_id: "mctm_logger",
values: [],
},
],
header: { stamp: { sec: 1547062466, nsec: 1674890 }, frame_id: "", seq: 0 },
},
topic: "/foo",
receiveTime: { sec: 1547062466, nsec: 1674890 },
});
const diagnosticInfoAtLevel = (level: number): DiagnosticInfo => {
const { message } = messageAtLevel(level);
return computeDiagnosticInfo(message.status[0]!, message.header.stamp);
};
describe("addMessages", () => {
it("adds a message at the right warning level", () => {
const message = messageAtLevel(LEVELS.OK);
const info = diagnosticInfoAtLevel(LEVELS.OK);
const hardwareId = `|${info.status.hardware_id}|`;
expect(addMessages(defaultDiagnosticsBuffer(), [message])).toEqual({
diagnosticsByNameByTrimmedHardwareId: new Map([
[info.status.hardware_id, new Map([[info.status.name, info]])],
]),
sortedAutocompleteEntries: [
{
displayName: info.status.hardware_id,
hardware_id: info.status.hardware_id,
id: hardwareId,
name: undefined,
sortKey: info.status.hardware_id.toLowerCase(),
},
{
displayName: info.displayName,
hardware_id: info.status.hardware_id,
id: info.id,
name: info.status.name,
sortKey: info.displayName.toLowerCase(),
},
],
});
});
it("can move a message from one level to another", () => {
const message1 = messageAtLevel(LEVELS.OK);
const message2 = messageAtLevel(LEVELS.ERROR);
const info = diagnosticInfoAtLevel(LEVELS.ERROR);
const hardwareId = `|${info.status.hardware_id}|`;
expect(addMessages(defaultDiagnosticsBuffer(), [message1, message2])).toEqual({
diagnosticsByNameByTrimmedHardwareId: new Map([
[info.status.hardware_id, new Map([[info.status.name, info]])],
]),
sortedAutocompleteEntries: [
{
displayName: info.status.hardware_id,
hardware_id: info.status.hardware_id,
id: hardwareId,
name: undefined,
sortKey: info.status.hardware_id.toLowerCase(),
},
{
displayName: info.displayName,
hardware_id: info.status.hardware_id,
id: info.id,
name: info.status.name,
sortKey: info.displayName.toLowerCase(),
},
],
});
});
});