Skip to content

Commit

Permalink
fix: remove old creation code (#8004)
Browse files Browse the repository at this point in the history
* Removing old components

* marking unit tests for revision

* Removing old creation string

* Updating CreateBot component

* Moving creation files outside of v2 dir

* removing V2 from creation class names

* update migrate and createProjcet api endpoints

* Updating fetchtemplates endpoint and references

* misc v2 verbage and variable name clean up

* update createbot dispatchers

* update createNewBotFromTemplate

* minor fix in navigation in creation flow

* Updating creation flow unit test location

* updating lcoale file and removing unused variable

* Fix Unit test mocking

* Remove old unit test

* reverting en-us to resolve conflict with main
  • Loading branch information
pavolum committed Jun 8, 2021
1 parent c859da0 commit e8e4ada
Show file tree
Hide file tree
Showing 33 changed files with 535 additions and 2,087 deletions.
11 changes: 1 addition & 10 deletions Composer/cypress/support/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@

declare namespace Cypress {
interface Chainable {
/**
* Deprecated!
* Creates a bot based on template id.
* If botName not provided, names the bot __Test${botId},
* otherwise, __Test&{botName}.
* @example cy.createBot('TodoSample', 'NewBotName')
*/
createBot(botId: string, botName?: string): void;

/**
* Creates a bot based on empty bot.
* @example cy.createBot('EmptySample', ()=> {})
*/
createBotV2(botName: string, createdCallback: (bot: any) => void): void;
createBot(botName: string, createdCallback: (bot: any) => void): void;

/**
* Creates a bot based on empty bot.
Expand Down
22 changes: 3 additions & 19 deletions Composer/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,7 @@ import '@testing-library/cypress/add-commands';

let TemplateBotProjectId = '';

Cypress.Commands.add('createBot', (botId: string, botName?: string) => {
const name = `__Test${botName || botId}`;

const params = {
storageId: 'default',
name,
description: '',
templateId: botId,
};

cy.request('post', '/api/projects', params).then((res) => {
const { id: projectId } = res.body;
cy.visit(`/bot/${projectId}/dialogs/${name.toLowerCase()}`);
});
});

Cypress.Commands.add('createBotV2', (botName: string, callback: (bot: any) => void) => {
Cypress.Commands.add('createBot', (botName: string, callback: (bot: any) => void) => {
const params = {
description: '',
location: '',
Expand Down Expand Up @@ -50,7 +34,7 @@ Cypress.Commands.add('createBotV2', (botName: string, callback: (bot: any) => vo
}
};

cy.request('post', '/api/v2/projects', params).then((res) => {
cy.request('post', '/api/projects', params).then((res) => {
const { jobId } = res.body;
// install package can take a long time.
cy.wait(20000);
Expand All @@ -59,7 +43,7 @@ Cypress.Commands.add('createBotV2', (botName: string, callback: (bot: any) => vo
});

Cypress.Commands.add('createTemplateBot', (botName: string, callback: (bot: any) => void) => {
cy.createBotV2(`TemplateBot_${botName}`, (bot) => {
cy.createBot(`TemplateBot_${botName}`, (bot) => {
TemplateBotProjectId = bot.id;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,28 @@ describe('<CreateOptions/>', () => {
const handleDismissMock = jest.fn();
const handleCreateNextMock = jest.fn();
const handleJumpToOpenModal = jest.fn();
const handleFetchReadMeMock = jest.fn();

const templates = [
{
description: 'empty bot',
id: 'EmptyBot',
description: 'conversational core template generator',
id: 'generator-conversational-core',
index: 0,
name: 'Empty Bot',
path: 'templatePath',
support: ['C#', 'JS'],
tags: ['Basic'],
},
{
description: 'echo bot',
id: 'EchoBot',
index: 1,
name: 'Echo Bot',
path: 'templatePath',
support: ['C#', 'JS'],
tags: ['Basic'],
name: 'conversational-core',
dotnetSupport: { webAppSupported: true, functionsSupported: true },
nodeSupport: { webAppSupported: true, functionsSupported: true },
package: {
packageName: 'generator-conversational-core',
packageSource: 'npm',
packageVersion: '1.0.9',
},
},
];

const renderComponent = () => {
return renderWithRecoil(
<CreateOptions
fetchReadMe={handleFetchReadMeMock}
path="create"
templates={templates}
onDismiss={handleDismissMock}
Expand All @@ -44,21 +42,12 @@ describe('<CreateOptions/>', () => {
);
};

it('should save empty bot template id', async () => {
const component = renderComponent();
const nextButton = await component.findByText('Next');
fireEvent.click(nextButton);
expect(handleCreateNextMock).toBeCalledWith('EmptyBot');
});

it('should save echo bot template id', async () => {
it('should save conversational core template id', async () => {
const component = renderComponent();
const option = await component.findByTestId('Create from template');
fireEvent.click(option);
const echoBot = await component.findByText('Echo Bot');
fireEvent.click(echoBot);
const conversationalCoreBot = await component.findByTestId('generator-conversational-core');
fireEvent.click(conversationalCoreBot);
const nextButton = await component.findByText('Next');
fireEvent.click(nextButton);
expect(handleCreateNextMock).toBeCalledWith('EchoBot');
expect(handleCreateNextMock).toBeCalledWith('generator-conversational-core', 'dotnet');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,6 @@ describe('<DefineConversation/>', () => {
expect(component.container).toBeDefined();
});

it('should update formdata with data passed through location props', async () => {
locationMock = {
search:
'schemaUrl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2Fbotframework-sdk%2Fmaster%2Fschemas%2Fcomponent%2Fcomponent.schema%26name%3DEchoBot-11299%26description%3DTest%20Echo',
};
const component = renderComponent();
const node = await component.findByText('OK');
fireEvent.click(node);
expect(
onSubmitMock.mock.calls[0][0] ===
{
description: 'Test Echo',
name: 'EchoBot-11299',
location: '\\test-folder\\Desktop',
schemaUrl:
'https://raw.githubusercontent.com/microsoft/botframework-sdk/master/schemas/component/component.schema',
} ||
onSubmitMock.mock.calls[0][0] ===
{
description: 'Test Echo',
name: 'EchoBot-11299',
location: '/test-folder/Desktop',
schemaUrl:
'https://raw.githubusercontent.com/microsoft/botframework-sdk/master/schemas/component/component.schema',
}
).toBeTruthy;
});

it('does not allow submission when the name is invalid', async () => {
const component = renderComponent();
const nameField = await component.getByTestId('NewDialogName');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { createHistory, createMemorySource, LocationProvider } from '@reach/rout
import { RecoilRoot } from 'recoil';
import { getDefaultFeatureFlags } from '@bfc/shared';

import CreationFlow from '../../../src/components/CreationFlow/CreationFlow';
import {
focusedStorageFolderState,
creationFlowStatusState,
dispatcherState,
featureFlagsState,
templateProjectsState,
} from '../../../src/recoilModel';
import { CreationFlowStatus } from '../../../src/constants';
import CreationFlow from '../../../src/components/CreationFlow/CreationFlow';

describe('<CreationFlow/>', () => {
let locationMock;
Expand All @@ -28,14 +29,24 @@ describe('<CreationFlow/>', () => {
fetchRecentProjects: jest.fn(),
fetchFeed: jest.fn(),
fetchTemplates: jest.fn(),
fetchTemplatesV2: jest.fn(),
setCreationFlowStatus: jest.fn(),
navTo: jest.fn(),
saveTemplateId: jest.fn(),
setCurrentPageMode: jest.fn(),
});
set(creationFlowStatusState, CreationFlowStatus.NEW_FROM_TEMPLATE);
set(featureFlagsState, getDefaultFeatureFlags());
set(templateProjectsState, [
{
id: '@microsoft/generator-bot-empty',
name: 'Empty Bot',
description: 'Yeoman generator for creating an empty bot built on the Azure Bot Framework.',
package: { packageName: '@microsoft/generator-bot-empty', packageSource: 'npm', packageVersion: '1.0.0' },
dotnetSupport: { functionsSupported: true, webAppSupported: true },
nodeSupport: { functionsSupported: true, webAppSupported: true },
},
]);

set(focusedStorageFolderState, {
name: 'Desktop',
parent: '/test-folder',
Expand Down Expand Up @@ -73,8 +84,8 @@ describe('<CreationFlow/>', () => {
</RecoilRoot>
);

navigate('create/EchoBot');
const node = await findByText('OK');
navigate('create/dotnet/%40microsoft%2Fgenerator-bot-empty');
const node = await findByText('Create');

act(() => {
fireEvent.click(node);
Expand All @@ -84,14 +95,25 @@ describe('<CreationFlow/>', () => {
if (process.platform === 'win32') {
expectedLocation = '\\test-folder\\Desktop';
}

expect(createProjectMock).toHaveBeenCalledWith({
appLocale: 'en-US',
description: '',
location: expectedLocation,
name: 'EchoBot-1',
name: 'Empty',
schemaUrl: '',
templateId: 'EchoBot',
templateId: '@microsoft/generator-bot-empty',
templateVersion: '1.0.0',
alias: undefined,
eTag: undefined,
preserveRoot: undefined,
qnqKbUrls: undefined,
runtimeType: 'webapp',
templateDir: undefined,
urlSuffix: undefined,
profile: undefined,
qnaKbUrls: undefined,
runtimeLanguage: 'dotnet',
source: undefined,
});
});
});

This file was deleted.

This file was deleted.

Loading

0 comments on commit e8e4ada

Please sign in to comment.