Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests to ensure restart bubble not present #2107

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added tests to ensure restart bubble not present
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

Should hide restart bubble if speech bot

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

Typo fixed

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
  • Loading branch information
Srinaath Ravichandran committed Mar 13, 2020
commit c6e50c6bdcd41c0825238dbb527a3deffa0c9af9
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import { ValueTypes, RestartConversationOptions, RestartConversationStatus } fro
import { OuterActivityWrapper } from './outerActivityWrapper';
import { OuterActivityWrapperContainer } from './outerActivityWrapperContainer';

jest.mock('./chat.scss', () => ({
hidden: 'hidden-restart',
}));

describe('<OuterActivityWrapper />', () => {
it('should render', () => {
const storeState = {
Expand Down Expand Up @@ -152,4 +156,201 @@ describe('<OuterActivityWrapper />', () => {
expect((instance as any).isUserActivity(userCard.activity)).toBe(true);
expect((instance as any).isUserActivity(botCard.activity)).toBe(false);
});

describe('Restart conversation bubble in OuterActivityWrapper', () => {
it('should show restart bubble if a)not Speech bot; b) Webchat is enabled; c)User activity is selected', () => {
const card = {
activity: {
id: 'card1',
from: {
role: 'user',
},
channelData: {
test: true,
},
},
};
const storeState = {
chat: {
chats: {
doc1: {
highlightedObjects: [],
inspectorObjects: [{ value: { ...card.activity }, valueType: ValueTypes.Activity }],
mode: 'livechat',
},
},
restartStatus: {
doc1: RestartConversationStatus.Stop,
},
},
};

const wrapper = mount(
<Provider store={createStore((state, action) => state, storeState)}>
<OuterActivityWrapperContainer
card={card}
documentId={'doc1'}
>
/>
</Provider>
);
expect(wrapper.find('hidden-restart').length).toBe(0);
});

it('should hide restart bubble if activity not selected', () => {
const card = {
activity: {
id: 'card1',
from: {
role: 'user',
},
channelData: {
test: true,
},
},
};
const storeState = {
chat: {
chats: {
doc1: {
highlightedObjects: [],
inspectorObjects: [{ value: {}, valueType: ValueTypes.Activity }],
mode: 'livechat',
},
},
restartStatus: {
doc1: RestartConversationStatus.Stop,
},
},
};

const wrapper = mount(
<Provider store={createStore((state, action) => state, storeState)}>
<OuterActivityWrapperContainer
card={card}
documentId={'doc1'}
>
/>
</Provider>
);
expect(wrapper.find('.hidden-restart').length).toBe(1);
});

it('should hide restart bubble if it is a speech bot', () => {
const card = {
activity: {
id: 'card1',
from: {
role: 'user',
},
channelData: {
test: true,
},
},
};
const storeState = {
chat: {
chats: {
doc1: {
highlightedObjects: [],
inspectorObjects: [{ value: { ...card.activity }, valueType: ValueTypes.Activity }],
mode: 'livechat',
speechKey: 'abc',
speechRegion: 'westus',
},
},
restartStatus: {
doc1: RestartConversationStatus.Stop,
},
},
};

const wrapper = mount(
<Provider store={createStore((state, action) => state, storeState)}>
<OuterActivityWrapperContainer
card={card}
documentId={'doc1'}
>
/>
</Provider>
);
expect(wrapper.find('.hidden-restart').length).toBe(1);
});

it('should hide restart bubble if restart conversation has a status of "Started" for chat', () => {
const card = {
activity: {
id: 'card1',
from: {
role: 'user',
},
channelData: {
test: true,
},
},
};
const storeState = {
chat: {
chats: {
doc1: {
highlightedObjects: [],
inspectorObjects: [{ value: { ...card.activity }, valueType: ValueTypes.Activity }],
mode: 'livechat',
},
},
restartStatus: {
doc1: RestartConversationStatus.Started,
},
},
};

const wrapper = mount(
<Provider store={createStore((state, action) => state, storeState)}>
<OuterActivityWrapperContainer
card={card}
documentId={'doc1'}
>
/>
</Provider>
);
expect(wrapper.find('.hidden-restart').length).toBe(1);
});

it('should hide restart bubble if chat in transcript mode', () => {
const card = {
activity: {
id: 'card1',
from: {
role: 'user',
},
channelData: {
test: true,
},
},
};
const storeState = {
chat: {
chats: {
doc1: {
highlightedObjects: [],
inspectorObjects: [{ value: { ...card.activity }, valueType: ValueTypes.Activity }],
mode: 'transcript',
},
},
restartStatus: {},
},
};

const wrapper = mount(
<Provider store={createStore((state, action) => state, storeState)}>
<OuterActivityWrapperContainer
card={card}
documentId={'doc1'}
>
/>
</Provider>
);
expect(wrapper.find('.hidden-restart').length).toBe(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface OuterActivityWrapperProps {
currentRestartConversationOption: RestartConversationOptions;
mode: EmulatorMode;
restartStatus: RestartConversationStatus;
isDLSpeechBot: boolean;
}

export class OuterActivityWrapper extends React.Component<OuterActivityWrapperProps, {}> {
Expand All @@ -69,14 +70,15 @@ export class OuterActivityWrapper extends React.Component<OuterActivityWrapperPr
onItemRendererKeyDown,
mode,
restartStatus,
isDLSpeechBot,
} = this.props;

const isSelected = this.shouldBeSelected(card.activity);
const isUserActivity = this.isUserActivity(card.activity);
const isWebChatDisabled =
mode === 'transcript' || mode === 'debug' || restartStatus === RestartConversationStatus.Started;

const showRestartBubble = isUserActivity && isSelected && !isWebChatDisabled;
const showRestartBubble = !isDLSpeechBot && isUserActivity && isSelected && !isWebChatDisabled;

return (
<ActivityWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function mapStateToProps(state: RootState, { documentId }: { documentId: string
currentRestartConversationOption: state.chat.chats[documentId].restartConversationOption,
mode: state.chat.chats[documentId].mode,
restartStatus: state.chat.restartStatus[documentId],
isDLSpeechBot: !!(state.chat.chats[documentId].speechKey && state.chat.chats[documentId].speechRegion),
};
}

Expand Down