mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
test(graphql): Test menu item filter.
This commit is contained in:
parent
e80e461eba
commit
1cfe6362f0
@ -25,6 +25,7 @@ const loaders = {
|
||||
};
|
||||
|
||||
const context = testBootstrapContext({ loaders });
|
||||
const contextUser = testBootstrapContext({ loaders, user: { sub: 'sub' } });
|
||||
|
||||
beforeEach(() => {
|
||||
mockLoadComponent.mockReset();
|
||||
@ -445,3 +446,334 @@ test('getMenus, default menu has no links', async () => {
|
||||
homePageId: null,
|
||||
});
|
||||
});
|
||||
|
||||
describe('filter menus', () => {
|
||||
test('Menu all protected, public request', async () => {
|
||||
mockLoadComponent.mockImplementation((id) => {
|
||||
if (id === 'menus') {
|
||||
return [
|
||||
{
|
||||
menuId: 'default',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:2',
|
||||
menuItemId: '2',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:3',
|
||||
menuItemId: '3',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:4',
|
||||
menuItemId: '4',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:5',
|
||||
menuItemId: '5',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
menuId: 'other',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:other:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (id === 'config') {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const controller = createComponentController(context);
|
||||
const res = await controller.getMenus();
|
||||
expect(res).toEqual({
|
||||
menus: [
|
||||
{
|
||||
menuId: 'default',
|
||||
links: [],
|
||||
},
|
||||
{
|
||||
menuId: 'other',
|
||||
links: [],
|
||||
},
|
||||
],
|
||||
homePageId: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('Menu all protected, public request', async () => {
|
||||
mockLoadComponent.mockImplementation((id) => {
|
||||
if (id === 'menus') {
|
||||
return [
|
||||
{
|
||||
menuId: 'default',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:2',
|
||||
menuItemId: '2',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:3',
|
||||
menuItemId: '3',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:4',
|
||||
menuItemId: '4',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:5',
|
||||
menuItemId: '5',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
menuId: 'other',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:other:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (id === 'config') {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const controller = createComponentController(contextUser);
|
||||
const res = await controller.getMenus();
|
||||
expect(res).toEqual({
|
||||
menus: [
|
||||
{
|
||||
menuId: 'default',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:2',
|
||||
menuItemId: '2',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:3',
|
||||
menuItemId: '3',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:4',
|
||||
menuItemId: '4',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:5',
|
||||
menuItemId: '5',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
menuId: 'other',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:other:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
homePageId: 'page',
|
||||
});
|
||||
});
|
||||
|
||||
test('Menu filter some items, public request', async () => {
|
||||
mockLoadComponent.mockImplementation((id) => {
|
||||
if (id === 'menus') {
|
||||
return [
|
||||
{
|
||||
menuId: 'default',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:1',
|
||||
menuItemId: '1',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:2',
|
||||
menuItemId: '2',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:3',
|
||||
menuItemId: '3',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:4',
|
||||
menuItemId: '4',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'public',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:5',
|
||||
menuItemId: '5',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:6',
|
||||
menuItemId: '6',
|
||||
type: 'MenuLink',
|
||||
pageId: 'page',
|
||||
auth: 'protected',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:7',
|
||||
menuItemId: '7',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:8',
|
||||
menuItemId: '8',
|
||||
type: 'MenuLink',
|
||||
url: 'https://lowdefy.com',
|
||||
auth: 'public',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (id === 'config') {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const controller = createComponentController(context);
|
||||
const res = await controller.getMenus();
|
||||
expect(res).toEqual({
|
||||
homePageId: 'page',
|
||||
menus: [
|
||||
{
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:2',
|
||||
menuItemId: '2',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:4',
|
||||
menuItemId: '4',
|
||||
pageId: 'page',
|
||||
type: 'MenuLink',
|
||||
auth: 'public',
|
||||
},
|
||||
{
|
||||
id: 'menuitem:default:7',
|
||||
menuItemId: '7',
|
||||
type: 'MenuGroup',
|
||||
auth: 'public',
|
||||
links: [
|
||||
{
|
||||
id: 'menuitem:default:8',
|
||||
menuItemId: '8',
|
||||
type: 'MenuLink',
|
||||
url: 'https://lowdefy.com',
|
||||
auth: 'public',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
menuId: 'default',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user