Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/helpers/normalizeSelectedInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const normalizeSelectedInstances = (selectedInstances, instances) => {
matchesPattern(instance.nm, selection)
})

matchedKeys.forEach(key => normalizedSet.add(key))
if (matchedKeys.length) matchedKeys.forEach(key => normalizedSet.add(key))
else normalizedSet.add(selection)
})

return Array.from(normalizedSet)
Expand Down
22 changes: 20 additions & 2 deletions src/helpers/normalizeSelectedInstances.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,28 @@ describe("normalizeSelectedInstances", () => {
expect(result.sort()).toEqual(["system.cpu@node1", "system.cpu@node2"])
})

it("should omit selections that dont match anything", () => {
it("preserves unmatched selections alongside resolved selections", () => {
const selected = ["nonexistent", "system.cpu"]
const result = normalizeSelectedInstances(selected, mockInstances)
expect(result.sort()).toEqual(["system.cpu@node1", "system.cpu@node2"])
expect(result.sort()).toEqual(["nonexistent", "system.cpu@node1", "system.cpu@node2"])
})

it.each([{}, { "system.cpu@node2": mockInstances["system.cpu@node2"] }])(
"preserves the requested node when its instance is absent from the summary",
instances => {
const selected = ["system.cpu@node1"]
expect(normalizeSelectedInstances(selected, instances)).toEqual(selected)
}
)

it("preserves an unmatched pattern until metadata becomes available", () => {
const selected = ["system.cpu*"]
const pending = normalizeSelectedInstances(selected, {})
expect(pending).toEqual(selected)
expect(normalizeSelectedInstances(pending, mockInstances).sort()).toEqual([
"system.cpu@node1",
"system.cpu@node2",
])
})

it("should handle multiple different selections", () => {
Expand Down