From 6a45c4b1f27e0e323fdc82531e99761bc47669d3 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Tue, 20 Aug 2019 11:55:22 -0500 Subject: [PATCH] sort namespaces lexicographically --- ui/app/lib/path-to-tree.js | 2 ++ ui/tests/unit/lib/path-to-tree-test.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ui/app/lib/path-to-tree.js b/ui/app/lib/path-to-tree.js index 9142f545c4d5..8c527a8e69e6 100644 --- a/ui/app/lib/path-to-tree.js +++ b/ui/app/lib/path-to-tree.js @@ -38,6 +38,8 @@ export default function(paths) { return accumulator; }, []); + + tree = tree.sort((a, b)=> a.localeCompare(b)); // after the reduction we're left with an array that contains // strings that represent the longest branches // we'll replace the dots in the paths, then expand the path diff --git a/ui/tests/unit/lib/path-to-tree-test.js b/ui/tests/unit/lib/path-to-tree-test.js index 733d11e568d9..4013bedee0fe 100644 --- a/ui/tests/unit/lib/path-to-tree-test.js +++ b/ui/tests/unit/lib/path-to-tree-test.js @@ -67,6 +67,28 @@ module('Unit | Lib | path to tree', function() { }, }, ], + [ + 'sorting lexicographically', + ['99', 'bat', 'bat/bird', 'animal/flying/birds', 'animal/walking/dogs', 'animal/walking/cats', '1/thing'], + { + 1: { + thing: null, + }, + 99: null, + animal: { + flying: { + birds:null, + }, + walking: { + cats: null, + dogs: null, + } + }, + bat: { + bird: null + } + }, + ], ]; tests.forEach(function([name, input, expected]) {