[My Items] Make folder name customizable (#4627)

* making my items folder name customizable

Co-authored-by: Nikhil <nikhil.k.mandlik@nasa.gov>
Co-authored-by: John Hill <john.c.hill@nasa.gov>
This commit is contained in:
Jamie V 2021-12-30 16:27:51 -08:00 committed by GitHub
parent 6a8f4b5d9c
commit 23ead2ceaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 49 deletions

View File

@ -22,14 +22,14 @@
import { MY_ITEMS_KEY } from "./createMyItemsIdentifier";
function myItemsInterceptor(identifierObject, openmct) {
function myItemsInterceptor(openmct, identifierObject, name) {
const myItemsModel = {
identifier: identifierObject,
"name": "My Items",
"type": "folder",
"composition": [],
"location": "ROOT"
name,
type: "folder",
composition: [],
location: "ROOT"
};
return {

View File

@ -23,11 +23,13 @@
import { createMyItemsIdentifier } from "./createMyItemsIdentifier";
import myItemsInterceptor from "./myItemsInterceptor";
export default function MyItemsPlugin(namespace = '') {
const MY_ITEMS_DEFAULT_NAME = 'My Items';
export default function MyItemsPlugin(name = MY_ITEMS_DEFAULT_NAME, namespace = '') {
return function install(openmct) {
const identifier = createMyItemsIdentifier(namespace);
openmct.objects.addGetInterceptor(myItemsInterceptor(identifier, openmct));
openmct.objects.addGetInterceptor(myItemsInterceptor(openmct, identifier, name));
openmct.objects.addRoot(identifier);
};
}

View File

@ -30,6 +30,8 @@ import {
} from './createMyItemsIdentifier';
const MISSING_NAME = `Missing: ${MY_ITEMS_KEY}`;
const DEFAULT_NAME = 'My Items';
const FANCY_NAME = 'Fancy Items';
const myItemsIdentifier = createMyItemsIdentifier();
describe("the plugin", () => {
@ -40,9 +42,10 @@ describe("the plugin", () => {
name: MISSING_NAME
};
describe('with no arguments passed in', () => {
beforeEach((done) => {
openmct = createOpenMct();
openmct.install(openmct.plugins.MyItems());
openmct.on('start', done);
@ -61,6 +64,7 @@ describe("the plugin", () => {
return openmct.objects.areIdsEqual(domainObject.identifier, myItemsIdentifier);
})[0];
expect(myItems.name).toBe(DEFAULT_NAME);
expect(myItems).toBeDefined();
});
@ -89,4 +93,31 @@ describe("the plugin", () => {
});
});
});
describe('with a name argument passed in', () => {
beforeEach((done) => {
openmct = createOpenMct();
openmct.install(openmct.plugins.MyItems(FANCY_NAME));
spyOn(openmct.objects, 'isMissing').and.returnValue(true);
openmct.on('start', done);
openmct.startHeadless();
});
afterEach(() => {
return resetApplicationState(openmct);
});
it('when installed, uses the passed in name', async () => {
let myItems = await openmct.objects.get(myItemsIdentifier);
expect(myItems.name).toBe(FANCY_NAME);
expect(myItems).toBeDefined();
});
});
});