Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
lei9444 committed Nov 27, 2019
1 parent c58f800 commit 971376c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions Composer/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Cypress.Commands.add('withinEditor', (editorName, cb) => {

Cypress.Commands.add('visitPage', page => {
cy.findByTestId(`LeftNav-CommandBarButton${page}`).click();
cy.wait(500);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { NotificationList } from '../../src/pages/notifications/NotificationList

describe('<NotificationList/>', () => {
const items = [
{ type: 'Error', location: 'test1', message: 'error1' },
{ type: 'Warning', location: 'test2', message: 'error2' },
{ type: 'Error', location: 'test3', message: 'error3' },
{ id: '1', severity: 'Error', type: 'dialog', location: 'test1', message: 'error1', diagnostic: '' },
{ id: '2', severity: 'Warning', type: 'lu', location: 'test2', message: 'error2', diagnostic: '' },
{ id: '3', severity: 'Error', type: 'lg', location: 'test3', message: 'error3', diagnostic: '' },
];
it('should render the NotificationList', () => {
const { container } = render(<NotificationList items={items} />);
Expand Down
8 changes: 7 additions & 1 deletion Composer/packages/client/src/ShellApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useEffect, useContext, useMemo } from 'react';
import { ShellData } from '@bfc/shared';
import isEqual from 'lodash/isEqual';
import get from 'lodash/get';
import { LGTemplate } from 'botbuilder-lg';

import { isExpression } from './utils';
import * as lgUtil from './utils/lgUtil';
Expand Down Expand Up @@ -132,8 +133,13 @@ export const ShellApi: React.FC = () => {
if (id === undefined) throw new Error('must have a file id');
const file = lgFiles.find(file => file.id === id);
if (!file) throw new Error(`lg file ${id} not found`);
let templates: LGTemplate[] = [];
try {
templates = lgUtil.parse(file.content);
} catch (error) {
console.error(error);
}

const templates = lgUtil.parse(file.content);
const lines = file.content.split('\n');

return templates.map(t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const LGPage: React.FC<RouteComponentProps> = props => {
css={actionButton}
onText={formatMessage('Edit mode')}
offText={formatMessage('Edit mode')}
defaultChecked={false}
checked={editMode}
disabled={(!isRoot && editMode === false) || (codeRange === null && fileValid === false)}
onChange={onToggleEditMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const RecognizerField: React.FC<FieldProps<MicrosoftIRecognizer>> = props
selectedFile && typeof props.formData === 'string' && props.formData.startsWith(selectedFile.id)
);

//make the inline editor show error message
useEffect(() => {
if (selectedFile && selectedFile.diagnostics.length > 0) {
const msg = selectedFile.diagnostics.reduce((msg: string, diagnostic) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ describe('lu operation', () => {
}
});

it('should throw error when lu content is invalid', async () => {
it('should update diagnostics when lu content is invalid', async () => {
const id = 'root';
const content = 'hello \n hello3';

await expect(proj.updateLuFile(id, content)).rejects.toThrow();
const luFiles = await proj.updateLuFile(id, content);
const result = luFiles.find(f => f.id === id);
if (result !== undefined) {
await expect(result.diagnostics.length).toBeGreaterThan(0);
}
});

it('should delete lu file and update index', async () => {
Expand Down

0 comments on commit 971376c

Please sign in to comment.