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
10 changes: 7 additions & 3 deletions pkg/rancher-prime/config/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IPlugin } from '@shell/core/types';
import { PRODUCT_SETTING_NAME, SETTING_PAGE_NAME } from './constants';
import { IF_HAVE } from '@shell/store/type-map';
import { SCC } from '@shell/store/features';

// Product configuration
export function init($plugin: IPlugin, store: any) {
Expand All @@ -9,9 +11,11 @@ export function init($plugin: IPlugin, store: any) {
} = $plugin.DSL(store, PRODUCT_SETTING_NAME);

virtualType({
labelKey: 'registration.navigation.label',
name: SETTING_PAGE_NAME,
route: { name: SETTING_PAGE_NAME },
ifHave: IF_HAVE.ADMIN,
ifFeature: SCC,
labelKey: 'registration.navigation.label',
name: SETTING_PAGE_NAME,
route: { name: SETTING_PAGE_NAME },
});

basicType([SETTING_PAGE_NAME]);
Expand Down
40 changes: 40 additions & 0 deletions pkg/rancher-prime/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { SCC } from '@shell/store/features';
const { IF_HAVE } = require('@shell/store/type-map');

jest.doMock('@rancher/auto-import', () => ({ importTypes: jest.fn() }), { virtual: true });

describe('extension: rancher-prime', () => {
it('should enable routing for admin users with SCC feature', async() => {
const plugin = await import('./index'); // initialized after the mock
const virtualTypeSpy = jest.fn();
const basicTypeSpy = jest.fn();
const dslMock = jest.fn().mockReturnValue({
virtualType: virtualTypeSpy,
basicType: basicTypeSpy
});

const pluginMock = {
environment: { isPrime: true },
addProduct: jest.fn(),
addRoutes: jest.fn(),
addPanel: jest.fn(),
addNavHooks: jest.fn(),
register: jest.fn(), // Used in installDocHandler
metadata: {},
DSL: dslMock
} as any;

plugin.default(pluginMock); // basic extension import
pluginMock.addProduct.mock.calls[0][0].init(pluginMock, {}); // force init to trigger as in @rancher/shell

expect(pluginMock.addProduct).toHaveBeenCalledWith(
expect.objectContaining({ init: expect.any(Function) })
);
expect(virtualTypeSpy).toHaveBeenCalledWith(
expect.objectContaining({
ifHave: IF_HAVE.ADMIN,
ifFeature: SCC
})
);
});
});
2 changes: 1 addition & 1 deletion pkg/rancher-prime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const poolRegistration = (store: Store<any>) => {
if (store.state['managementReady']) {
setNotification(store);
clearInterval(id);
attempts -= 1;
}
attempts -= 1;
}, 1000);
};

Expand Down
1 change: 1 addition & 0 deletions shell/store/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const STEVE_CACHE = create('ui-sql-cache', false);
export const UIEXTENSION = create('uiextension', true);
export const PROVISIONING_PRE_BOOTSTRAP = create('provisioningprebootstrap', false);
export const SCHEDULING_CUSTOMIZATION = create(SCHEDULING_CUSTOMIZATION_FEATURE, false);
export const SCC = create('rancher-scc-registration-extension', true);

// Not currently used.. no point defining ones we don't use
// export const EMBEDDED_CLUSTER_API = create('embedded-cluster-api', true);
Expand Down