Skip to content

Commit

Permalink
fix typo and some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyLaw committed Dec 19, 2019
2 parents 0b0bca9 + 76a7f2e commit 4e1bfb5
Show file tree
Hide file tree
Showing 16 changed files with 535 additions and 68 deletions.
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"*.schema": "json"
},
"eslint.enable": true,
"eslint.autoFixOnSave": true,
"eslint.packageManager": "yarn",
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
"typescript",
"typescriptreact",
],
"eslint.workingDirectories": ["./Composer"],
"editor.formatOnSave": true,
"typescript.tsdk": "./Composer/node_modules/typescript/lib"
"typescript.tsdk": "./Composer/node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
4 changes: 2 additions & 2 deletions Composer/cypress/integration/LUPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ context('LU Page', () => {
.should('exist');

// nav to ToDoBotWithLuisSample.main dialog
cy.get('.dialogNavTree button[title="__TestToDoBotWithLuisSample.Main"]').click({ multiple: true });
cy.get('[name="__TestToDoBotWithLuisSample.Main"]').click({ multiple: true });

// goto edit-mode
cy.get('@switchButton').click();
Expand All @@ -34,7 +34,7 @@ context('LU Page', () => {
.should('exist');

// back to all table view
cy.get('.dialogNavTree button[title="All"]').click();
cy.get('[name="All"]').click();
cy.findByTestId('LUEditor')
.findByTestId('table-view')
.should('exist');
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/NotificationPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ context('Notification Page', () => {
it('can show lu syntax error ', () => {
cy.visitPage('User Input');

cy.get('.dialogNavTree button[title="__TestToDoBotWithLuisSample.Main"]').click({ multiple: true });
cy.get('[name="__TestToDoBotWithLuisSample.Main"]').click({ multiple: true });

cy.get('.toggleEditMode button').click();
cy.get('textarea').type('test lu syntax error');
Expand Down
66 changes: 66 additions & 0 deletions Composer/packages/client/__tests__/components/design.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import * as React from 'react';
import { render, fireEvent } from 'react-testing-library';

import { renderWithStore } from '../testUtils';
import { dialogs } from '../constants.json';

import { TriggerCreationModal } from './../../src/components/ProjectTree/TriggerCreationModal';
import { ProjectTree } from './../../src/components/ProjectTree';
import NewDialogModal from './../../src/pages/design/new-dialog-modal';
describe('<ProjectTree/>', () => {
it('should render the ProjectTree', async () => {
const dialogId = 'Main';
const selected = 'triggers[0]';
const handleSelect = jest.fn(() => {});
const handleAddDialog = jest.fn(() => {});
const handleDeleteDialog = jest.fn(() => {});
const handleDeleteTrigger = jest.fn(() => {});
const openNewTriggerModal = jest.fn(() => {});
const { findByText } = renderWithStore(
<ProjectTree
dialogs={dialogs}
dialogId={dialogId}
selected={selected}
onSelect={handleSelect}
onAdd={handleAddDialog}
onDeleteDialog={handleDeleteDialog}
onDeleteTrigger={handleDeleteTrigger}
openNewTriggerModal={openNewTriggerModal}
/>
);
const node = await findByText('AddToDo');
fireEvent.click(node);
expect(handleSelect).toHaveBeenCalledTimes(1);
});

it('should open NewDialogModal, close after clicking cancel', async () => {
let isOpen = true;
const handleDismiss = jest.fn(() => {
isOpen = false;
});
const handleSubmit = jest.fn(() => {});
const { getByText } = render(
<NewDialogModal isOpen={isOpen} onDismiss={handleDismiss} onSubmit={handleSubmit} onGetErrorMessage={() => {}} />
);
const cancelButton = getByText('Cancel');
fireEvent.click(cancelButton);
expect(isOpen).toBe(false);
});

it('should open the TriggerCreationModal, close after clicking cancel', async () => {
let isOpen = true;
const handleDismiss = jest.fn(() => {
isOpen = false;
});
const handleSubmit = jest.fn(() => {});
const { getByText } = render(
<TriggerCreationModal dialogId={'Main'} isOpen={isOpen} onDismiss={handleDismiss} onSubmit={handleSubmit} />
);
const cancelButton = getByText('Cancel');
fireEvent.click(cancelButton);
expect(isOpen).toBe(false);
});
});
88 changes: 88 additions & 0 deletions Composer/packages/client/__tests__/components/home.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import * as React from 'react';
import { fireEvent, render } from 'react-testing-library';

import { RecentBotList } from '../../src/pages/home/RecentBotList';
import { ExampleList } from '../../src/pages/home/ExampleList';
import { ToolBar } from '../../src/components/ToolBar/index';
describe('<Home/>', () => {
it('should dispatch onSelectionChanged event when clicked on a link on <RecentBotList>', () => {
const recentProjects = [
{ dataModified: 'Thu Nov 28 2019 17:22:19 GMT+0800 (GMT+08:00)', name: 'a', path: 'path1', storageId: 'default' },
{ dataModified: 'Thu Nov 28 2019 17:22:19 GMT+0800 (GMT+08:00)', name: 'b', path: 'path2', storageId: 'default' },
];
const onSelectionChanged = jest.fn(item => item.path);
const { container, queryByLabelText } = render(
<RecentBotList onSelectionChanged={onSelectionChanged} recentProjects={recentProjects} />
);
expect(container).toHaveTextContent('a');
expect(container).toHaveTextContent('b');
const link = queryByLabelText('a');
fireEvent.click(link);
expect(onSelectionChanged.mock.results[0].value).toBe('path1');
});

it('should dispatch onClick event when clicked on an ExampleList', () => {
const templates = [
{ description: 'echo bot', id: 'EchoBot', name: 'Echo Bot', order: 1 },
{ description: 'empty bot', id: 'EmptyBot', name: 'Empty Bot', order: 2 },
];
const onClickTemplate = jest.fn(item => item);
const { container, getByText } = render(<ExampleList onClick={onClickTemplate} examples={templates} />);
expect(container).toHaveTextContent('Echo Bot');
const link = getByText('Echo Bot');
fireEvent.click(link);
expect(onClickTemplate.mock.results[0].value).toBe('EchoBot');
});

it('should call onClick handler when clicked', () => {
const setCreationFlowStatus = jest.fn(item => item);
const items = [
{
type: 'action',
text: 'New',
buttonProps: {
iconProps: {
iconName: 'CirclePlus',
},
onClick: () => setCreationFlowStatus('NEW'),
},
align: 'left',
dataTestid: 'homePage-ToolBar-New',
disabled: false,
},
{
type: 'action',
text: 'Open',
buttonProps: {
iconProps: {
iconName: 'OpenFolderHorizontal',
},
onClick: () => setCreationFlowStatus('OPEN'),
},
align: 'left',
dataTestid: 'homePage-ToolBar-Open',
disabled: false,
},
{
type: 'action',
text: 'Save as',
buttonProps: {
iconProps: {
iconName: 'Save',
},
onClick: () => setCreationFlowStatus('SAVE AS'),
},
align: 'left',
disabled: false,
},
];
const { container, getByText } = render(<ToolBar toolbarItems={items} />);
expect(container).toHaveTextContent('New');
const link = getByText('New');
fireEvent.click(link);
expect(setCreationFlowStatus.mock.results[0].value).toBe('NEW');
});
});
3 changes: 2 additions & 1 deletion Composer/packages/client/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function getClientEnvironment(publicUrl) {
GIT_SHA: getGitSha()
.toString()
.replace('\n', ''),
SDK_PACKAGE_VERSON: '4.6.0-preview2', // TODO: change this when Composer supports custom schema/custom runtime
SDK_PACKAGE_VERSION: '4.7.0-preview-191208-1', // TODO: change this when Composer supports custom schema/custom runtime
COMPOSER_VERSION: 'Preview 2.0',
}
);
// Stringify all values so we can feed into Webpack DefinePlugin
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/client/src/pages/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const About: React.FC<RouteComponentProps> = () => {
<div css={about.content}>
<div css={about.title}> {formatMessage(`About`)} </div>
<div css={about.body}>
<div css={about.version}>{formatMessage(`Release: Preview 1.0`)}</div>
<div css={about.version}>{formatMessage(`Release: `) + (process.env.COMPOSER_VERSION || 'Unknown')}</div>
<div css={about.description}>
<p>
{formatMessage(`Bot Framework Composer is an integrated development environment (IDE) for building
Expand Down Expand Up @@ -54,12 +54,12 @@ export const About: React.FC<RouteComponentProps> = () => {
<div css={about.DiagnosticsInfoTextAlignLeft}>{formatMessage(`SDK runtime packages`)}</div>
<div css={about.DiagnosticsInfoTextAlignLeft}>
<Link
href={`https://botbuilder.myget.org/feed/botbuilder-v4-dotnet-daily/package/nuget/Microsoft.Bot.Builder.Dialogs.Adaptive/${process.env.SDK_PACKAGE_VERSON}`}
href={`https://botbuilder.myget.org/feed/botbuilder-v4-dotnet-daily/package/nuget/Microsoft.Bot.Builder.Dialogs.Adaptive/${process.env.SDK_PACKAGE_VERSION}`}
tabIndex={-1}
target={'_blank'}
style={{ marginLeft: '5px' }}
>
{process.env.SDK_PACKAGE_VERSON || 'Unknown'}
{process.env.SDK_PACKAGE_VERSION || 'Unknown'}
</Link>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/pages/about/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const smallText = css`
export const DiagnosticsInfoText = css`
display: flex;
justify-content: space-between;
width: 460px;
width: 550px;
font-size: 24px;
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/** @jsx jsx */
import { jsx } from '@emotion/core';
import React, { useContext, Fragment, useEffect, useState, useMemo, Suspense } from 'react';
import formatMessage from 'format-message';
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
import { Nav } from 'office-ui-fabric-react/lib/Nav';
import { Nav, INavLinkGroup, INavLink } from 'office-ui-fabric-react/lib/Nav';

import { StoreContext } from '../../store';
import {
ContentHeaderStyle,
ContentStyle,
flexContent,
actionButton,
contentEditor,
} from '../language-understanding/styles';
import { projectContainer, projectTree, projectWrapper } from '../design/styles';
import { navigateTo } from '../../utils';
import { LoadingSpinner } from '../../components/LoadingSpinner';
import { Tree } from '../../components/Tree';
import { ToolBar } from '../../components/ToolBar/index';
import { TestController } from '../../TestController';

import { Tree } from './../../components/Tree';
import TableView from './table-view';
import { ToolBar } from './../../components/ToolBar/index';
import { TestController } from './../../TestController';
import { ContentHeaderStyle, ContentStyle, flexContent, actionButton, contentEditor } from './styles';

const CodeEditor = React.lazy(() => import('./code-editor'));

const LUPage = props => {
interface DefineConversationProps {
path: string;
}

const LUPage: React.FC<DefineConversationProps> = props => {
const { state, actions } = useContext(StoreContext);
const { luFiles, dialogs } = state;
const [editMode, setEditMode] = useState(false);
Expand All @@ -39,17 +36,20 @@ const LUPage = props => {

const luFile = luFiles.length && activeDialog ? luFiles.find(luFile => luFile.id === activeDialog.id) : null;

const navLinks = useMemo(() => {
const subLinks = dialogs.reduce((result, file) => {
const navLinks: INavLinkGroup[] = useMemo(() => {
const subLinks = dialogs.reduce((result: INavLink[], file) => {
if (result.length === 0) {
result = [
{
links: [],
name: '',
url: '',
},
];
}
const item = {
id: file.id,
url: file.id,
key: file.id,
name: file.displayName,
};
Expand All @@ -61,7 +61,7 @@ const LUPage = props => {
isExpanded: true,
};
} else {
result[0].links.push(item);
result[0].links && result[0].links.push(item);
}
return result;
}, []);
Expand All @@ -73,6 +73,7 @@ const LUPage = props => {
id: '_all',
key: '_all',
name: 'All',
url: '_all',
isExpanded: true,
links: subLinks,
},
Expand Down Expand Up @@ -106,9 +107,10 @@ const LUPage = props => {
setEditMode(false);
}

async function onChange(newContent) {
async function onChange(newContent: string) {
const id = activeDialog ? activeDialog.id : undefined;
const payload = {
id: activeDialog.id, // current opened lu file
id: id, // current opened lu file
content: newContent,
};
try {
Expand Down Expand Up @@ -156,8 +158,8 @@ const LUPage = props => {
<div css={projectWrapper}>
<Nav
onLinkClick={(ev, item) => {
onSelect(item.id);
ev.preventDefault();
item && onSelect(item.id);
ev && ev.preventDefault();
}}
styles={{
root: {
Expand Down Expand Up @@ -186,7 +188,7 @@ const LUPage = props => {
<CodeEditor file={luFile} onChange={onChange} errorMsg={errorMsg} />
</Suspense>
) : (
<TableView file={luFile} activeDialog={activeDialog} onClickEdit={onTableViewClickEdit} />
<TableView activeDialog={activeDialog} onClickEdit={onTableViewClickEdit} />
)}
</div>
</div>
Expand Down
Loading

0 comments on commit 4e1bfb5

Please sign in to comment.