Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion chat-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@aws/chat-client-ui-types": "^0.1.13",
"@aws/language-server-runtimes-types": "^0.1.11",
"@aws/mynah-ui": "^4.28.0"
"@aws/mynah-ui": "^4.30.1"
},
"devDependencies": {
"@types/jsdom": "^21.1.6",
Expand Down
156 changes: 156 additions & 0 deletions chat-client/src/client/features/history.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { DetailedList, MynahUI } from '@aws/mynah-ui'
import { Messager } from '../messager'
import sinon = require('sinon')
import { ChatHistoryList } from './history'
import { ListConversationsResult } from '@aws/language-server-runtimes-types'
import * as assert from 'assert'
import { DetailedListSheetProps } from '@aws/mynah-ui/dist/components/detailed-list/detailed-list-sheet'

describe('history', () => {
let mynahUi: MynahUI
let messager: Messager
let openDetailedListStub: sinon.SinonStub
let chatHistoryList: ChatHistoryList

beforeEach(() => {
mynahUi = {
openDetailedList: sinon.stub(),
} as unknown as MynahUI
openDetailedListStub = mynahUi.openDetailedList as sinon.SinonStub

messager = {
onListConversations: sinon.stub(),
onConversationClick: sinon.stub(),
} as unknown as Messager

chatHistoryList = new ChatHistoryList(mynahUi, messager)
})

afterEach(() => {
sinon.restore()
})

it('show opens detailed list if called the first time', () => {
const mockParams: ListConversationsResult = {
header: { title: 'test title' },
list: [
{
groupName: 'group',
icon: 'not_existing',
items: [
{
id: 'i1',
icon: 'chat',
description: 'desc',
actions: [
{
id: 'a1',
text: 'delete',
icon: 'trash',
},
],
},
],
},
],
filterOptions: [
{
id: '1',
type: 'textinput',
icon: 'search',
},
],
}

chatHistoryList.show(mockParams)

sinon.assert.calledOnce(openDetailedListStub)
const arg = openDetailedListStub.getCall(0).args[0] as DetailedListSheetProps
assert.equal(arg.detailedList.header, mockParams.header)
assert.deepEqual(arg.detailedList.filterOptions, [
{
...mockParams.filterOptions?.[0],
autoFocus: true,
},
])
assert.deepEqual(arg.detailedList.list, [
{
groupName: mockParams.list?.[0].groupName,
icon: undefined,
children: mockParams.list?.[0].items,
},
])
})
it('show updates detailed list if called the second time', () => {
const mockParams: ListConversationsResult = {
header: { title: 'test title' },
list: [
{
groupName: 'group',
items: [
{
id: 'i1',
},
],
},
],
}

const updateStub = sinon.stub()
openDetailedListStub.returns({
update: updateStub,
close: sinon.stub(),
changeTarget: sinon.stub(),
getTargetElementId: sinon.stub(),
})

// First call to show
chatHistoryList.show(mockParams)

// Second call to show
const updatedMockParams: ListConversationsResult = {
list: [
{
groupName: 'group',
items: [
{
id: 'i2',
},
],
},
],
}
chatHistoryList.show(updatedMockParams)

sinon.assert.calledOnce(openDetailedListStub)
sinon.assert.calledOnce(updateStub)
const updateArg = updateStub.getCall(0).args[0] as DetailedList
assert.equal(updateArg.list?.[0].children?.[0].id, updatedMockParams.list[0].items?.[0].id)
})
it('show opens detailed list if called after close', () => {
const mockParams: ListConversationsResult = {
header: { title: 'test title' },
list: [
{
groupName: 'group',
items: [
{
id: 'i1',
},
],
},
],
}

// First call to show
chatHistoryList.show(mockParams)

// Close the list
chatHistoryList.close()

// Call show again
chatHistoryList.show(mockParams)

sinon.assert.calledTwice(openDetailedListStub)
})
})
1 change: 0 additions & 1 deletion chat-client/src/client/features/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class ChatHistoryList {
this.historyDetailedList.update(detailedList)
} else {
this.historyDetailedList = this.mynahUi.openDetailedList({
tabId: '', // TODO: remove after MynahUI is changed to remove the property
detailedList: detailedList,
events: {
onFilterValueChange: this.onFilterValueChange,
Expand Down
27 changes: 27 additions & 0 deletions chat-client/src/client/mynahUi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,33 @@ describe('MynahUI', () => {
})
})
})

describe('conversationClicked result', () => {
it('should list conversarions if successfully deleted conversation', () => {
const listConversationsSpy = sinon.spy(messager, 'onListConversations')

// Successful conversation deletion
inboundChatApi.conversationClicked({
success: true,
action: 'delete',
id: 'test-conversation-id',
})

sinon.assert.calledOnce(listConversationsSpy)
})
it('should not list conversarions if conversartion click processing failed', () => {
const listConversationsSpy = sinon.spy(messager, 'onListConversations')

// Unsuccessful conversation deletion
inboundChatApi.conversationClicked({
success: false,
action: 'delete',
id: 'test-conversation-id',
})

sinon.assert.neverCalledWith(listConversationsSpy)
})
})
})

describe('withAdapter', () => {
Expand Down
2 changes: 1 addition & 1 deletion chat-client/src/client/mynahUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export const createMynahUi = (
tabBarButtons: [
{
id: ChatHistory.TabBarButtonId,
icon: MynahIcons.COMMENT,
icon: MynahIcons.HISTORY,
description: 'View chat history',
},
],
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading