-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
535 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Composer/packages/client/__tests__/components/design.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
88
Composer/packages/client/__tests__/components/home.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.