diff --git a/controllers/reconcile.go b/controllers/reconcile.go index 30fdb161..565ca579 100644 --- a/controllers/reconcile.go +++ b/controllers/reconcile.go @@ -1012,8 +1012,10 @@ func setupBundlesData(feList *crd.FrontendList, feEnvironment crd.FrontendEnviro for _, bundle := range *feEnvironment.Spec.Bundles { delete(skippedNavItemsMap, bundle.ID) - // TODO sort alphabetically if position collision sort.Slice(bundleNavSegmentMap[bundle.ID], func(i, j int) bool { + if (bundleNavSegmentMap[bundle.ID])[i].Position == (bundleNavSegmentMap[bundle.ID])[j].Position { + return (bundleNavSegmentMap[bundle.ID])[i].SegmentID[0] < (bundleNavSegmentMap[bundle.ID])[j].SegmentID[0] + } return (bundleNavSegmentMap[bundle.ID])[i].Position < (bundleNavSegmentMap[bundle.ID])[j].Position }) navItems := []crd.ChromeNavItem{} diff --git a/tests/e2e/generate-bundles/01-create-resources.yaml b/tests/e2e/generate-bundles/01-create-resources.yaml index 176c3fd8..9cddc798 100644 --- a/tests/e2e/generate-bundles/01-create-resources.yaml +++ b/tests/e2e/generate-bundles/01-create-resources.yaml @@ -34,12 +34,12 @@ spec: modules: [] moduleID: landing-page navigationSegments: - - segmentId: inventory-partial-2 + - segmentId: inventory-last-segment bundleId: rhel - position: 200 + position: 200 # should be last based on position values navItems: - id: landing2 - title: Landing section + title: Landing section last href: /apps/landing - id: bar2 title: Some new link @@ -51,12 +51,12 @@ spec: - id: baz2 title: Some new link href: /baz - - segmentId: inventory-partial + - segmentId: c-inventory-segment bundleId: rhel position: 100 navItems: - id: landing - title: Landing section + title: Landing section c href: /apps/landing - id: bar title: Some new link @@ -68,6 +68,27 @@ spec: - id: baz title: Some new link href: /baz + - segmentId: a-inventory-segment + bundleId: rhel + position: 100 # collision with above segment - should sort by segmentId alphabetically + navItems: + - id: landing + title: Landing section A + href: /apps/landing + - segmentId: b-inventory-segment + bundleId: rhel + position: 100 # collision with above segment - should sort by segmentId alphabetically + navItems: + - id: landing + title: Landing section B + href: /apps/landing + - segmentId: d-inventory-segment + bundleId: rhel + position: 100 # collision with above segment - should sort by segmentId alphabetically + navItems: + - id: landing + title: Landing section D + href: /apps/landing - segmentId: skipped-partial bundleId: skipped position: 100 diff --git a/tests/e2e/generate-bundles/02-assert.yaml b/tests/e2e/generate-bundles/02-assert.yaml index 0780a901..498b9d2a 100644 --- a/tests/e2e/generate-bundles/02-assert.yaml +++ b/tests/e2e/generate-bundles/02-assert.yaml @@ -50,7 +50,8 @@ data: {"landing-page":{"manifestLocation":"/apps/landing-page/fed-mods.json","moduleID":"landing-page","fullProfile":false}} bundles.json: >- [{"id":"rhel","title":"Red Hat Enterprise Linux","navItems":[{"href":"/apps/landing","title":"Landing - section","id":"landing"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some - new link","id":"baz"},{"href":"/apps/landing","title":"Landing section","id":"landing2"},{"expandable":true,"title":"Some - new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some + section A","id":"landing"},{"href":"/apps/landing","title":"Landing section B","id":"landing"},{"href":"/apps/landing","title":"Landing + section c","id":"landing"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some + new link","id":"baz"},{"href":"/apps/landing","title":"Landing section D","id":"landing"},{"href":"/apps/landing","title":"Landing + section last","id":"landing2"},{"expandable":true,"title":"Some new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some new link","id":"baz2"}]},{"id":"ansible","title":"Ansible","navItems":[]},{"id":"settings","title":"Settings","navItems":[]}]