Skip to content

Commit

Permalink
feat: QnA import url (#3919)
Browse files Browse the repository at this point in the history
* lu  reference

* update

* update

* minimal publish model

* update resolver

* update package

* update

* support  path based resolve

* support wildcard match * / **

* update

* resolver support .qna file ext

* define source qna in bot structure

* include dialog name in source qna name

* qnaIndexer update

* update

* create qna file for imported  url & name

* update

* enable source qna in all up view

* import url sync all locale

* update import name

* qna parse more infomation

* keep header in qna crud

* group source.qna in dialog.qna

* refactor qnaUtil curd methods

* refactor qna all up view

* update

* remove > !# @source.name in options

* do not insert \n before section

* update

* remove source from nav tree

* enable multi turn

* create qna file for imported url & name

* update package

* imports methods

* remove import in table-view

* update

* update

* enable multiturn

* remove file state

* update style

* handle focus states

* clean install

* rename

* refactor create qna modal

* ... menuItems for navTree

* rename

* create from scratch & url

* clean up

* fix build

* update

* update all up view UX

* creation flow from qna scratch

* edit container name

* update css

* update css

* migrate exist qna to container

* edit url source

* update css

* update css

* clean up

* update bf-lu package

* update

* update ux

* creation back

* update

* fix create qna bot

* update css

* update container edit

* update tests

* update to multi projectId

* fix bug and update css

* fix bug

* add tests

* resolve merge conflict

* update

* use notification card

* unify create qna modal

* show code & back KB

* rename migrated file to *-munual.source.qna

* clean

* update css

* update styles

* update tests

* revert test

* update showcode button test id

* resolve comments

* resolve types

* update

* required validation

* edit field height

* update

* update

* expand row index

* craete QnA pair controls

* update

* fix empty group creation

* not change backgroud when switch to scratch

* update

* height

* update

* update

* resolve merge conflict

* fix creation

* fix bug

* show + when hover

Co-authored-by: liweitian <liweitian93@outlook.com>
Co-authored-by: Weitian Li <weitli@microsoft.com>
Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
4 people committed Oct 15, 2020
1 parent 4e1317f commit e5fc3df
Show file tree
Hide file tree
Showing 72 changed files with 4,668 additions and 1,474 deletions.
2 changes: 1 addition & 1 deletion Composer/cypress/integration/LGPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ context('LG Page', () => {
cy.contains('TodoSample');
cy.contains('All');

cy.get('.toggleEditMode button').as('switchButton');
cy.findByTestId('showcode').as('switchButton');

// by default is table view
cy.findByTestId('LGPage').findByTestId('table-view').should('exist');
Expand Down
4 changes: 2 additions & 2 deletions Composer/cypress/integration/LUPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ context('LU Page', () => {
cy.contains('__TestToDoBotWithLuisSample');
cy.contains('All');

cy.get('.toggleEditMode button').should('not.exist');
cy.findByTestId('showcode').should('not.exist');

// by default it goes to table view
cy.findByTestId('LUPage').findByTestId('table-view').should('exist');
Expand All @@ -25,7 +25,7 @@ context('LU Page', () => {
cy.findByTestId('ProjectTree').within(() => {
cy.findByText('__TestToDoBotWithLuisSample').click('left');
});
cy.get('.toggleEditMode button').as('switchButton');
cy.findByTestId('showcode').as('switchButton');
// goto edit-mode
cy.get('@switchButton').click();
cy.findByTestId('LUPage').get('.monaco-editor').should('exist');
Expand Down
5 changes: 2 additions & 3 deletions Composer/cypress/integration/NotificationPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ context('Notification Page', () => {
it('can show lg syntax error ', () => {
cy.visitPage('Bot Responses');

cy.get('.toggleEditMode button').as('switchButton');
cy.get('@switchButton').click();
cy.findByTestId('showcode').click();
cy.get('textarea').type('#', { delay: 200 });

cy.findByTestId('LeftNav-CommandBarButtonNotifications').click();
Expand All @@ -29,7 +28,7 @@ context('Notification Page', () => {
cy.findByText('__TestToDoBotWithLuisSample').click();
});

cy.get('.toggleEditMode button').click();
cy.findByTestId('showcode').click();
cy.get('textarea').type('t', { delay: 200 });

cy.findByTestId('LeftNav-CommandBarButtonNotifications').click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React from 'react';
import { fireEvent } from '@bfc/test-utils';

import { renderWithRecoil } from '../testUtils/renderWithRecoil';
import CreateQnAFromUrlModal from '../../src/components/QnA/CreateQnAFromUrlModal';
import { showCreateQnAFromUrlDialogState, showCreateQnAFromUrlDialogWithScratchState } from '../../src/recoilModel';

describe('<CreateQnAFromUrlModal />', () => {
const onDismiss = jest.fn(() => {});
const onSubmit = jest.fn(() => {});
const projectId = 'test-create-qna';

it('renders <CreateQnAFromUrlModal /> and create from scratch', () => {
const container = renderWithRecoil(
<CreateQnAFromUrlModal
dialogId="test"
projectId={projectId}
qnaFiles={[]}
onDismiss={onDismiss}
onSubmit={onSubmit}
/>,
({ set }) => {
set(showCreateQnAFromUrlDialogState(projectId), true);
set(showCreateQnAFromUrlDialogWithScratchState(projectId), true);
}
);

const { getByTestId } = container;
const createFromScratchButton = getByTestId('createKnowledgeBaseFromScratch');
expect(createFromScratchButton).not.toBeNull();
fireEvent.click(createFromScratchButton);
// actions tobe called
});

it('create with name/url and validate the value', () => {
const container = renderWithRecoil(
<CreateQnAFromUrlModal
dialogId="test"
projectId={projectId}
qnaFiles={[]}
onDismiss={onDismiss}
onSubmit={onSubmit}
/>,
() => {}
);

const { findByText, getByTestId } = container;
const inputName = getByTestId('knowledgeLocationTextField-name') as HTMLInputElement;
fireEvent.change(inputName, { target: { value: 'test' } });

const inputUrl = getByTestId('knowledgeLocationTextField-url') as HTMLInputElement;
fireEvent.change(inputUrl, { target: { value: 'test' } });

expect(inputUrl.value).toBe('test');
expect(findByText(/A valid url should start with/)).not.toBeNull();
fireEvent.change(inputUrl, { target: { value: 'http://test' } });

const createKnowledgeButton = getByTestId('createKnowledgeBase');
expect(createKnowledgeButton).not.toBeNull();
fireEvent.click(createKnowledgeButton);
expect(onSubmit).toBeCalled();
expect(onSubmit).toBeCalledWith({ url: 'http://test', name: 'test', multiTurn: false });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable react-hooks/rules-of-hooks */
import React from 'react';

import QnAPage from '../../../src/pages/knowledge-base/QnAPage';
import TableView from '../../../src/pages/knowledge-base/table-view';
import CodeEditor from '../../../src/pages/knowledge-base/code-editor';
import { renderWithRecoil } from '../../testUtils';
Expand All @@ -26,12 +27,16 @@ answer

const state = {
projectId: 'test',
dialogs: [{ id: '1' }, { id: '2' }],
dialogs: [
{ id: '1', content: '', skills: [] },
{ id: '2', content: '', skills: [] },
],
locale: 'en-us',
qnaFiles: [
{
id: 'a.en-us',
content: initialContent,
imports: [],
qnaSections: [
{
Questions: [{ content: 'question', id: 1 }],
Expand Down Expand Up @@ -63,16 +68,20 @@ const initRecoilState = ({ set }) => {

describe('QnA page all up view', () => {
it('should render QnA page table view', () => {
const { getByText, getByTestId } = renderWithRecoil(
const { getByTestId, getByText } = renderWithRecoil(
<TableView dialogId={'a'} projectId={state.projectId} />,
initRecoilState
);
getByTestId('table-view');
getByText('question (1)');
getByText('answer');
getByText('Question');
});

it('should render QnA page code editor', () => {
renderWithRecoil(<CodeEditor dialogId={'a'} projectId={state.projectId} />, initRecoilState);
});

it('should render QnA page', () => {
const { getByTestId } = renderWithRecoil(<QnAPage dialogId={'a'} projectId={state.projectId} />, initRecoilState);
getByTestId('QnAPage');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import React from 'react';

import { renderWithRecoil } from '../../testUtils';
import LGPage from '../../../src/pages/language-generation/LGPage';
import TableView from '../../../src/pages/language-generation/table-view';
import CodeEditor from '../../../src/pages/language-generation/code-editor';
import {
localeState,
luFilesState,
lgFilesState,
settingsState,
schemasState,
Expand All @@ -31,16 +31,16 @@ const initialTemplates = [

const state = {
projectId: 'test',
dialogs: [{ id: '1' }, { id: '2' }],
dialogs: [
{ id: '1', content: '', diagnostics: [], skills: [] },
{ id: '2', content: '', diagnostics: [], skills: [] },
],
locale: 'en-us',
lgFiles: [
{ id: 'a.en-us', content: initialContent, templates: initialTemplates },
{ id: 'a.fr-fr', content: initialContent, templates: initialTemplates },
],
luFiles: [
{ id: 'a.en-us', content: initialContent, templates: initialTemplates },
{ id: 'a.fr-fr', content: initialContent, templates: initialTemplates },
{ id: 'a.en-us', content: initialContent, templates: initialTemplates, diagnostics: [] },
{ id: 'a.fr-fr', content: initialContent, templates: initialTemplates, diagnostics: [] },
],

settings: {
defaultLanguage: 'en-us',
languages: ['en-us', 'fr-fr'],
Expand All @@ -51,7 +51,6 @@ const initRecoilState = ({ set }) => {
set(currentProjectIdState, state.projectId);
set(localeState(state.projectId), state.locale);
set(dialogsState(state.projectId), state.dialogs);
set(luFilesState(state.projectId), state.luFiles);
set(lgFilesState(state.projectId), state.lgFiles);
set(settingsState(state.projectId), state.settings);
set(schemasState(state.projectId), mockProjectResponse.schemas);
Expand All @@ -70,4 +69,9 @@ describe('LG page all up view', () => {
it('should render lg page code editor', () => {
renderWithRecoil(<CodeEditor dialogId={'a'} projectId={state.projectId} />, initRecoilState);
});

it('should render lg page', () => {
const { getByTestId } = renderWithRecoil(<LGPage dialogId={'a'} projectId={state.projectId} />, initRecoilState);
getByTestId('LGPage');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import React from 'react';

import LUPage from '../../../src/pages/language-understanding/LUPage';
import TableView from '../../../src/pages/language-understanding/table-view';
import CodeEditor from '../../../src/pages/language-understanding/code-editor';
import { renderWithRecoil } from '../../testUtils';
import {
localeState,
dialogsState,
luFilesState,
lgFilesState,
settingsState,
schemasState,
currentProjectIdState,
Expand All @@ -22,17 +22,23 @@ const initialContent = `
- hello
`;

const initialIntents = [
{
Name: 'Greeting',
Body: '- hello',
},
];

const state = {
projectId: 'test',
dialogs: [{ id: '1' }, { id: '2' }],
locale: 'en-us',
lgFiles: [
{ id: 'a.en-us', content: initialContent },
{ id: 'a.fr-fr', content: initialContent },
dialogs: [
{ id: '1', content: '', skills: [] },
{ id: '2', content: '', skills: [] },
],
locale: 'en-us',
luFiles: [
{ id: 'a.en-us', content: initialContent },
{ id: 'a.fr-fr', content: initialContent },
{ id: 'a.en-us', content: initialContent, templates: initialIntents, diagnostics: [] },
{ id: 'a.fr-fr', content: initialContent, templates: initialIntents, diagnostics: [] },
],
settings: {
defaultLanguage: 'en-us',
Expand All @@ -45,7 +51,6 @@ const initRecoilState = ({ set }) => {
set(localeState(state.projectId), state.locale);
set(dialogsState(state.projectId), state.dialogs);
set(luFilesState(state.projectId), state.luFiles);
set(lgFilesState(state.projectId), state.lgFiles);
set(settingsState(state.projectId), state.settings);
set(schemasState(state.projectId), mockProjectResponse.schemas);
};
Expand All @@ -63,4 +68,8 @@ describe('LU page all up view', () => {
it('should render lu page code editor', () => {
renderWithRecoil(<CodeEditor dialogId={'a'} projectId={state.projectId} />, initRecoilState);
});

it('should render lu page', () => {
renderWithRecoil(<LUPage dialogId={'a'} projectId={state.projectId} />, initRecoilState);
});
});
92 changes: 0 additions & 92 deletions Composer/packages/client/__tests__/utils/qnaUtil.test.ts

This file was deleted.

Loading

0 comments on commit e5fc3df

Please sign in to comment.