2024-01-02 10:24:22 -05:00
|
|
|
import { createOpenMct, resetApplicationState } from '../utils/testing.js';
|
2024-03-11 16:39:38 -07:00
|
|
|
import { identifierToString, objectPathToUrl, paramsToArray } from './url.js';
|
2022-01-14 02:07:57 +01:00
|
|
|
|
|
|
|
describe('the url tool', function () {
|
|
|
|
let openmct;
|
|
|
|
let mockObjectPath;
|
|
|
|
|
|
|
|
beforeEach((done) => {
|
|
|
|
mockObjectPath = [
|
|
|
|
{
|
|
|
|
name: 'mock folder',
|
|
|
|
type: 'fake-folder',
|
|
|
|
identifier: {
|
|
|
|
key: 'mock-folder',
|
|
|
|
namespace: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'mock parent folder',
|
|
|
|
type: 'fake-folder',
|
|
|
|
identifier: {
|
|
|
|
key: 'mock-parent-folder',
|
|
|
|
namespace: ''
|
|
|
|
}
|
2023-05-18 14:54:46 -07:00
|
|
|
}
|
2022-01-14 02:07:57 +01:00
|
|
|
];
|
|
|
|
openmct = createOpenMct();
|
|
|
|
openmct.on('start', () => {
|
2023-01-20 10:27:09 -08:00
|
|
|
openmct.router.setPath('/browse/mine?testParam1=testValue1');
|
2022-01-14 02:07:57 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
openmct.startHeadless();
|
2023-05-18 14:54:46 -07:00
|
|
|
});
|
2022-01-14 02:07:57 +01:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
return resetApplicationState(openmct);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('paramsToArray', () => {
|
|
|
|
it('exists', () => {
|
|
|
|
expect(paramsToArray).toBeDefined();
|
|
|
|
});
|
|
|
|
it('can construct an array properly from query parameters', () => {
|
|
|
|
const arrayOfParams = paramsToArray(openmct);
|
|
|
|
expect(arrayOfParams.length).toBeDefined();
|
|
|
|
expect(arrayOfParams.length).toBeGreaterThan(0);
|
2023-05-18 14:54:46 -07:00
|
|
|
});
|
|
|
|
});
|
2022-01-14 02:07:57 +01:00
|
|
|
|
|
|
|
describe('identifierToString', () => {
|
|
|
|
it('exists', () => {
|
|
|
|
expect(identifierToString).toBeDefined();
|
|
|
|
});
|
|
|
|
it('can construct a String properly from a path', () => {
|
|
|
|
const constructedString = identifierToString(openmct, mockObjectPath);
|
|
|
|
expect(constructedString).toEqual('#/browse/mock-parent-folder/mock-folder');
|
2023-05-18 14:54:46 -07:00
|
|
|
});
|
|
|
|
});
|
2022-01-14 02:07:57 +01:00
|
|
|
|
|
|
|
describe('objectPathToUrl', () => {
|
|
|
|
it('exists', () => {
|
|
|
|
expect(objectPathToUrl).toBeDefined();
|
|
|
|
});
|
|
|
|
it('can construct URL properly from a path', () => {
|
|
|
|
const constructedURL = objectPathToUrl(openmct, mockObjectPath);
|
|
|
|
expect(constructedURL).toContain('#/browse/mock-parent-folder/mock-folder');
|
|
|
|
});
|
2022-12-02 17:03:43 -06:00
|
|
|
it('can take params to set a custom url', () => {
|
|
|
|
const customParams = {
|
|
|
|
'tc.startBound': 1669911059,
|
|
|
|
'tc.endBound': 1669911082,
|
|
|
|
'tc.mode': 'fixed'
|
|
|
|
};
|
|
|
|
const constructedURL = objectPathToUrl(openmct, mockObjectPath, customParams);
|
2023-07-18 17:32:05 -07:00
|
|
|
expect(constructedURL).toContain('tc.startBound=1669911059&tc.endBound=1669911082');
|
|
|
|
expect(constructedURL).toContain('tc.mode=fixed');
|
2022-01-14 02:07:57 +01:00
|
|
|
});
|
2023-05-18 14:54:46 -07:00
|
|
|
});
|
2022-01-14 02:07:57 +01:00
|
|
|
});
|