mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
PageRegistration / PageMenuRegistration fixes & more simplification (#1386)
* PageRegistration & PageMenuRegistration fixes & more simplification, fix #1383 Signed-off-by: Roman <ixrock@gmail.com> * clean up test, deprecate page.routePath Signed-off-by: Roman <ixrock@gmail.com> * fix: proper `isActive` state matching for page-menu-target to page considering current document location Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
596e60a6f3
commit
13dbdac2f2
12 files changed
+147
-93
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { getPageUrl, globalPageRegistry } from "../page-registry"
|
||||
import { getExtensionPageUrl, globalPageRegistry, PageRegistration } from "../page-registry"
|
||||
import { LensExtension } from "../../lens-extension"
|
||||
import React from "react";
|
||||
|
||||
@@ -18,20 +18,19 @@ describe("getPageUrl", () => {
|
||||
})
|
||||
|
||||
it("returns a page url for extension", () => {
|
||||
expect(getPageUrl(ext)).toBe("/extension/foo-bar")
|
||||
expect(getExtensionPageUrl({ extensionId: ext.name })).toBe("/extension/foo-bar")
|
||||
})
|
||||
|
||||
it("allows to pass base url as parameter", () => {
|
||||
expect(getPageUrl(ext, "/test")).toBe("/extension/foo-bar/test")
|
||||
expect(getExtensionPageUrl({ extensionId: ext.name, pageId: "/test" })).toBe("/extension/foo-bar/test")
|
||||
})
|
||||
|
||||
it("removes @", () => {
|
||||
ext.manifest.name = "@foo/bar"
|
||||
expect(getPageUrl(ext)).toBe("/extension/foo-bar")
|
||||
expect(getExtensionPageUrl({ extensionId: "@foo/bar" })).toBe("/extension/foo-bar")
|
||||
})
|
||||
|
||||
it("adds / prefix", () => {
|
||||
expect(getPageUrl(ext, "test")).toBe("/extension/foo-bar/test")
|
||||
expect(getExtensionPageUrl({ extensionId: ext.name, pageId: "test" })).toBe("/extension/foo-bar/test")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -57,12 +56,24 @@ describe("globalPageRegistry", () => {
|
||||
id: "another-page",
|
||||
components: {
|
||||
Page: () => React.createElement('Text')
|
||||
},
|
||||
},
|
||||
{
|
||||
components: {
|
||||
Page: () => React.createElement('Default')
|
||||
}
|
||||
},
|
||||
], ext)
|
||||
})
|
||||
|
||||
describe("getByPageMenuTarget", () => {
|
||||
it("matching to first registered page without id", () => {
|
||||
const page = globalPageRegistry.getByPageMenuTarget({ extensionId: ext.name })
|
||||
expect(page.id).toEqual(undefined);
|
||||
expect(page.extensionId).toEqual(ext.name);
|
||||
expect(page.routePath).toEqual(getExtensionPageUrl({ extensionId: ext.name }));
|
||||
});
|
||||
|
||||
it("returns matching page", () => {
|
||||
const page = globalPageRegistry.getByPageMenuTarget({
|
||||
pageId: "test-page",
|
||||
|
||||
Reference in new issue
Block a user