Skip to content

Commit

Permalink
fix the diagnostic path error (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
lei9444 authored Feb 20, 2020
1 parent 3e8d170 commit 3a9b11b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createPath } from './../../src/dialogUtils/dialogChecker';

describe('create right diagnostic path', () => {
it('should check if the diagnostics have errors', () => {
expect(createPath('Main.triggers[7].actions[0].cases[1].actions[0].condition', 'type')).toBe(
'Main.triggers[7].actions[0].cases[1].actions[0]#type#condition'
);
expect(createPath('Main.triggers[7].actions[0].condition', 'type')).toBe(
'Main.triggers[7].actions[0]#type#condition'
);
expect(createPath('Main.triggers[7].condition', 'type')).toBe('Main.triggers[7]#type#condition');
expect(createPath('Main.triggers[7].actions[0].elseActions[0].condition', 'type')).toBe(
'Main.triggers[7].actions[0].elseActions[0]#type#condition'
);
expect(createPath('Main.triggers[7].actions[0]', 'type')).toBe('Main.triggers[7].actions[0]#type');
});
});
14 changes: 10 additions & 4 deletions Composer/packages/lib/indexers/src/dialogUtils/dialogChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@

import get from 'lodash/get';
import { FieldNames } from '@bfc/shared';
import values from 'lodash/values';

import { Diagnostic } from '../diagnostic';

import { ExpressionType } from './validation';
import { CheckerFunc } from './types';
import { validate } from './validation';

const createPath = (path: string, type: string): string => {
const steps = [FieldNames.Events, FieldNames.Actions, FieldNames.ElseActions];
export const createPath = (path: string, type: string): string => {
let list = path.split('.');
const matches = list.filter(x => !steps.every(step => !x.startsWith(step)));
const matches = list.filter(x => {
if (/\[|\]/.test(x)) {
const reg = /\[.*\]/;
x = x.replace(reg, '');
return ~values(FieldNames).indexOf(x);
}
});

const focused = matches.join('.');
list = path.split(`${focused}.`);
if (list.length !== 2) return path;
if (list.length !== 2) return `${path}#${type}`;

return `${list[0]}${focused}#${type}#${list[1]}`;
};
Expand Down

0 comments on commit 3a9b11b

Please sign in to comment.