Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
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
100 changes: 100 additions & 0 deletions Composer/packages/client/__tests__/utils/navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { PromptTab } from '@bfc/shared';

import {
BreadcrumbUpdateType,
getUrlSearch,
checkUrl,
getFocusPath,
clearBreadcrumb,
updateBreadcrumb,
convertPathToUrl,
} from './../../src/utils/navigation';

describe('getFocusPath', () => {
it('return focus path', () => {
const result1 = getFocusPath('selected', 'focused');
expect(result1).toEqual('focused');
const result2 = getFocusPath('selected', '');
expect(result2).toEqual('selected');
const result3 = getFocusPath('', '');
expect(result3).toEqual('');
});
});

describe('Breadcrumb Util', () => {
it('return focus path', () => {
const breadcrumb = [
{ dialogId: `1`, selected: `1`, focused: `1` },
{ dialogId: `2`, selected: `2`, focused: `2` },
{ dialogId: `3`, selected: `3`, focused: `3` },
];
const result1 = clearBreadcrumb(breadcrumb);
expect(result1).toEqual([]);
const result2 = clearBreadcrumb(breadcrumb, 0);
expect(result2).toEqual([]);
const result3 = clearBreadcrumb(breadcrumb, 1);
expect(result3.length).toEqual(1);
expect(result3[0].dialogId).toEqual('1');
const result4 = clearBreadcrumb(breadcrumb, 4);
expect(result4.length).toEqual(3);
});

it('update breadcrumb', () => {
const result1 = updateBreadcrumb([], BreadcrumbUpdateType.Selected);
expect(result1).toEqual([]);
let breadcrumb = [
{ dialogId: `1`, selected: `1`, focused: `1` },
{ dialogId: `2`, selected: `2`, focused: `2` },
{ dialogId: `3`, selected: `3`, focused: `3` },
];
const result2 = updateBreadcrumb(breadcrumb, BreadcrumbUpdateType.Selected);
expect(result2.length).toEqual(1);
expect(result2[0].dialogId).toEqual('1');
breadcrumb = [
{ dialogId: `1`, selected: `1`, focused: `` },
{ dialogId: `2`, selected: `2`, focused: `` },
{ dialogId: `3`, selected: `3`, focused: `3` },
];
const result3 = updateBreadcrumb(breadcrumb, BreadcrumbUpdateType.Focused);
expect(result3.length).toEqual(2);
expect(result3[1].dialogId).toEqual('2');
});
});

describe('composer url util', () => {
it('create url', () => {
const result1 = getUrlSearch('triggers[0]', 'triggers[0].actions[0]');
expect(result1).toEqual('?selected=triggers[0]&focused=triggers[0].actions[0]');
});

it('check url', () => {
const result1 = checkUrl(`/bot/1/dialogs/a?selected=triggers[0]&focused=triggers[0].actions[0]#botAsks`, {
dialogId: 'a',
projectId: '1',
selected: 'triggers[0]',
focused: 'triggers[0].actions[0]',
promptTab: PromptTab.BOT_ASKS,
});
expect(result1).toEqual(true);
const result2 = checkUrl(`test`, {
dialogId: 'a',
projectId: '1',
selected: 'triggers[0]',
focused: 'triggers[0].actions[0]',
promptTab: PromptTab.BOT_ASKS,
});
expect(result2).toEqual(false);
});

it('convert path to url', () => {
const result1 = convertPathToUrl('1', 'main');
expect(result1).toEqual('/bot/1/dialogs/main');
const result2 = convertPathToUrl('1', 'main', 'main.triggers[0].actions[0]');
expect(result2).toEqual('/bot/1/dialogs/main?selected=triggers[0]&focused=triggers[0].actions[0]');
const result3 = convertPathToUrl('1', 'main', 'main.triggers[0].actions[0]#Microsoft.TextInput#prompt');
expect(result3).toEqual('/bot/1/dialogs/main?selected=triggers[0]&focused=triggers[0].actions[0]#botAsks');
});
});
4 changes: 2 additions & 2 deletions Composer/packages/client/src/pages/notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NotificationHeader } from './NotificationHeader';
import { root } from './styles';
import { INotification, NotificationType } from './types';
import { navigateTo } from './../../utils';
import { convertPathToUrl, toUrlUtil } from './../../utils/navigation';
import { convertPathToUrl } from './../../utils/navigation';

const Notifications: React.FC<RouteComponentProps> = () => {
const [filter, setFilter] = useState('');
Expand All @@ -24,7 +24,7 @@ const Notifications: React.FC<RouteComponentProps> = () => {
let uri = `/bot/${projectId}/language-generation/${resourceId}/edit#L=${diagnostic.range?.start.line || 0}`;
//the format of item.id is lgFile#inlineTemplateId
if (dialogPath) {
uri = toUrlUtil(projectId, dialogPath);
uri = convertPathToUrl(projectId, resourceId, dialogPath);
}
navigateTo(uri);
},
Expand Down
17 changes: 0 additions & 17 deletions Composer/packages/client/src/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,6 @@ export function convertPathToUrl(projectId: string, dialogId: string, path?: str
return uri;
}

export function toUrlUtil(projectId: string, path: string): string {
const tokens = path.split('#');
const firstDotIndex = tokens[0].indexOf('.');
const dialogId = tokens[0].substring(0, firstDotIndex);
const focusedPath = parsePathToFocused(tokens[0]);
const selectedPath = parsePathToSelected(tokens[0]);
const type = tokens[1];
const property = tokens[2];
const fragment = parseTypeToFragment(type, property);
if (!focusedPath || !selectedPath) {
return '';
}
return `/bot/${projectId}/dialogs/${dialogId}?selected=${selectedPath}&focused=${focusedPath}${
fragment ? '#' + fragment : ''
}`;
}

export function navigateTo(to: string, navigateOpts: NavigateOptions<NavigationState> = {}) {
const mapNavPath = resolveToBasePath(BASEPATH, to);
navigate(mapNavPath, navigateOpts);
Expand Down